I am doing volumetric raycasting and curently working on depth jitter. I have 3D position on ray and want to sample 2D noise texture to jitter the depth.

Function for converting (or hashing) 3D position to 2D have to produce absolutely different numbers for a little changes (especialy because i am sampling in texture space so sample values differs very very little) and have to be "shader-wise" - so forget about branches, cycles etc.

I'm looking forward for yours nice and fast solutions.

  • \$\begingroup\$ It's not perfect but you couldn't you just modify ray length based on the texture coords of the position you hit? \$\endgroup\$ – t123 Feb 8 '11 at 18:40
  • \$\begingroup\$ @tm1rbrt I don't hit anything, volumetric raycasting samples through volume (like 3D array) and gathering data. And i have texcoords and they are the values which i want to hash. But great idea for regular raycasting. \$\endgroup\$ – Notabene Feb 8 '11 at 19:23
  • 1
    \$\begingroup\$ I solved this very easily at the end. I just shift the ray origin in a ray direction by a noise texture (if i need just one sample, i can use output texture coords for sampling noise). It is easy and working. But the question is still very interesting, though. \$\endgroup\$ – Notabene Feb 8 '11 at 19:31

I'm not sure it is quite what you are looking for, but this article on spatial hashing is interesting (and has some HLSL code as well): perfect spatial hashing.

| improve this answer | |
  • \$\begingroup\$ Something a little more useful might be to make a pair of value-noise 3D texture (i.e., a pure random value at each texel--instead of, say, Perlin noise), and sample them both using your 3D position. Using different scalings on the texture coordinates you can change the period of sampling one each, and that could be useful. (rereading your last comment it seems like you may have already done something like this) \$\endgroup\$ – ChrisE Feb 8 '11 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.