View Full Version : varying variable in vertex shader question

03-31-2005, 01:15 PM

I've read the glsl spec and this sentence hooked up my attention :
"A vertex shader may also read varying variables, getting back the same values it has written. Reading a varying variable in a vertex shader returns undefined values if it is read before being written."

What does this exactly means?

Is it then possible to render a geometry, the vertex shader writes in a varying array the view space interpolated vertice. The array would be initialised at -1.0 everywhere so when adding a data we can easily find the next free element with a small loop(PS3.0 and Nv4x makes it possible).

But let us say that we have ten (interpolated)vertices that projects into a same fragment. I'd like to get back the varying array computed by the vertex shader before. Is it possible?

Also, do you think it is possible that once the fragment is treated for the first time, to stop the others 9 from being processed?

I don't know if I made myself clear but if anyone has an idea I would appreciate having some advices.

Cheers, Jeff.

03-31-2005, 04:25 PM
Originally posted by funkeejeffou:
I'd like to get back the varying array computed by the vertex shader before. Is it possible?No. What the spec means is simply that you can write code like this:

varying vec3 lightVec;
varying vec3 viewVec;
varying vec3 halfVec;

void main(){
lightVec = normalize(lightPos - gl_Vertex.xyz);
viewVec = normalize(camPos - gl_Vertex.xyz);

halfVec = normalize(lightVec + viewVec); // Reading varyings

03-31-2005, 04:35 PM
Oh ok....

Thanks for the reply, it would have been too perfect if this kind of stuff was possible, so shaders really cannot communicate between them.

Cheers, Jeff.