POV-Ray : Newsgroups : povray.general : Bug with noise generator Server Time
23 Dec 2024 22:33:00 EST (-0500)
  Bug with noise generator (Message 1 to 3 of 3)  
From: Zohar
Subject: Bug with noise generator
Date: 27 Jun 2003 17:50:02
Message: <web.3efcbb174718e7c3d0082e520@news.povray.org>
Hi,
I think I found a couple of bugs with the noise generator.
I downloaded the source code for POV-Ray 3.5 for windows, to see how noise
is generated. When reviewing the source, I saw the following:

In the POV-Ray Core project,
in the file "Texture.cpp",
in the function "static void InitSolidNoise (void)",

there is a section of code designed to generate random gradient vectors,
which are  uniformly distributed on the unit sphere. There are 2 bugs with
that:
1. There is a loop there, with a condition that is supposed to "trash" any
random vector which is outside the sphere. The condition should be OR, not
AND:

The code for each random vector generation looks something like that:

   do {
      Find a random vector in the unit cube.
      s = the length of the vector, squared.
   } while ((s > 1.0) && (s < 1.0e-5));

   Normalize the vector;

The condition is a contradiction, and should have been:
   "while ((s > 1.0) || (s < 1.0e-05))"

This bug causes the vectors to be non-uniformly distributed on the sphere.

2. In general, this technique will not produce uniform distribution of
vectors even when the bug is fixed (because the random values are actually
a discrete set of values), but I guess some compromises are tolerable, and
probably invisible (Who can tell that the noise is not exactly uniform?...)

Zohar Leder,
zoh### [at] yahoocom


Post a reply to this message

From: Wolfgang Wieser
Subject: Re: Bug with noise generator
Date: 28 Jun 2003 03:38:46
Message: <3efd4605@news.povray.org>
You'd better post this to povray.programming. 
I'm including a full-quote here so that the complete message appears on 
p.programming. 

Zohar wrote:
> Hi,
> I think I found a couple of bugs with the noise generator.
> I downloaded the source code for POV-Ray 3.5 for windows, to see how noise
> is generated. When reviewing the source, I saw the following:
> 
> In the POV-Ray Core project,
> in the file "Texture.cpp",
> in the function "static void InitSolidNoise (void)",
> 
> there is a section of code designed to generate random gradient vectors,
> which are  uniformly distributed on the unit sphere. There are 2 bugs with
> that:
> 1. There is a loop there, with a condition that is supposed to "trash" any
> random vector which is outside the sphere. The condition should be OR, not
> AND:
> 
> The code for each random vector generation looks something like that:
> 
>    do {
>       Find a random vector in the unit cube.
>       s = the length of the vector, squared.
>    } while ((s > 1.0) && (s < 1.0e-5));
> 
>    Normalize the vector;
> 
> The condition is a contradiction, and should have been:
>    "while ((s > 1.0) || (s < 1.0e-05))"
> 
ACK. 

> This bug causes the vectors to be non-uniformly distributed on the sphere.
> 
> 2. In general, this technique will not produce uniform distribution of
> vectors even when the bug is fixed (because the random values are actually
> a discrete set of values), but I guess some compromises are tolerable, and
> probably invisible (Who can tell that the noise is not exactly
> uniform?...)
> 
> Zohar Leder,
> zoh### [at] yahoocom


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Bug with noise generator
Date: 28 Jun 2003 04:02:09
Message: <3efd4b81@news.povray.org>
In article <web.3efcbb174718e7c3d0082e520@news.povray.org> , "Zohar" 
<zoh### [at] yahoocom> wrote:

>    do {
>       Find a random vector in the unit cube.
>       s = the length of the vector, squared.
>    } while ((s > 1.0) && (s < 1.0e-5));
>
>    Normalize the vector;
>
> The condition is a contradiction, and should have been:
>    "while ((s > 1.0) || (s < 1.0e-05))"

Indeed, the current code does not make sense.  This is a bug.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

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