POV-Ray : Newsgroups : povray.programming : Parametric object fix : Re: Parametric object fix Server Time
27 Jul 2024 22:24:02 EDT (-0400)
  Re: Parametric object fix  
From: Massimo Valentini
Date: 6 Jul 2004 07:01:21
Message: <40ea8681@news.povray.org>
"Wolfgang Wieser" ha scritto ...
> As already mentioned in the previous thread, I have come up with a 
> "solution" for the parametric object bug (crash) as reported by me 
> (on 20 Jun 2003 21:49:03 in p.programming)
> 
> There are two problems: 
> (1) When accuracy is made too small, an internal fixed-size array overflows. 
> (2) Unless using no_shadow, the parametric object may be completely black. 
> 
> This (completely black object) can be seen e.g. using: 
> 
> ------------------------------------------
> #include "functions.inc"
> 
> global_settings { assumed_gamma 2.2 }
> light_source { <-0.4,0.2,-0.3>*20, rgb <2,2,2>/2 }
> light_source { <0.2,1,-0.8>*20, rgb <2,2,2>/1.7 }
> 
> #declare m=3;
> parametric {
> function { u*sin(v) }
> function { 15*sqrt(pow(sin(m*v)*sin(u/2)/3,2)+
> pow(cos(m*v)*m/u*sin(u/2)/3,2)) }
> function { u*cos(v) }
> <0.001,0>, <15,2*pi>
> contained_by { sphere { 0, 15 } }
> precompute 12 x,y,z
> accuracy 0.00001
> 
> pigment { rgb y }
> }
> 
> camera { location <0,0.6,-1>*8.3*3 up y look_at <0,0,0> }
> --------------------------------------------
> 
> Let's come to the black object (2) first:
> -----------------------------------------
> 
> Somebody (I do not know who) supposed a patch for this which was 
> as follows (IMO): 

I suggested it

...
> Depth1 = 0;
> 
> + if (Depth1 < DEPTH_TOLERANCE)
> + Depth1 = DEPTH_TOLERANCE;
> 
> if ((Depth1 += 4 * Par->accuracy) > Depth2)
> return false;
> 
> Intervals_Low[INDEX_U][0] = Par->umin;
> -------------------------------------------------------------
> 
> This will make the above code render a nice green parametric object. 
> 
> I must admit that I do not completely understand why this works and 
> it was not me who suggested it. I recall that some of my tests made 
> the object have no self-shadow, so here comes a modified test scene which 
> was used to verify that shadow and self-shadow work correctly for 
> accuracies 0.01 and 1e-9: (NOTE! This needs the patch for (1) applied, 
> see below.)
> 
> I do not know if we should apply this. Somebody with more clue about 
> the code should comment on that. This change may have side effects 
> which I am not aware of. But it seems, this solution is at least better 
> than the current one. 
> 

I do agree, IMO it is better than the current.

My (short) comment on why the fix works:

The problem is that the surface is getting self shadowed for accuracy 
problems. The black color is the result of the surface being shadowed 
by itself.

The intersections between a ray and the parametric surface are not 
computed exactly, the algorithm would eventually converge to the solution, 
but you need to stop it at some point. So you obtain an approximated 
intersection, that's likely NOT on the surface, it is near, but either 
in front or behind the surface. 
Shooting a ray from the approximated (behind) intersection point to the 
light, it will find the same surface at a small distance from the start.

So the sense of the fix is to reduce the range in which to search a valid 
intersection. It is something that is done for nearly every primitive in 
POVray.

HTH 
Massimo


Post a reply to this message

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