# finding pixel corners' texture coordinates using dFdx and dFdy

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

## 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?

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 30
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631408
• Total Posts
2999924
×