Jump to content
  • Advertisement
Sign in to follow this  
Glatzemann

Signed Distance Field Direction

This topic is 2485 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 guys,

I have created a signed distance field (two dimensional) which contains the nearest distance to the boundary like in PixelJunk Shooter (described here: http://fumufumu.q-ga.../shooterGDC.pdf; pages 44 to 46). Now I want to calculate the direction to the nearest boundary for any given point. In the PixelJunk Shooter presentation they talk about gradients and four sample points around the given point, but I'm not very good with calculus.

Is there anyone who can easily explain how to do that? Some pseudo-code would be great :-)

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
It's probably easier to do with just three points:

double gradient_x = dist[x+1][y] - dist[x][y];
double gradient_y = dist[x][y+1] - dist[x][y];


You can then normalize the gradient vector and perhaps change its sign, and you'll get the vector that points where you want (approximately).

Share this post


Link to post
Share on other sites
This sounds really interesting. I will try this tomorrow morning. Thank you very much.

How will this look with more than three points? I think the result will be better in some cases with more sample points, isn't it?

Share this post


Link to post
Share on other sites
I just read the three pages of the PDF file you referenced. I think what they are doing is this:

double gradient_x = dist[x+1][y] + dist[x+1][y+1] - dist[x][y] - dist[x][y+1];
double gradient_y = dist[x][y+1] + dist[x+1][y+1] - dist[x][y] - dist[x+1][y];


This is more appropriate if you are going to assign this gradient to the whole square between (x,y) and (x+1,y+1).

Share this post


Link to post
Share on other sites
I've investigated this some more and found a very simple solution:
[
CODE]
double gradient_x = dist[x-1] - dist[x+1];
double gradient_y = dist[y-1] - dist[y+1];


After normalizing the result it looks smooth and nice :-)

Thank you guys for your help.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!