Jump to content
  • Advertisement
Sign in to follow this  
Matt Aufderheide

Reconstruct normal from position

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

Advertisement
Yes, but by approximate its pretty much going to be at half-res

Use the derivative functions to find the worldspace vector pointing right and down, then normalize and cross-product for your answer

Share this post


Link to post
Share on other sites
Quote:
Original post by Exorcist
Yes, but by approximate its pretty much going to be at half-res

Use the derivative functions to find the worldspace vector pointing right and down, then normalize and cross-product for your answer


This is great, where did you learn it ?

Does it hold because the derivate of the position is the speed, so the direction ?

Share this post


Link to post
Share on other sites
Knowing what ddx() and ddy() do i took a guess and it worked :)

Basically the pixel shader works on 2x2 blocks for the sake of mipmapping etc, and the derivative functions work on these blocks by giving you the derivative along x and y of what ever variable you pass in. If you pass in a world position, then the derivatives are going to be the difference in position along the screen x and y - i.e. directions in worldspace :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Exorcist
Knowing what ddx() and ddy() do i took a guess and it worked :)

Basically the pixel shader works on 2x2 blocks for the sake of mipmapping etc, and the derivative functions work on these blocks by giving you the derivative along x and y of what ever variable you pass in. If you pass in a world position, then the derivatives are going to be the difference in position along the screen x and y - i.e. directions in worldspace :)


Yes, it makes perfectly sense :D

So, since ddx() and ddy() work on a 2x2 block, they are gonna give you the difference of the variable in the current fragment and the preceeding fragment, divided by one, so just giving you the difference.

if the current fragment has coordinate (x, y):

ddx(k) = k(x, y) - k(x-1,y)
ddy(k) = k(x, y) - k(x,y-1)

is it right ?

---

Going back to the topic start question, it should not work along edges, does it ?

Share this post


Link to post
Share on other sites
As for your equation, yeah that's correct. One thing to remember though, is that X and Y here in this case are always the same corner of every 2x2 block (cant remember if its bottom-right or top-right, depends on the direction of rasterization i guess)

If its at the time of drawing the geometry, then the edges wont be a problem (the entire 2x2 block is solved by the shader regardless of if it falls partially on a polygon edge)

If you are doing it after converting a z-buffer depth into a world position, then you will run into continuity problems along edges, simply because of the severe change in Z.

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!