Jump to content
  • Advertisement
Sign in to follow this  
WizardOfOzzz

Derivative instruction details (ddx ddy or dFdx dFdy etc.)?

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

Hi All, From my understanding the derivative instructions ddx,ddy,fwidth etc. Use 2x2 blocks of pixels to compute the derivative. Can someone please explain: 1.) What happens on triangle boundaries where a triangle only intersects one or 2 pixels of the 2x2 region 2.) The exact formula for the derivatives for each pixel in the 2x2 block. For example, given the block: a b c d the ddx derivative for pixel a/b/c/d could be ((b-a)+(d-c))/2 or it could be b-a for a/b and d-c for c/d. I have scoured the net and haven't found a good reference for this. I have found that if I draw a box and take the derivative of a complicated calculated value that *sometimes* i get artifacts on the border of the box's polygons. I imagine this is due to how it is computed on polygon boundaries. Any help would be appreciated. Cheers! Eric [Edited by - WizardOfOzzz on January 9, 2008 8:16:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by WizardOfOzzz
From my understanding the derivative instructions ddx,ddy,fwidth etc. Use 2x2 blocks of pixels to compute the derivative.

That's correct.

Quote:
Original post by WizardOfOzzz
1.) What happens on triangle boundaries where a triangle only intersects one or 2 pixels of the 2x2 region

The shader is evaluated for all of the pixels in the 2x2 "quad", even if some of them fall outside of the triangle.

Quote:
Original post by WizardOfOzzz
2.) The exact formula for the derivatives for each pixel in the 2x2 block. For example, given the block:
a b
c d

IIRC the ddx(a) and ddx(b) will be (b-a), ddy(a) and ddy(c) will be (c-a) and so on.

Quote:
Original post by WizardOfOzzz
I have found that if I draw a box and take the derivative of a complicated calculated value that *sometimes* i get artifacts on the border of the box's polygons.

This problem can indeed occur if you're computing some function that is undefined or otherwise not well-behaved outside of the normal triangle interpolant range. Similar problems can occur with multi-sampling, but there you can often solve them using "centroid" interpolation. I don't recall exactly how derivatives interact with centroid interpolation but I wouldn't be surprised if it is implementation-dependent.

Share this post


Link to post
Share on other sites
Thanks a lot for your response! With a bit more testing I'm finding that they tend to have problems on triangle boundaries when I use the results from texture sampling.

I figured maybe they can compute derivatives for things like interpolants without evaluating the entire pixel shader, but if the entire shader has to be executed then they don't bother?

In any event thanks a lot for your response!

Eric

Share this post


Link to post
Share on other sites
I had some issues myself with the derivate instructions on triangle edges; I was computing the derivative of one of my interpolants. Basically, the way I got it fixed was changing the way that my interpolant was passed; instead of passing it in TEXCOORD, i passed it in COLOR. I finally found out that this works because COLOR has centroid sampling and TEXCOORD doesnt. Not sure if that bit will help you out in your case, buts thats how i fixed the artifacts on my triangle edges.

Share this post


Link to post
Share on other sites
I believe there is a suffix you can add to certain semantics to indicate you want centroid sampling, i.e. TEXCOORD_centroid. It's in the docs somewhere for sure, that's where I've seen it before.

Share this post


Link to post
Share on other sites
Thanks for all of your replies. I don't believe extrapolation should make any of my calculations undefined, but it's a good place to start looking. In one case I also need the derivatives to be accurate so centroid won't work. Thankfully in that case I'm not getting artifacts anyway.

Cheers!

Eric

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!