enmaniac

07-13-2005, 02:03 AM

Hi!

I want to create glow effect in my project. I came across the code from ATI SDK. They used shaders for performing the gaussian blur on the texture. This is the code:

[Vertex shader]

uniform vec2 invSize;

varying vec2 texCoordM;

varying vec2 texCoordB0;

varying vec2 texCoordF0;

varying vec2 texCoordB1;

varying vec2 texCoordF1;

varying vec2 texCoordB2;

varying vec2 texCoordF2;

void main(){

gl_Position = gl_Vertex;

vec2 texCoord = gl_MultiTexCoord0.xy + 0.25 * invSize;

texCoordM = texCoord;

texCoordB0 = texCoord - invSize;

texCoordF0 = texCoord + invSize;

texCoordB1 = texCoord - invSize * 2.0;

texCoordF1 = texCoord + invSize * 2.0;

texCoordB2 = texCoord - invSize * 3.0;

texCoordF2 = texCoord + invSize * 3.0;

}

[Fragment shader]

uniform sampler2D Image;

varying vec2 texCoordM;

varying vec2 texCoordB0;

varying vec2 texCoordF0;

varying vec2 texCoordB1;

varying vec2 texCoordF1;

varying vec2 texCoordB2;

varying vec2 texCoordF2;

void main(){

vec4 sampleM = texture2D(Image, texCoordM);

vec4 sampleB0 = texture2D(Image, texCoordB0);

vec4 sampleF0 = texture2D(Image, texCoordF0);

vec4 sampleB1 = texture2D(Image, texCoordB1);

vec4 sampleF1 = texture2D(Image, texCoordF1);

vec4 sampleB2 = texture2D(Image, texCoordB2);

vec4 sampleF2 = texture2D(Image, texCoordF2);

gl_FragColor = 0.1752 * sampleM + 0.1658 * (sampleB0 + sampleF0) + 0.1403 * (sampleB1 + sampleF1) + 0.1063 * (sampleB2 + sampleF2);

}

My question is: Why do they compute texure coords in vertex shader and not in fragment shader ?

Don't they retrieve texels around vertices only?

What about the rest of the texture ? It seems they use the same texcoords for most of the texture, dont they ?

Hmm...I am confused! Please help!

Thx in advance

I want to create glow effect in my project. I came across the code from ATI SDK. They used shaders for performing the gaussian blur on the texture. This is the code:

[Vertex shader]

uniform vec2 invSize;

varying vec2 texCoordM;

varying vec2 texCoordB0;

varying vec2 texCoordF0;

varying vec2 texCoordB1;

varying vec2 texCoordF1;

varying vec2 texCoordB2;

varying vec2 texCoordF2;

void main(){

gl_Position = gl_Vertex;

vec2 texCoord = gl_MultiTexCoord0.xy + 0.25 * invSize;

texCoordM = texCoord;

texCoordB0 = texCoord - invSize;

texCoordF0 = texCoord + invSize;

texCoordB1 = texCoord - invSize * 2.0;

texCoordF1 = texCoord + invSize * 2.0;

texCoordB2 = texCoord - invSize * 3.0;

texCoordF2 = texCoord + invSize * 3.0;

}

[Fragment shader]

uniform sampler2D Image;

varying vec2 texCoordM;

varying vec2 texCoordB0;

varying vec2 texCoordF0;

varying vec2 texCoordB1;

varying vec2 texCoordF1;

varying vec2 texCoordB2;

varying vec2 texCoordF2;

void main(){

vec4 sampleM = texture2D(Image, texCoordM);

vec4 sampleB0 = texture2D(Image, texCoordB0);

vec4 sampleF0 = texture2D(Image, texCoordF0);

vec4 sampleB1 = texture2D(Image, texCoordB1);

vec4 sampleF1 = texture2D(Image, texCoordF1);

vec4 sampleB2 = texture2D(Image, texCoordB2);

vec4 sampleF2 = texture2D(Image, texCoordF2);

gl_FragColor = 0.1752 * sampleM + 0.1658 * (sampleB0 + sampleF0) + 0.1403 * (sampleB1 + sampleF1) + 0.1063 * (sampleB2 + sampleF2);

}

My question is: Why do they compute texure coords in vertex shader and not in fragment shader ?

Don't they retrieve texels around vertices only?

What about the rest of the texture ? It seems they use the same texcoords for most of the texture, dont they ?

Hmm...I am confused! Please help!

Thx in advance