3d - 2d hash function

Started by
6 comments, last by kirkd 15 years, 9 months ago
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.
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...
Could you tell us a bit more about how this is going to be used?
The Trouble With Robots - www.digitalchestnut.com/trouble
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!
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.
The reason for using this scheme is to avoid flickering that happens if I use screen coordinates.

What does LCG stand for?
LCG stands for 'Linear Congruential Generator', a simple type of pseudo random number generator.

http://en.wikipedia.org/wiki/Linear_congruential_generator

I still don't really understand what you're trying to do, so I can't say much more at this point.
The Trouble With Robots - www.digitalchestnut.com/trouble
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.

This topic is closed to new replies.

Advertisement