Varying variable in vertex shader question

Hi,

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.

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
}

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.