varying variables

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).

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

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

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.

You will not be guaranteed the same value in all fragments contained within the primitive
I 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.

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.

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.

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.

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

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