POV-Ray : Newsgroups : povray.off-topic : Random vector through a hemisphere? : Re: Random vector through a hemisphere? Server Time
11 Oct 2024 03:17:32 EDT (-0400)
  Re: Random vector through a hemisphere?  
From: Severi Salminen
Date: 19 Feb 2008 14:05:50
Message: <47bb288e$1@news.povray.org>
scott wrote:

>> What I don't get is the sqrt(rand()). Why sqrt? Why not just rnd()? Does
>> the sqrt give us the cosine distribution and should remove the need to
>> later scale by taking cosine of the angle between normal and the light
>> ray?
> 
> No, you are simply choosing a fixed Y position, which then defines a
> ring around the sphere of possible points.  Then phi is used to choose a
> point at random on this ring which gives you the final point.

I made a few more tests. And it really seems to be that if you use
cosine weighted distribution (with sqrt around y -> less rays at
equator, more at pole) you don't need to calculate cosine at all during
tracing! Benefits:

1. No need to do cosine calculation. This might be good/bad depending on
how you create the cosine weighted rays and how you would've calculated
the cosine. At least on my program it is faster to do one sqrt() than to
calculate the cosine of two vectors with dot product of the two.

A much bigger benefit:

2. It seems that you get less variance with this weighted method because
 rays coming near the normal give more information than rays coming from
equator. I guess this is called "importance sampling".

I'm testing this now and the new method gives identical results after
about 250 passes compared to about 360 passes of the old method. Judged
by my eye. And in addition each pass takes 10% less time than the old one!

So a BIG improvement!! That is if I'm not missing something important here.

I have to find a way to analyze the actual variance (noisiness) of the
image so that I don't have to trust my eyes. Any ideas?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.