Jump to content


Random direction not so random


6 replies to this topic

#1 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 28 April 2012 - 03:01 PM

Is it possible to create a "random" direction on the hemisphere based on the point position on a surface, rather than using frand()? So that it is not so random locally, but in overall, it appear random enough?

I'm trying to make it so that if a ray hit a point (or within a radius) the random hemisphere reflected ray will be the same everytime.

#2 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 28 April 2012 - 06:06 PM

You could create a grid of evenly spread directions, then jitter each one based on some Perlin noise function.

Bu I don't think it sounds like a great idea. If you use it for sampling in a raytracer, you'll get weird artifacts.

#3 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 29 April 2012 - 04:04 AM

I was thinking of doing this for my render, because, when a ray hit a glossy surface, it shoot a random ray, so now it looks grainy like a photon or path tracer! I don't know how to make it otherwise!

#4 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 29 April 2012 - 05:44 AM

Yes, less random directions would make it look less grainy. But you would instead get banding. There's really no way around this.

#5 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 29 April 2012 - 06:04 AM

I know what you mean. So how do some renders produce super fast shadows that are so smooth??

#6 }:+()___ (Smile)

    Member

  • Members
  • PipPipPip
  • 169 posts

Posted 29 April 2012 - 02:17 PM

I think you can try following method.

First, pregenerate array of evenly distributed rays in full unit sphere, defRay[N].xyz.
Second, generate random rotation matrix M. For that you must generate true random point on 4D sphere (quaternion), it might be tricky but quite doable.
Third, spawn rays with directions dir[i] = normalize(N + M * defRay[i]), where N is unit surface normal.

That way you have rays distributed in hemisphere with density proportional to cos(N^dir) which is ideal for diffuse surfaces. True random rotation on every ray hit ensures mathematic correctness and reduces banding.
Sorry my broken english!

#7 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 29 April 2012 - 04:37 PM

I see what you mean. I'll give that a try, thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users