~jaytaoko/nuxcodesamples/nuxcodesamples-gst-video-decode

« back to all changes in this revision

Viewing changes to data/shaders/GaussianShader.glsl

  • Committer: Jay Taoko
  • Date: 2012-01-07 19:20:32 UTC
  • Revision ID: jay.taoko@canonical.com-20120107192032-5fymlfzbeyx84fz3
- Visual FX program

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
[Vertex Shader] 
 
2
#version 120
 
3
 
 
4
uniform mat4 ViewProjectionMatrix;
 
5
 
 
6
attribute vec4 AVertex;
 
7
attribute vec4 TextureCoord0;
 
8
attribute vec4 VertexColor;
 
9
 
 
10
varying vec4 varyTexCoord0;
 
11
varying vec4 varyVertexColor;
 
12
 
 
13
void main()
 
14
{
 
15
    varyTexCoord0 = TextureCoord0;
 
16
    varyVertexColor = VertexColor;
 
17
    gl_Position =  ViewProjectionMatrix * (AVertex);
 
18
}
 
19
 
 
20
[Fragment Shader]
 
21
#version 120
 
22
#extension GL_ARB_texture_rectangle : enable
 
23
 
 
24
varying vec4 varyTexCoord0;
 
25
varying vec4 varyVertexColor;
 
26
 
 
27
#ifdef SAMPLERTEX2D
 
28
        uniform sampler2D TextureObject0;
 
29
        uniform vec2 TextureSize0;
 
30
        vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)
 
31
        {
 
32
            return texture2D(TexObject, TexCoord.st);
 
33
        }
 
34
#elif defined SAMPLERTEX2DRECT
 
35
        uniform sampler2DRect TextureObject0;
 
36
        uniform vec2 TextureSize0;
 
37
        vec4 SampleTexture(sampler2DRect TexObject, vec2 TexCoord)
 
38
        {
 
39
            return texture2DRect(TexObject, TexCoord.st);
 
40
        }
 
41
#endif                                                             
 
42
 
 
43
#define NUM_SAMPLES 55
 
44
uniform float W[NUM_SAMPLES];
 
45
 
 
46
#ifdef HORIZONTALGAUSS
 
47
void main()
 
48
{
 
49
    vec4 sum   = vec4(0.0, 0.0, 0.0, 0.0);
 
50
    vec2 delta = vec2(1.0 / TextureSize0.x, 0.0);
 
51
 
 
52
    vec2 texCoord = vec2(varyTexCoord0.s, varyTexCoord0.t);
 
53
    texCoord.x -= ((NUM_SAMPLES -1)/2) / TextureSize0.x;
 
54
    texCoord.y += 0.0 / TextureSize0.y;
 
55
   
 
56
    for(int i = 0; i < NUM_SAMPLES; ++i)
 
57
    {
 
58
        sum += SampleTexture(TextureObject0, texCoord) * W[i];
 
59
        texCoord += delta;
 
60
    }
 
61
    gl_FragColor = vec4(sum.x, sum.y, sum.z, sum.w);
 
62
}
 
63
#endif
 
64
 
 
65
#ifdef VERTICALGAUSS
 
66
void main()
 
67
{
 
68
    vec4 sum   = vec4(0.0, 0.0, 0.0, 0.0);
 
69
    vec2 delta = vec2(0.0, 1.0 / TextureSize0.y);
 
70
 
 
71
    vec2 texCoord = vec2(varyTexCoord0.s, varyTexCoord0.t);
 
72
    texCoord.x += 0.0 / TextureSize0.x;
 
73
    texCoord.y -= ((NUM_SAMPLES -1)/2) / TextureSize0.y;
 
74
   
 
75
    for(int i = 0; i < NUM_SAMPLES; ++i)
 
76
    {
 
77
        sum += SampleTexture(TextureObject0, texCoord) * W[i];
 
78
        texCoord += delta;
 
79
    }
 
80
    gl_FragColor = vec4(sum.x, sum.y, sum.z, sum.w);
 
81
}
 
82
#endif
 
83