Jump to content
  • Advertisement
Sign in to follow this  
skytiger

float2 dx = ddx(uv.xy * size.x); // does this make sense?

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

(given that uv is float2)

shouldn't it be:

[source lang="cpp"]float dx = ddx(uv.x * size.x);

float dy = ddy(uv.y * size.y);

[/source]

and why is there an ddx() and a ddy() ? why not just a dd() ?

Share this post


Link to post
Share on other sites
Advertisement
ddx is the partial derivative of the value with respect to screen-space X, ddy is the partial derivative of the value with respect to screen-space Y. In other words ddx tells you how much the value changes if you were to move to right a pixel, while ddy tells you how much the value changes if you were to move down a pixel. That is why there are two different functions.

I can't tell you whether your code makes sense without knowing what you're actually trying to accomplish, and also knowing what "size" is.

Share this post


Link to post
Share on other sites
Yeah, what mjp said.

If you intend to use the derivatives for manual tex2d lookup because you're having issues with branch code, you'll probably want to do:
float2 dx = ddx(uv.xy * size.xy);
float2 dy = ddy(uv.xy * size.xy);

Share this post


Link to post
Share on other sites
I see now!

float2 dx = ddx(uv.xy);

ddx() is returning a vector in texture space

The original code was calculating a lod level manually to allow for sampling neighbouring pixels (in DX9)
[source lang="cpp"]float MipMapLevel(in float2 uv, in float2 textureSize) {

float2 dx = ddx(uv * textureSize.x);
float2 dy = ddy(uv * textureSize.y);

float d = max(dot(dx, dx), dot(dy, dy));

return log2(sqrt(d));

}//function

// then I can use tex2Dlod() with correct pixel offsets for manual interpolation
[/source]
also, from my testing on an ATI3870, fractional LOD levels seem to cause blending between mip levels
so I need to round or truncate my lod level before calculating the pixel offsets

thanks MJP (edit: and Matias, good point) Edited by skytiger

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!