POV-Ray : Newsgroups : povray.programming : Retrieving OBJECT reference from media, pigment or pattern code ? Server Time
4 May 2024 03:14:26 EDT (-0400)
  Retrieving OBJECT reference from media, pigment or pattern code ? (Message 1 to 6 of 6)  
From: Antonio Ferrari
Subject: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 10 Oct 2007 09:40:00
Message: <web.470cd56a890b55134e64f15d0@news.povray.org>
Hi,
I'de like to know to obtain the current OBJECT pointer in the following
procedures:

- density_patter
- Evaluate_TPat
- Compute_Pigment
- evaluate_density_pattern
- sample_media
- Backtrace_Simulate_Media

Thanks.

Antonio


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 10 Oct 2007 09:56:07
Message: <470cd9f7$1@news.povray.org>
Antonio Ferrari wrote:
> I'de like to know to obtain the current OBJECT pointer in the following
> procedures:
> 
> - Evaluate_TPat

It is in the intersection (Isection->Object), the same goes for all patterns.

> - Compute_Pigment

Some as above.

> - Backtrace_Simulate_Media

Some as above.

> - sample_media

You can get it from the caller (see above).

What are you actually trying to do?

	Thorsten


Post a reply to this message

From: Antonio Ferrari
Subject: Re: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 11 Oct 2007 03:30:01
Message: <web.470dd022a5f6d2324e64f15d0@news.povray.org>
Thorsten Froehlich <tho### [at] trfde> wrote:
> Antonio Ferrari wrote:
> > I'de like to know to obtain the current OBJECT pointer in the following
> > procedures:
> >
> > - Evaluate_TPat
>
> It is in the intersection (Isection->Object), the same goes for all patterns.
>
> > - Compute_Pigment
>
> Some as above.
>
> > - Backtrace_Simulate_Media
>
> Some as above.
>
> > - sample_media
>
> You can get it from the caller (see above).
>
> What are you actually trying to do?
>
>  Thorsten



Hi,
first of all thanks for your suggestions. Be patinet, it'a a bit long and
difficult to explain what I'de like to do... I've already tried to explain
my problem in othen posts, but I've received no useful answers...

So, let's start from an object (sphere, box, etc. but also CSGs etc. etc.)
that can accept media in the interior. I'de like to obtain a sort of
Subsurface Scattering. Media allows us to have Subsurface Scattering (I
suppose Monte Carlo technics are implemented...). Media is flexible and
allow to introduce different densities, in particular using functions in x,
y and z.

What I don't know is if light emitted or scattered by medias also interacts
with the other objects and the external world. A real Subsurface Scattering
or BSSRDF methods do that, anyway. I also think that, if future releases of
Povray want to be POWERFUL, they MUST thak into account the best features
of blender or yafray etc. etc.

But now we are come to the point: how can I have a density function that
depends on the distance (minimal distance) of a point <x, y, z>, internal
to one of the objects I've mentiones above? I want a density=0 outside the
object, but inside I'de like density calculate in this way:
density(x,y,z)=A+B*min_distance(<x,y,z>, Object)^C. A, B and C are
constants. min_distance is an operator that calculate the minimal distance
of <x,y,z> from Object.

I know that we could use df3 files, but to generate them we would have to
use external programs... And that for isosurfaces we can consider the
generating function. But I need a more universal method.

min_distance operator doesn't exist in Povray. We could implement a new
operator acting in a way similar to the following macro:

#include "rand.inc"
#macro distToSurface(Obj, vec, samp, rsd)
   #local dist = 1000000;
   #local c=0;
   #while (c<samp)
      #local rdir = VRand_On_Sphere(rsd);
      #declare Norm = <0, 0, 0>;
      #local hit = trace(Obj, vec, rdir, Norm);
      #if (vlength(Norm) != 0)
         #local dist = min(dist, vlength(hit - vec));
      #end
      #local c=c+1;
   #end
#end

I don't know if there are methods more accurate, different from this
sampling one.

Starting from the last idea I've thought to implement something new in
density section, adding the possibility to recognize also a new parameter D
(D=min_distance, as described above) in density functions or maybe adding a
new keword:

interior {
  media {
    ...
    density {
      min_distance_density { 1 + 2*pow(D,3) }
    }
  }
}

It's just an example... min_distance_density is only a stupid idea. Maybe
the function could also use x, y and z parameters.

