• Advertisement
Sign in to follow this  

3d - 2d hash function

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

I am in need of a function that converts a 3d coordinate into a 2d one and make sure the output is as random as possible. I am using this to do a 2D lookup in map based on a 3d position. Right now I am using: val_x = x + z; val_y = y + z; But this is pretty bad as the value might not change on certain surfaces. I am going to implement this in a GPU shader so I would take simpler over more random(=faster), as long as it is pretty random.

Share this post


Link to post
Share on other sites
Advertisement
So this is even worse then I first thought because another thing needed is that input values close to one another should have similar output. What I mean is that if u increase the input by a small amount, the output should not greatly change but slowly "fade" to another value. This is because I will lots of aliasing issues otherwise.

My current version is:
value_x = mod(x, 2) + mod(z, 3);
value_y = mod(y, 2) + mod(z, 3);

This is just slightly better then my last.

I am starting to think that a 3d lookup table might be the only thing that suits my needs...

Share this post


Link to post
Share on other sites
I am using a map (3d actually) that has several jittered sample disks, one disk per 2D pixel to be correct. Now i am choosing what jitter disk to used (in a version of SSAO) based on the world postion of the pixel. Now I want to get a 2D position for the map (and jittered disk) from the 3d position vector and I therefore need to hash the 3d position to get a 2d position. And I want an algo that always varies the 2d coordinate when the 3d position changes. When using:
val_x = x + z;
val_y = y + z;
There are times when the changes in x, y and z "cancels" each other out and the hashed 2d coord does not change.

However, I am changing the algo a bit so that change of jittered disks is not as important. Still interested in suggestion for a hash algorithm though!

Share this post


Link to post
Share on other sites
I'm not really sure how suitable these are for your needs or why you need such a sophisticated mapping for SSAO, but here are a few ideas off the top of my head:

1) Planar projection.
2) Conversion to spherical coordinates, ignoring one of the coordinates.
3) Using on LCG of some sort with XYZ to generate XY.

Share this post


Link to post
Share on other sites
The reason for using this scheme is to avoid flickering that happens if I use screen coordinates.

What does LCG stand for?

Share this post


Link to post
Share on other sites
What about something simple like Principle Components or Sammon Mapping? Both project points from a higher dimensional space to a lower dimensional space while maintaining the relative pairwise distances as much as possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement