Jump to content
  • Advertisement
Sign in to follow this  

finding pixel corners' texture coordinates using dFdx and dFdy

This topic is 4841 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

Inside the fragment shader, I'm trying to estimate each pixel's corner's texture coordinates using the derivative functions:
    vec2 dxHalf = dFdx(gl_TexCoord[0])*0.5;
    vec2 dyHalf = dFdy(gl_TexCoord[0])*0.5;

    vec2 vec2BotLeft =
        vec2(gl_TexCoord[0] - dxHalf - dyHalf);
    vec2 vec2BotRight =
        vec2(gl_TexCoord[0] + dxHalf - dyHalf);
    vec2 vec2TopLeft =
        vec2(gl_TexCoord[0] - dxHalf + dyHalf);
    vec2 vec2TopRight =
        vec2(gl_TexCoord[0] + dxHalf + dyHalf);
Which seems to work great, except for cases where the triangle is almost perpendicular to the near plane. In which case, the dFdx() and dFdy() functions (correctly) go to positive or negative infinity. I would like to somehow clamp those values to stay within the pixel's parent triangle. (Clamping the values to [0, 1] was not enough, since a texture could have hundreds of triangles inside.) I thought of using barycentric coordinates, but that would require me to pass in a barycentric coordinate for every vertex. Since I'm using VBO's with indexed arrays, this would be a hassle. Any ideas?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!