# 3d - 2d hash function

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 on other sites
Could you tell us a bit more about how this is going to be used?

##### 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 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 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 on other sites
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.

##### 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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633294
• Total Posts
3011242
• ### Who's Online (See full list)

There are no registered users currently online

×