PDA

View Full Version : Pass informations from vertex to fragment shader



Lapinot
05-07-2005, 04:34 AM
Hi
I compute some values in the vertex shader and then ,depending on their values, do some operations in the fragment shader. How can I pass this values/information, if it's not the normal parameters (color, position, texture, etc...)?
Thanks

airseb
05-07-2005, 05:22 AM
Hi
you have to create a global variable with the qualifier "varying". It must be the same declaration in your vertex shader and in the fragment shader. Data between vertex and fragment shader are interpolated thanks to this.

Lapinot
05-07-2005, 06:02 AM
Can I really do that in ARB program? Or do I have to use a special language or packages?

Java Cool Dude
05-07-2005, 07:33 AM
Using varying variables or passing things directly as texture coordinates.

GLSL:
Passing:
gl_TexCoord[0] = stuffToPass;

Retrieving:
vec4 passedStuff = gl_TexCoord[0]

ARB:
Passing:
MOV result.texcoord[0], stuffToPass;

Retrieving:
MOV passedStuff, fragment.texcoord[0];

Korval
05-07-2005, 11:29 AM
Texture coordinates do not have to be used for textures. They're just a 4-vector floating-point value that gets linearly interpolated (perspectively-correct) across the surface of a triangle.