The core of the problem is to calculate the density values in
density_pattern or Evaluate_TPat or Compute_Pigment or
evaluate_density_pattern and so on. Now I don't know where is the best
point to insert the calculation of the density. Also I don't know at all if
it's possible.

Surely for doing that I need to know the "ACTUAL" object, that is the OBJECT
reference correlated to the VECTOR used when a certain density has to be
taken into account. For df3 files the density values are stored in
DENSITY_FILE_DATA structure. I'm pretty sure that there is a procedure in
which the density values can also be calculated on the fly using a function
with the new parameter D (min_distance).

Oh, I hope I've been sufficiently clear... :-/

Bye,
Antonio


Post a reply to this message

From: Antonio Ferrari
Subject: Re: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 11 Oct 2007 10:50:00
Message: <web.470e37bca5f6d2324e64f15d0@news.povray.org>
A little addendum to my previous post. I've seen that TPATTERN (and in
particular the field Vals.Density_File) struct is filled with data of the
density. For density of an interior, what is the best place where I can add
my function that calculate the density using min_distance as parameter?


Post a reply to this message

From: Antonio Ferrari
Subject: Re: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 15 Oct 2007 09:35:00
Message: <web.47136b81a5f6d2324e64f15d0@news.povray.org>
Hi Thorsten,
in order to implement my idea I've modified Parse_Pattern() in parstxtr.cpp
in order to recognize the keyword "power" followed by two floats Power_Val1
e Power_Val2 (added in TPATTERN struct). So there is a new POWER_TOKEN and a
new POWER_PATTERN.

In case of POWER_PATTERN I do the following:

  DBL Evaluate_TPat ( ...) {
    ...
    switch (TPat->Type) {
      ...
      case POWER_PATTERN: value = power_pattern ( EPoint, TPat,
Isection->Object); break;
      ...
    }
  }

Here power_pattern is defined as follows:

DBL power_pattern ( VECTOR EPoint, TPATTERN* TPat, OBJECT *Object ). This
new function do the following:

1 - If EPoing is inside Object return zero, otherwise go on.
2 - Apply sampling to find the minimal distanze of EPoint from the surface
(I've cabled 100 samples at the moment); let's call Mdist this distance.
3 - Find the maximum between Object->BBox.Lengths[X],
Object->BBox.Lengths[Y] and Object->BBox.Lengths[X]; let's call Lmax this
value.
4 - Mdist = Midst / Lmax (in order to have a value in the range 0..1)
5 - return (TPat->Vals.Power_Val1 * pow (Mdist, TPat->Vals.Power_Val2) )

Now I explain what I'de like to obtain through an example:

  density {
    power 1 2
    ...
  }

So density grows following the distance...

My question are:

1-Must the values assigned to value in Evaluate_TPat always be in the range
0..1?
2-Is step 4 necessary accordin to you?
3-Any suggestions? :-/

Antonio Ferrari


Post a reply to this message

From: Antonio Ferrari
Subject: Re: Retrieving OBJECT reference from media, pigment or pattern code ?
Date: 15 Oct 2007 12:15:00
Message: <web.471391cea5f6d2324e64f15d0@news.povray.org>
> DBL power_pattern ( VECTOR EPoint, TPATTERN* TPat, OBJECT *Object ). This
> new function do the following:
>
> 1 - If EPoing is inside Object return zero, otherwise go on.
> 2 - Apply sampling to find the minimal distanze of EPoint from the surface
> (I've cabled 100 samples at the moment); let's call Mdist this distance.
> 3 - Find the maximum between Object->BBox.Lengths[X],
> Object->BBox.Lengths[Y] and Object->BBox.Lengths[X]; let's call Lmax this
> value.
> 4 - Mdist = Midst / Lmax (in order to have a value in the range 0..1)
> 5 - return (TPat->Vals.Power_Val1 * pow (Mdist, TPat->Vals.Power_Val2) )

I've tested the code. I've modified the signature of power_pattern. Now it
receives INTERSECTION pointer, and not OBJECT. This allow some checks. At
the beginning of power_patern(...) there is the following line:

if (Isection == NULL) return 0;

Now, what it happens is that this line is always executed and so zero is
always assigned to value in Evalutate_TPat .....

So, how  could I retreive a reference to OBJECT (it is necessary for
implementing my idea) ???


Post a reply to this message

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