PDA

View Full Version : varying variables



powerpad
06-21-2005, 08:13 AM
Varying variables get interpolated when going from vertex shader to fragment shader.

If I specify 2 vertices with the same value then no interpolation is done at all or am I wrong here?

I ask this because I want to use the texture coords to pass some values but I don't want them to get interpolated.

Is this possible or is there a better way? I would use uniforms in a fragment shader but unfortunately it seems that I cannot use more uniforms (I don't get a location for them - I asked this in another thread).

zed
06-21-2005, 11:50 AM
If I specify 2 vertices with the same value then no interpolation is done at all or am I wrong here?
I ask this because I want to use the texture coords to pass some values but I don't want them to get interpolated.seems correct assumption, also u dont need to use texture coordinates for the varying

powerpad
06-21-2005, 12:35 PM
I know but I don't want to use other one since these are builtin but you are right it might lead to confusion.

thanks

kingjosh
06-21-2005, 12:39 PM
Zed's statement is incorrect according to the OpenGL Shading Language spec.

From the Spec:
All varying variables are interpolated in a perspective-correct manner over the primitive being rendered.

You will not be guaranteed the same value in all fragments contained within the primitive - even if you pass identical values among the vertices due to the perspective correction.

Korval
06-21-2005, 03:31 PM
You will not be guaranteed the same value in all fragments contained within the primitiveI admit my knowledge of perspective-correct interpolation is a bit lacking, but if you pass in 3 values that are the same for all three verts, how exactly is it that you can get something different over the surface of the primitive. I thought perspective-correction merely corrected the problems with linearly interpolating the value. Since linear interpolation produces the same value everywhere, I don't see how it is reasonable to see a constant value change over a primitive's surface.

kingjosh
06-21-2005, 05:40 PM
The varyings would still go through an interpolation with perspective correction algorithm, whether or not they are identical values at the vertices. It would be possible to lose a little precision in this and thus get a slightly different value at some fragments.

For this reason, one would not be be guaranteed the same value at every fragment, although it is possible. The only way to guarantee the values would be identical at all fragments would be to skip sending the varyings through the interpolation which clearly would not be conformant to the OpenGL Shading Language Specification.

Korval
06-21-2005, 07:35 PM
For this reason, one would not be be guaranteed the same value at every fragment, although it is possible.While yes, floating-point math precision wouldn't guarentee binary-identacal float results, let's be reasonable about this. You're not going to get random values out. If you send the same value from all 3 coordinates, you're going to get something that looks very much like that value to the first 4-6 significant digits.

Ffelagund
06-21-2005, 11:13 PM
Originally posted by powerpad:
I would use uniforms in a fragment shader but unfortunately it seems that I cannot use more uniforms (I don't get a location for them - I asked this in another thread).Have you tried to use built-in uniforms in 'general purpose' way? for example, you can fill the clip planes data, anda later, in the shaders read the data and use for your your own purposes.

I don't know if built-in uniforms are independant of user uniforms (I don't think so) but it is worth to try.

powerpad
06-22-2005, 12:02 AM
hmm if this works would be nice since i will not have to worry about the interpolation but if they counted into my active uniforms it would be useless since I could define uniforms and pass them directly to the shader

I will try and thanks for the hint