Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

OpenGL Interpolators

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose I drew a quad onto the screen with a custom value being passed from the vertex shader to the pixel shader, as shown in the attachment. (The 0s and 1s correspond to the value being assigned in the vertex shader).

In the pixel shader, what value would be read for the top left pixel? Would it be 0.25 or 0 (assuming the same z for all 4 vertices)? i.e. is the interpolated value obtained from the center of the pixel or from the corner?

Finally, is this behavior the same in OpenGL and DirectX (or between shading langues)? And does it depend on which interpolator is used (e.g. TEXCOORD0 vs NORMAL vs POSITION in HLSL)?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
just take a look at the OpenGL specs.

http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf: 4.3.9 Interpolation
http://www.opengl.org/registry/doc/glspec41.core.20100725.pdf:3.5 Line Segments, 2.19 Flatshading

in a shader you can tell openGL excatly how every single varrying should be interpolated (perspective correct, linear or flat)
you can also decide at which position each fragment should be sampled.

the standart way is that u get perspective interpolation with random samples.
So to answer your question, there is no guarantee which value your fragments would have in your example.
The left top fragment could have any value between 0. and 0.5

Share this post


Link to post
Share on other sites
Normally, it should be 0.25 for the top left pixel but it can vary between implementations.

Share this post


Link to post
Share on other sites
Thanks for the replies. If it's always 0.25 that's exactly what I need but I'll also look more at the gl spec to see if there's a way to enforce that. (The reason is for computing shadow bias.)

Share this post


Link to post
Share on other sites
D3D9 interpolates the same, but because it addresses pixels in a different way, you can accidentally get "0.0" instead of "0.25" by specifying slightly incorrect vertex positions.

Share this post


Link to post
Share on other sites
like the glsl specs point out you can use the centroid keyword, which enforces to sample at the middle of the pixel.

eg. centroid in vec2 texcoord;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!