POV-Ray : Newsgroups : povray.advanced-users : Stochastics expertise needed Server Time
2 May 2024 07:15:56 EDT (-0400)
  Stochastics expertise needed (Message 11 to 20 of 26)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>
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

<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>

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