|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I've run into an interesting and totally unexpected situation in v3.6.1 while
animating, trying to produce some random values from frame to frame. I'm seeing
repeating patterns in the values; nothing that I try eliminates them.
The problem arose by using seed(clock) or seed(frame_number) in my SDL scene to
generate different random seed streams for each frame (a standard method?) then
pulling only one rand() value from that per frame--which made the patterns very
apparent. I *thought* that by simply throwing some multiplier value 'M'
at seed(M*clock) or seed(M*frame_number)--just one time in my POV scene, to use
for the entire animation--would give me 'obvious' random numbers from frame to
frame. Unfortunately, not so. There are, to my great surprise, clear
*almost*-repeating rand() patterns, no matter what seed values I use. And it
shows up quite quickly in animation--usually over 5 to 10 frames. I've included
some small test code. A few newsgroup posts mention that the current
random-number-generator in POV may need to be improved; my animation indicates
that as well.
The near-repetition of rand() is more apparent with certain seed values than
with others, but there are--in my limited experimentation--always patterns, if
you're patient enough to discern them. It's especially obvious when using
strict integer multiples for M--3,6,9,12, for example. Actually, any multiple
of any integer. So simply using clock or frame_number to change the seed value
from frame to frame presents a problem, as they both count up linearly.
I had always thought (perhaps wrongly) that any particular value for seed would
produce a totally different rand() sequence...different enough to 'appear'
random, in any case, with no discernible pattern. Instead, it's as if a great
many seed() values are falling across or interacting with some kind of built-in
seed 'frequency.' My own analogy is light waves interfering--two waves of
different frequencies (one of them non-varying), interacting to form crests and
troughs. Or pure sine-wave sound tones causing 'beats.'
So, practically speaking: How do I get *obviously* random values in animation,
across frames? I'm stuck. Trying different schemes to vary seed hasn't worked so
far (although I haven't exhausted the idea yet.) Perhaps this:
#declare temp_seed = seed(frame_number);
#declare real_seed = seed(M*frame_number*sqrt(rand(temp_seed)));
Or this..
#declare temp_seed = seed(frame_number);
#declare real_seed = M*sqrt(clock)*rand(temp_seed);
Haven't tried these yet. (Such ideas have endless permutations!) Of course, they
could simply be substituting one pattern for another.
Here's the test code, to show the situation. Run a 100-frame animation, with
clock 0 to 1. It gives seed() a different integer for each frame, counting up
in integer multiples. The resulting visual pattern becomes apparent quite
quickly. (For fun, set multiplier M to 1000 to see an extreme situation; or 12,
for yet another clear pattern):
#declare M = 1; // or any integer--or *any* value >= 1
#declare P = seed(M*frame_number)
sphere{0,1
texture{
pigment{rgb 1}
finish{
ambient 1
diffuse 0
}
}
translate 20*rand(P)*y
}
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Not that I have any idea about the inner working of POV's rand() generator - but
did you also try *dividing* clock or frame_number?
Maybe the integer part of the seed() argument is thrown away and only the
fraction is used?
Post a reply to this message
|
|
| |
| |
|
|
From: Thorsten Froehlich
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 23 Jan 2009 17:02:29
Message: <497a3e75$1@news.povray.org>
|
|
|
| |
| |
|
|
Kenneth wrote:
> I've run into an interesting and totally unexpected situation in v3.6.1 while
> animating, trying to produce some random values from frame to frame. I'm seeing
> repeating patterns in the values; nothing that I try eliminates them.
No, because so is the nature of a simple random number generator.
Thorsten
Post a reply to this message
|
|
| |
| |
|
|
From: Chris B
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 23 Jan 2009 17:51:41
Message: <497a49fd$1@news.povray.org>
|
|
|
| |
| |
|
|
"Kenneth" <kdw### [at] earthlinknet> wrote in message
news:web.497a1e5215dcf5ebf50167bc0@news.povray.org...
> I've run into an interesting and totally unexpected situation in v3.6.1
> while
> animating, trying to produce some random values from frame to frame. I'm
> seeing
> repeating patterns in the values; nothing that I try eliminates them.
> ... snip ...
> So, practically speaking: How do I get *obviously* random values in
> animation,
> across frames? I'm stuck. Trying different schemes to vary seed hasn't
> worked so
> far (although I haven't exhausted the idea yet.)
You could try using the same seed in each frame, using the frame_number or a
multiple of it to step through to a fresh part of the pseudo random sequence
. The following example throws away one for each frame that's gone before.
If you use 10 in a frame you could loop 10 times as far through the stream.
#declare P = seed(1);
#local I = 0;
#while (I<frame_number)
#local ThrowAway = rand(P);
#end
Post a reply to this message
|
|
| |
| |
|
|
From: Nicolas Alvarez
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 23 Jan 2009 21:52:54
Message: <497a8286@news.povray.org>
|
|
|
| |
| |
|
|
clipka wrote:
> Maybe the integer part of the seed() argument is thrown away and only the
> fraction is used?
Other way around, as far as I know. The seed value is truncated.
Post a reply to this message
|
|
| |
| |
|
|
From: Warp
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 24 Jan 2009 06:00:42
Message: <497af4da@news.povray.org>
|
|
|
| |
| |
|
|
Kenneth <kdw### [at] earthlinknet> wrote:
> I've run into an interesting and totally unexpected situation in v3.6.1 while
> animating, trying to produce some random values from frame to frame. I'm seeing
> repeating patterns in the values; nothing that I try eliminates them.
POV-Ray uses a linear congruential generator as RNG, and those tend to
produce patterns in certain situations.
What you can do to get a more random sequence is this:
1) On the first frame seed the RNG with whatever value (eg. 0).
2) Then pull a value with rand(), multiply it by a large value and
#write it to a file. Then use the value in your scene in any way
you want.
3) In subsequent frames #read that value from the file and give it to seed()
4) Repeat the steps 2 and 3.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"clipka" <nomail@nomail> wrote:
> Not that I have any idea about the inner working of POV's rand() generator - but
> did you also try *dividing* clock or frame_number?
>
> Maybe the integer part of the seed() argument is thrown away and only the
> fraction is used?
My own experience is that seed() values less than 1 result in *almost*
NON-varying rand()values--in my animation test, anyway, when extracting only
one rand() number per frame--so I'm guessing that POV rounds the seed value up
or down to an integer before pulling a rand()sequence. Using something like
seed(pi*frame_number) produces a pattern as well.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Thorsten Froehlich <tho### [at] trfde> wrote:
> Kenneth wrote:
> > I've run into an interesting and totally unexpected situation in v3.6.1 while
> > animating, trying to produce some random values from frame to frame. I'm seeing
> > repeating patterns in the values; nothing that I try eliminates them.
>
> No, because so is the nature of a simple random number generator.
>
Alas, so it seems. It's interesting that, when using only one seed() value--as
in a still image--rand() has no problem producing endlessly varying values from
it. (I've never *noticed* a pattern.) So rand() itself isn't the problem,
AFAIK.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris B" <nom### [at] nomailcom> wrote:
>
> You could try using the same seed in each frame, using the frame_number or a
> multiple of it to step through to a fresh part of the pseudo random sequence...
>
> #declare P = seed(1);
> #local I = 0;
> #while (I<frame_number)
> #local ThrowAway = rand(P);
> #declare I = I + 1; // added by Kenneth ;-)
> #end
That's quite interesting, and it makes great sense--it pulls a nice random value
for each frame. I'll try it! It's one of those solutions where I smack my
forehead and say, "Of course!" I had a funny feeling that some kind of #while
loop might be a solution, though how and where had me baffled. I'll report back
with the results.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> Kenneth <kdw### [at] earthlinknet> wrote:
> > I've run into an interesting and totally unexpected situation in v3.6.1 while
> > animating, trying to produce some random values from frame to frame. I'm seeing
> > repeating patterns in the values; nothing that I try eliminates them.
>
> POV-Ray uses a linear congruential generator as RNG, and those tend to
> produce patterns in certain situations.
>
> What you can do to get a more random sequence is this:
>
> 1) On the first frame seed the RNG with whatever value (eg. 0).
> 2) Then pull a value with rand(), multiply it by a large value and
> #write it to a file. Then use the value in your scene in any way
> you want.
> 3) In subsequent frames #read that value from the file and give it to seed()
> 4) Repeat the steps 2 and 3.
>
> --
> - Warp
Another interesting idea; thanks. I see that it would produce what's needed:
Each subsequent frame's seed is using the rand() value from the previous frame
for ITS value; so even though there are patterns, each new frame sees what
amounts to a different pattern (if I'm thinking correctly.) Nice.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |