POV-Ray : Newsgroups : povray.advanced-users : Stochastics expertise needed Server Time
9 Oct 2026 11:05:40 EDT (-0400)
  Stochastics expertise needed (Message 1 to 26 of 26)  
From: clipka
Subject: Stochastics expertise needed
Date: 25 Aug 2016 20:15:43
Message: <57bf8a2f$1@news.povray.org>
Folks, I could need a bit of help with a maths problem.

I need an algorithm to generate random points on the surface of a
sphere, conforming to the following criteria:

- The distribution must be radially symmetric around the Y axis.
- The sample density should be roughly uniform, except for a pronounced
peak centered at +Y (but not -Y!)
- For each random point generated, the algorithm also needs to compute
the theoretical sample density at that location.
- The algorithm must be reasonably fast.

Ideally, the algorithm should also have the following properties:

- The density should fall off smoothly from the peak.
- The algorithm should have a parameter to govern the "tightness" of the
peak.
- The sample density away from the peak should approach (but not reach!)
zero.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 04:30:00
Message: <web.57bffd228629941bdadd19850@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

I suppose no. 16 on http://mathworld.wolfram.com/SpherePointPicking.html hints
at the solution: You "just" need a space defined by a vector that meets the
above criteria. The "distortion" of the space at the selected point will then
allow computation of a scalar that should have some relation to the sample
density. Basically, with the shape of the unit hull you can also shape the
sample density by projecting it back on a unit sphere.

However, I am not sure if the "incorrect" example on that page won't
already solve most of your problem.


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 05:36:31
Message: <57c00d9f@news.povray.org>
Am 26.08.2016 um 10:28 schrieb Thorsten Froehlich:

> I suppose no. 16 on http://mathworld.wolfram.com/SpherePointPicking.html hints
> at the solution: You "just" need a space defined by a vector that meets the
> above criteria. The "distortion" of the space at the selected point will then
> allow computation of a scalar that should have some relation to the sample
> density. Basically, with the shape of the unit hull you can also shape the
> sample density by projecting it back on a unit sphere.

"_hints_ at the solution"... "_some_ relation to the sample density"...
(emphasis added)... I think I see a pattern there ;)

> However, I am not sure if the "incorrect" example on that page won't
> already solve most of your problem.

Not exactly:

- It has samples bunching up at both poles, not just +Y.
- The tightness of the bunching-up cannot be tweaked.
- The off-peak density does not approach zero.


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 11:45:00
Message: <web.57c063998629941bb488d9aa0@news.povray.org>
I'm busy at the moment, but:

define a sphere with radius 0.5
pow(x,2) + pow(y,2) = 0.5

so pow(y,2) = 0.5 - pow(x,2)

and y = sqrt ( 0.5 - pow(x,2))

translate y*0.5

y = sqrt ( 0.5 - pow(x,2)) +0.5

make your function equal to the sin of that times pi/2 so that the function
smoothly increases from 0 to 1

add the smallest number POV will work with to that (1E-whatever)

Multiply that by a line equation, the slop of which is the tightness

I will give this some more thought


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 12:50:01
Message: <web.57c072418629941bb488d9aa0@news.povray.org>
Try this as a starting point

// spherical pattern
// Bald Eagle 2016
#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "textures.inc"
#include "rand.inc"

camera {
 location <0, 0.5, -2>
 look_at  <0, 0.5, 0>
}


light_source {<20, 50, -100> White shadowless}


#declare R = 0.5;
#declare Tiny = 0.000001;

#declare Stream = seed (123);

#for (Point, 1, 5000)
    #declare Variable = (VRand_On_Sphere(Stream)*0.5 + <0, 0.5, 0>);
    #debug concat( "Variable = ", vstr(3, Variable, ", ", 3, 3), " \n")
    #declare Color = <abs(pow (Variable.y, 1))+Tiny, 0, 0>;
    #debug concat( "Color = ", vstr(3, Color, ", ", 3, 3), " \n")
    sphere {Variable, 0.01 pigment {rgb Color}}
#end


Post a reply to this message

From: MichaelJF
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 13:15:01
Message: <web.57c078cf8629941b69e826dc0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

I see a certain contradiction because a uniform distribution cannot fall off
smoothly to zero. My first idea is to use a 2D-normal distribution and project
it onto the sphere. One can play with the sigma(s) to sharpen the peak and/or
use weighted averages of such distributions.

Best regards,
Michael


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 14:05:01
Message: <web.57c083f28629941bb488d9aa0@news.povray.org>
I see the "probability" aspect of this now...
no time to code it at the moment.

define a spline with a probability function
sparse near 0, denser near 1, maybe exponentially peaking at 1

choose rand between 0 and 1
pluck out y value from spline

then it's just a sphere in that y gradient


Post a reply to this message

From: LanuHum
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 16:20:00
Message: <web.57c0a3b08629941b7a3e03fe0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

Let me simulate it in Blender. I use a system of particles and particle_map.
We have invented a bicycle.
Blender - your problem?


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 16:40:00
Message: <web.57c0a88b8629941bb488d9aa0@news.povray.org>
"LanuHum" <Lan### [at] yandexru> wrote:
> We have invented a bicycle.

likely.  ;)

// Log spherical pattern
// Bald Eagle 2016
#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "textures.inc"
#include "rand.inc"


#declare R = 5;


camera {
 location <0, R, -15>
 look_at  <0, R, 0>
}


light_source {<20, 50, -100> White shadowless}



#declare Tiny = 0.000001;
#declare Stream = seed (123);
#declare Stream2 = seed (456);
#declare Stream3 = seed (789);

#declare Sphere_Spline =
  spline {
    linear_spline
   -0.25, <-0.25, 0.0, 0>,
    0.00, <0.00000000000000000001, 0.0, 0>,

    1.00, <1, 0, 0>
    1.1 , <1.1, 0, 0>
  } //-------------------




#declare Sphere1 =
union {
    #for (Point, 1, 1000)
        #declare Phi =  RRand(0, 2*pi, Stream);

        #declare Variable2 = RRand(1.00000001, 10, Stream2);

        #declare Theta = -pi*Sphere_Spline(1-log(Variable2))+(pi/2);

    #declare X = R * cos (Theta.x) * sin (Phi);
    #declare Z = R * cos (Theta.x) * cos (Phi);
    #declare Y = R * sin (Theta.x) + R;

    sphere {<X, Y, Z>, 0.01 pigment {Red} }
    #end
}



object {Sphere1}


Post a reply to this message

From: LanuHum
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 17:45:00
Message: <web.57c0b8258629941b7a3e03fe0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "LanuHum" <Lan### [at] yandexru> wrote:
> > We have invented a bicycle.
>
> likely.  ;)
>
Tomorrow you will be asked to another location formula. The day after tomorrow
another. In each case the formula. Tired, you want to relax.
I have shown in the screenshots universal way: image_map.
Draw Mandelbrot grayscale on any object - no problem. :)))))


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 18:40:01
Message: <web.57c0c5018629941b5e7df57c0@news.povray.org>
"LanuHum" <Lan### [at] yandexru> wrote:

> Tomorrow you will be asked to another location formula. The day after tomorrow
> another. In each case the formula. Tired, you want to relax.
> I have shown in the screenshots universal way: image_map.
> Draw Mandelbrot grayscale on any object - no problem. :)))))

Yes, my Russian friend, but we ask many things of our good friend Christoph, and
he works hard for us to deliver the goods.
I'm always glad to help a friend, and I always look forward to seeing your
interpretations and experiments, translating between Blender and POV-Ray.

I think that he wants a function, an algorithm, that can be called in the source
code of POV-Ray, in order to perform a certain task.
It needs to be a method whereby any given point can be selected at random, and
the function will evaluate a probability density on the sphere.
It seems a lot to me like a highlight model.

I had many things to do today, and did the best I could on short notice, just to
illustrate the basic idea.  With some refinements, perhaps this evolve into
what's needed.

I am not sure I understand the banding on your image map method.

I think clipka needs something that is a very dense cluster at y=1 and hardly
anything at all near y=0.  I'm not sure my model is accurate, but it was a quick
brainstorming exercise.


Post a reply to this message

From: lelama
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 19:20:00
Message: <web.57c0ce5f8629941b7a63dc9f0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
with  y in [-1,1] and r=sqrt(1-y^2).

Then you choose t uniformly, and for y, you choose your distribution as you want
(this is you free parameter). Then the density around a point x,y,z depends only
on y.

If you want an explicit density with associated random points on the sphere in
povray, you may choose a density d(y) pieciwise affine : constant equal to c1>0
on an interval [-1,p] and growing from c1 to c2 when y is  in [p,1].  Then you
choose randomly and uniformly  (y,v) in [-1,1]x[0,c2]. If v>d(y), throw your
point away. If v<=d(y), choose t randomly and put the point P(t,y) on the
sphere.

This shoud satisfy all your needs if I'm not wrong.


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 22:21:19
Message: <57c0f91f$1@news.povray.org>
Am 27.08.2016 um 00:38 schrieb Bald Eagle:

> I think that he wants a function, an algorithm, that can be called in the source
> code of POV-Ray, in order to perform a certain task.
> It needs to be a method whereby any given point can be selected at random, and
> the function will evaluate a probability density on the sphere.
> It seems a lot to me like a highlight model.

You've hit the nail right on the head :)

This is intended to become part of a stochastic sampling mechanism,
intended to compute both diffuse interreflections (as currently computed
by radiosity) /and/ blurred reflections (as currently computed by a
dedicated algorithm in UberPOV) in one go.

A simple procedure to achieve that would be as follows:


(1) Pick a random direction, using a uniform distribution.

(2) Trace a ray in that direction to compute how much light comes from
other objects in that driection.

(3) Pretending that we have a light source in that direction, use the
established algorithms for diffuse, specular and phong to compute the
effective brightness the surface would exhibit if it was illuminated
only from this direction.

(4) Repeat, summing up the effective brightness for illumination from a
handful of directions.

(5) Divide the computed sum by the number of rays shot.


However, while this approach is ok for materials where the diffuse
contribution dominates, it's far from ideal when highlights are the
dominant component, since in that case we waste a lot of energy on
directions that contribute virtually nothing.

What we need to do is change the probability distribution of the random
directions. Ideally, the distribution should match the combined BRDF of
the diffuse, specular and phong components, but that might be difficult
to achieve, and besides all we need is a somewhat /similar/
distribution. So that's what I'm searching for.

Obviously however, if we just plug in a different random distribution
into the above mechanism, the regions with high distribution will tend
to be overrepresented in the the result; the solution to that is to
weigh the individual directions' contributions by the inverse of the
probability for picking that particular direction. But that's where I
start to struggle.


To keep things simple, I've decided /not/ to aim for a distribution that
matches a certain combined BRDF, but rather use two different
distributions: One custom-tailored for highlights, and one
custom-tailored for diffuse (cos-weighted should be ideal there). I
would then choose between the two distributions alternatingly or at random.


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 22:40:00
Message: <web.57c0fd6f8629941b5e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> You've hit the nail right on the head :)

Here's my crappy code, but best looking distribution for the day (based on my
abyssmal histograph).

I think it's a matter of defining the function / spline / clustering of the
random vector - everything else looks fairly straightforward.

I especially wanted to avoid the wasteful hit-or-miss style algorithm - so I
made sure every random number returns a "valid" result.

I'd say this looks like a statistics specialty, or given the spherical-based
distribution - a quantum mechanics-type function.

I hope this acts as a first pointer in the right direction.
{I started to struggle right at Theta and Phi.   ;)  :D   }

##############################################################

// spline / sqrt spherical pattern
// Bald Eagle 2016
#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "textures.inc"
#include "rand.inc"


#declare R = 5;


camera {
 location <0, R, -20>
 look_at  <0, R, 0>
 right     x*image_width/image_height
 up y
}


light_source {<20, 50, -100> White shadowless}



#declare Tiny = 0.000001;
#declare Stream = seed (123);
#declare Stream2 = seed (456789);
#declare Stream3 = seed (789);

#declare Sphere_Spline =
  spline {
    linear_spline
   //-0.25, <-0.25, 0.0, 0>,
    0.00, <0.00000000000000000001, 0.0, 0>,
 0.1 <0.9, 0, 0>,
    1.00, <1, 0, 0>
   // 1.1 , <1.1, 0, 0>
  } //-------------------


#declare Samples = 10000;
#declare Histograph = array [60]
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0};

#declare Sphere1 =
union {
    #for (Point, 1, Samples)
        #declare Phi =  RRand(0, 2*pi, Stream);

        #declare Variable2 = RRand(0, 1, Stream2);
        //#declare Variable2 = RRand(1.00000001, 10, Stream2);

  //#declare Theta = (pi*Sphere_Spline(Variable2).x)-(pi/2);
  #declare Theta = (pi*sqrt(Sphere_Spline(Variable2).x))-(pi/2);
        //#declare Theta = (-pi*(1-Sphere_Spline(log(Variable2)).x))+(pi/2);
        //#declare Theta = (-pi*abs(Sphere_Spline(pow(1-log(Variable2),
3)).x))+(pi/2);

    #declare X = R * cos (Theta.x) * sin (Phi);
    #declare Z = R * cos (Theta.x) * cos (Phi);
    #declare Y = R * sin (Theta.x) + R;

 #declare Histograph [int((Y/(2*R))*59)] = Histograph [int((Y/(2*R))*59)]+1;

    sphere {<X, Y, Z>, 0.01 pigment {Red} }
    #end
}



object {Sphere1}

cylinder {<0, 0, 0>, <6, 0, 0>, 0.05 pigment {Blue} }
cylinder {<0, 0, 0>, <0, R, 0>, 0.05 pigment {Blue} }
#for (GraphX, 0, 60-1)
 sphere {<GraphX/10, Histograph[GraphX]/10, 0>, 0.1 pigment {Green}}// translate
-y*R}
#end


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 23:49:51
Message: <57c10ddf$1@news.povray.org>
Am 27.08.2016 um 01:18 schrieb lelama:

> You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
> with  y in [-1,1] and r=sqrt(1-y^2).
> 
> Then you choose t uniformly, and for y, you choose your distribution as you want
> (this is you free parameter). Then the density around a point x,y,z depends only
> on y.
...
> This shoud satisfy all your needs if I'm not wrong.

Gee, I you have indeed nailed it!


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 02:24:09
Message: <57c13209$1@news.povray.org>
Am 27.08.2016 um 05:49 schrieb clipka:
> Am 27.08.2016 um 01:18 schrieb lelama:
> 
>> You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
>> with  y in [-1,1] and r=sqrt(1-y^2).
>>
>> Then you choose t uniformly, and for y, you choose your distribution as you want
>> (this is you free parameter). Then the density around a point x,y,z depends only
>> on y.
> ....
>> This shoud satisfy all your needs if I'm not wrong.
> 
> Gee, I you have indeed nailed it!

Hm... this still leaves me with a quest for an easy-to-generate random
distribution in the range [0..1) with a nicely configurable peak at 0,
and an easy-to-compute probability density function.

I guess I want the derivative of the probability density function to be
zero at the peak, and ideally also at 1.


Post a reply to this message

From: lelama
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 05:30:00
Message: <web.57c15b268629941b7a63dc9f0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 27.08.2016 um 05:49 schrieb clipka:
> > Am 27.08.2016 um 01:18 schrieb lelama:
> >
> >> You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
> >> with  y in [-1,1] and r=sqrt(1-y^2).
> >>
> >> Then you choose t uniformly, and for y, you choose your distribution as you want
> >> (this is you free parameter). Then the density around a point x,y,z depends only
> >> on y.
> > ....
> >> This shoud satisfy all your needs if I'm not wrong.
> >
> > Gee, I you have indeed nailed it!
>
> Hm... this still leaves me with a quest for an easy-to-generate random
> distribution in the range [0..1) with a nicely configurable peak at 0,
> and an easy-to-compute probability density function.
>
> I guess I want the derivative of the probability density function to be
> zero at the peak, and ideally also at 1.

Hi,

There is a proposal at the end of my previous message. Using uniform
distribution for y,t,d and throwing away some "bad" points, you get
whatever distribution you want. If you don't like the piecewised
affine d that I suggested (the derivative of the density probabilty is not zero
at y=1, so maybe not suitable for you), you can choose any positive function d
instead with the same construction.

By the way, the parameter c1 is not useful in my formula for the function d. One
can take c1=1 and adjust only the parameters p ( p close to 1 means that the
peak is very localised around y=1 ) and c2 ( the higher the c2, the bigger the
difference of intensity between y=1 and the zone with low uniform intensity).

have a good day,


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 06:13:24
Message: <57c167c4$1@news.povray.org>
Am 27.08.2016 um 11:26 schrieb lelama:

>> Hm... this still leaves me with a quest for an easy-to-generate random
>> distribution in the range [0..1) with a nicely configurable peak at 0,
>> and an easy-to-compute probability density function.
>>
>> I guess I want the derivative of the probability density function to be
>> zero at the peak, and ideally also at 1.
> 
> Hi,
> 
> There is a proposal at the end of my previous message. Using uniform
> distribution for y,t,d and throwing away some "bad" points, you get
> whatever distribution you want. If you don't like the piecewised
> affine d that I suggested (the derivative of the density probabilty is not zero
> at y=1, so maybe not suitable for you), you can choose any positive function d
> instead with the same construction.

The monte-carlo approach of generating arbitrarily distributed random
numbers is only practical if the points to throw away are reasonably
few, in other words if d(y)>>0 for most of the function. Unfortunately
that's specifically not the case I'm aiming for -- I want d(y)>>0 only
in a small portion near y=0.


Post a reply to this message

From: lelama
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 07:05:01
Message: <web.57c172d08629941b7a63dc9f0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 27.08.2016 um 11:26 schrieb lelama:
>
> >> Hm... this still leaves me with a quest for an easy-to-generate random
> >> distribution in the range [0..1) with a nicely configurable peak at 0,
> >> and an easy-to-compute probability density function.
> >>
> >> I guess I want the derivative of the probability density function to be
> >> zero at the peak, and ideally also at 1.
> >
> > Hi,
> >
> > There is a proposal at the end of my previous message. Using uniform
> > distribution for y,t,d and throwing away some "bad" points, you get
> > whatever distribution you want. If you don't like the piecewised
> > affine d that I suggested (the derivative of the density probabilty is not zero
> > at y=1, so maybe not suitable for you), you can choose any positive function d
> > instead with the same construction.
>
> The monte-carlo approach of generating arbitrarily distributed random
> numbers is only practical if the points to throw away are reasonably
> few, in other words if d(y)>>0 for most of the function. Unfortunately
> that's specifically not the case I'm aiming for -- I want d(y)>>0 only
> in a small portion near y=0.


Hmm, Yes, I see your objection.

A possibility then is to divide the surface under the graph of the function d
into smaller parts. For instance, in the piecewise affine case, the area under
the graph can be decomposed as a union of a rectangle R with measure r and a
triangle T with measure t . It is not too hard to make a uniform distribution
for points in R and an other uniform distribution for points in T.

Let t0,r0 be integers such that (t0,r0) is a vector proportional to the
measusrements (t,r) of the triangle and the rectangle.

Then choosing alternativly t points in the Triangle and r points in the
Rectangle with the uniform distributions discussed above yield the required
distribution without the problem you mentioned.

hth,
Laurent.


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 07:40:00
Message: <web.57c17b018629941b5e7df57c0@news.povray.org>
I have to be out for most of the day today, but I figured if we were searching
for a "bicycle" that already exists, then a search ought to pick up a nice
parametrizable equation.

I started off with blackbody and Maxwell-Boltzmann distributions, but then
enough coffee kicked in...   ;)

https://www.google.com/#q=brdf+code

http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
https://support.solidangle.com/pages/viewpage.action?pageId=5800819

https://www.google.com/#q=highlight+reflection+distribution


What's the "input" for this algorithm?  A vector?   I'm assuming that the output
is just the vector on the unit sphere.  I'm trying to visualize where this
"plugs in" to the pixel-evaluation chain of events.


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 08:41:49
Message: <57c18a8d$1@news.povray.org>
Am 27.08.2016 um 13:35 schrieb Bald Eagle:
> I have to be out for most of the day today, but I figured if we were searching
> for a "bicycle" that already exists, then a search ought to pick up a nice
> parametrizable equation.
> 
> I started off with blackbody and Maxwell-Boltzmann distributions, but then
> enough coffee kicked in...   ;)
> 
> https://www.google.com/#q=brdf+code
> 
> http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
> https://support.solidangle.com/pages/viewpage.action?pageId=5800819
> 
> https://www.google.com/#q=highlight+reflection+distribution
> 
> 
> What's the "input" for this algorithm?  A vector?   I'm assuming that the output
> is just the vector on the unit sphere.  I'm trying to visualize where this
> "plugs in" to the pixel-evaluation chain of events.

Congratulations, it seems like you've just found out what a BRDF is...
now to my problem of generating random numbers with a distribution that
is reasonably close to a given BRDF (in order to get an efficient
sampling), while keeping track of the probability of the numbers we're
generating (in order to compensate for the virtually inevitable mismatch) ;)


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 1 Sep 2016 18:20:00
Message: <web.57c8a8e08629941b5e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Congratulations, it seems like you've just found out what a BRDF is...
> now to my problem of generating random numbers with a distribution that
> is reasonably close to a given BRDF (in order to get an efficient
> sampling), while keeping track of the probability of the numbers we're
> generating (in order to compensate for the virtually inevitable mismatch) ;)

Thanks!   Do I win a prize?   :D

So, after skimming some of the literature, I have a much better idea of what
you're specifically looking for - some form of Importance Sampling.

If you can post a graph of the BRDF that you're trying to simulate for the
purposes of your sampling algorithm, or a means of plotting it themselves, then
that might give anyone following along a nudge forward.

It seems that for any given function plotted between A and B, the probability of
having X land in that interval is the integral (S) of that function.

So, for my square root spline sampling function, f(x) = pow(x, 0.5)
so S(pow(x, 0.5) = 1/1.5 * pow(x, 1.5).

Also,

My apologies, but I'm trying to figure out what you actually mean when you say
"keep track of the probability..."

Do you tallying up the actual results of the random sampling so that you can do
a summation and then divide by the number of random samples?


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 2 Sep 2016 01:30:30
Message: <57c90e76$1@news.povray.org>
Am 02.09.2016 um 00:17 schrieb Bald Eagle:

> So, after skimming some of the literature, I have a much better idea of what
> you're specifically looking for - some form of Importance Sampling.

Yes, that's what the experts call it.

> If you can post a graph of the BRDF that you're trying to simulate for the
> purposes of your sampling algorithm, or a means of plotting it themselves, then
> that might give anyone following along a nudge forward.

I can't. That's the crux of the matter: The algorithm needs to cope with
varying BRDFs. It might be Lambertian with a Phong highlight, or
Oren-Nayar with a Blinn-Phong highlight, or (in the future) maybe
Cook-Torrance, He-Torrance, Ward, Schlick, Lafortune, or whatever smart
brains may still come up with and someone decides to implement in POV-Ray.

I therefore intend to use a very simple approximation to generate my
sampling distribution, and compensate for the difference to the BRDF
(which, by the way, may actually not even be a true BRDF, such as
anything involving POV-Ray's brilliance model) by multiplying the
computed colour of the sample with the BRDF (which will actually be
hidden away in the sample computation) and then dividing it by the
probability that my sampling direction generator spits out that
particular sampling direction.

What exact formula to use is something I leave up to whoever can provide
a viable solution.

To give you a rouhg idea at what I'm aiming for, you might try the Phong
model:

    f(L,V) = k (Lm . V) ^n

where Lm is L mirrored at the surface normal.


> Also,
> 
> My apologies, but I'm trying to figure out what you actually mean when you say
> "keep track of the probability..."

What I mean by that is that I want to know the probability density
function of the sample directions.

> Do you tallying up the actual results of the random sampling so that you can do
> a summation and then divide by the number of random samples?

Something along those lines, yes. But I need to weigh the individual
samples by the probability density function of the sample direction
generator (or, more precisely, by the reciprocal thereof).


Post a reply to this message

From: scott
Subject: Re: Stochastics expertise needed
Date: 2 Sep 2016 02:39:06
Message: <57c91e8a@news.povray.org>
>> If you can post a graph of the BRDF that you're trying to simulate for the
>> purposes of your sampling algorithm, or a means of plotting it themselves, then
>> that might give anyone following along a nudge forward.
>
> I can't. That's the crux of the matter: The algorithm needs to cope with
> varying BRDFs. It might be Lambertian with a Phong highlight, or
> Oren-Nayar with a Blinn-Phong highlight, or (in the future) maybe
> Cook-Torrance, He-Torrance, Ward, Schlick, Lafortune, or whatever smart
> brains may still come up with and someone decides to implement in POV-Ray.

...or a BRDF created by interpolating real-life measurement data :-)


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 2 Sep 2016 03:38:48
Message: <57c92c88$1@news.povray.org>
Am 02.09.2016 um 08:39 schrieb scott:
>>> If you can post a graph of the BRDF that you're trying to simulate
>>> for the
>>> purposes of your sampling algorithm, or a means of plotting it
>>> themselves, then
>>> that might give anyone following along a nudge forward.
>>
>> I can't. That's the crux of the matter: The algorithm needs to cope with
>> varying BRDFs. It might be Lambertian with a Phong highlight, or
>> Oren-Nayar with a Blinn-Phong highlight, or (in the future) maybe
>> Cook-Torrance, He-Torrance, Ward, Schlick, Lafortune, or whatever smart
>> brains may still come up with and someone decides to implement in
>> POV-Ray.
> 
> ....or a BRDF created by interpolating real-life measurement data :-)

Or that, yes.

(And would that then be a naive interpolation of a data array, or maybe
a spherical harmonics-based approximation?)


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 2 Sep 2016 07:40:00
Message: <web.57c963eb8629941b5e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> I can't. That's the crux of the matter: The algorithm needs to cope with
> varying BRDFs. It might be Lambertian with a Phong highlight, or
> Oren-Nayar with a Blinn-Phong highlight, or (in the future) maybe
> Cook-Torrance, He-Torrance, Ward, Schlick, Lafortune, or whatever smart
> brains may still come up with and someone decides to implement in POV-Ray.

Well, for now, you can - if there were a set of equations for the BRDF's that
could be easily plotted over the range 0-1 or 0-pi, then the shape might inspire
an equation to mimic them.   Presumably you already have a few such equations
working with POV-Ray, and some of the special development versions.

I've thought about this a bit and will have some more to say and ask, but for
now:

Is there a way to take the models available and fit a curve to them?
Polynomials, or Taylor series, or something like that?

And now I'm off to work.


Post a reply to this message

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