POV-Ray : Newsgroups : povray.beta-test : Heightfield bug (most probably an inverted normals problem) Server Time
6 Oct 2022 17:04:00 EDT (-0400)
  Heightfield bug (most probably an inverted normals problem) (Message 1 to 10 of 27)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Warp
Subject: Heightfield bug (most probably an inverted normals problem)
Date: 21 Jan 2002 18:49:19
Message: <3c4ca8ff@news.povray.org>
Smooth heightfiels show sometimes a bug which seems to be related to normals
getting inverted when they shouldn't. This causes wrong lighting which can
be mainly seen as dark spots (which go away with 'double_illuminate').

  The following example shows clearly the problem. It uses a slope y pattern
with slopes <0.5 (ie surfaces facing downwards) colored red and slopes >0.5
colored with gray to white. As a heightfield, it should not show any red
because all surfaces are faced upwards. However, it shows red where surface
normals are inverted.
  The curious thing about this is that the places of the inverted normals
(ie the red spots) are somehow dependant of the camera location. If you
try the two given camera locations you'll see that the amount and location
of the spots change.

-------------8<--------------8<-------------8<-------------8<-----------
camera
{ location #if(0) <0,0.3,0> #else 0 #end
  look_at z*1
}

height_field
{ function 200,200 { pattern { granite } }
  smooth
  scale <10,1.5,10>
  pigment {slope y color_map { [0 rgb x][.5 rgb .5][1 rgb 1] } }
  finish{ambient 1}
  translate -<5,.3,0>
}
-------------8<--------------8<-------------8<-------------8<-----------

  Tested on both windows and unix versions of povray.


-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 21 Jan 2002 18:54:38
Message: <3c4caa3e@news.povray.org>
Let me guess the reason for this: When povray calculates the ray-hf
itersection, it returns the normal inverted if the regular normal was at
an angle <90 degrees with respect to the incoming ray.
  There might be some archaic reason for this and it doesn't matter with
non-smooth heightfields, but it causes a misbehaviour when a smooth triangle
is oriented so that it faces the camera but some of its normal vectors are
pointing away from it.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Mike Williams
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 22 Jan 2002 01:45:16
Message: <73EpCMAWEMT8EwUm@econym.demon.co.uk>
Wasn't it Warp who wrote:

>  Smooth heightfiels show sometimes a bug which seems to be related to normals
>getting inverted when they shouldn't. This causes wrong lighting which can
>be mainly seen as dark spots (which go away with 'double_illuminate').

Is this the same as

Unsmooth smooth HF shading
(the shading of height-fields with abrupt changes is very ugly when
smooth shading is turned on)
http://news.povray.org/3c02ac19@news.povray.org

which was eventually determined to be a limitation, rather than a bug?

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 22 Jan 2002 06:36:40
Message: <3c4d4ec8@news.povray.org>
Mike Williams <mik### [at] nospamplease> wrote:
: Is this the same as

: Unsmooth smooth HF shading
: (the shading of height-fields with abrupt changes is very ugly when
: smooth shading is turned on)
: http://news.povray.org/3c02ac19@news.povray.org

  It says:

"the shading of height-fields with abrupt changes is very ugly when smooth
shading is turned on."

  There are no abrupt changes in my example.
  The problem in my example seems that normals get inverted when they
shouldn't.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Francois Labreque
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 22 Jan 2002 07:55:41
Message: <3C4D610B.40700@videotron.ca>
Warp wrote:

> Mike Williams <mik### [at] nospamplease> wrote:
> : Is this the same as
> 
> : Unsmooth smooth HF shading
> : (the shading of height-fields with abrupt changes is very ugly when
> : smooth shading is turned on)
> : http://news.povray.org/3c02ac19@news.povray.org
> 
>   It says:
> 
> "the shading of height-fields with abrupt changes is very ugly when smooth
> shading is turned on."
> 
>   There are no abrupt changes in my example.
>   The problem in my example seems that normals get inverted when they
> shouldn't.


If it helps some of the coders, that problem was there in 3.1.  It is 
not due to new code in 3.5.

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   videotron.ca  */}camera{location<6,1.25,-6>look_at a orthographic}


Post a reply to this message

From: Warp
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 22 Jan 2002 10:53:08
Message: <3c4d8ae3@news.povray.org>
I have looked a bit at the heighfield code, but the reason of this inverting
is not as simple as I thought. There doesn't seem to be anything like:

  if(angle_between(incoming_ray, normal) < 90)
    invert(normal);

(this is pseudocode, not actual C code used in povray :) )

or at least I didn't find anything like that. If there's this kind of
inversion, it's quite hidden in some formula used in the code.
  Although the heightfield normal calculation code is rather simple, it's still
rather tricky to understand what exactly is done.
  I'll try to study it more.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: More info (Was: Heightfield bug (most probably an inverted normals problem))
Date: 22 Jan 2002 12:14:13
Message: <3c4d9de5@news.povray.org>
It's not actually a heightfield bug. It's a more general phenomenon. If the
angle between the normal vector returned by the object (any object) and the
incoming ray is <90 degrees, then the normal vector is inverted.
  Here is another example where this happens:

camera { location -z*2 look_at 0 }
smooth_triangle
{ <-1,-.2,0>, <-1,1,-1>
  <1,-.2,0>, <1,1,-1>
  <0,.2,2>, <0,1,1>
  pigment { slope y color_map { [0 rgb x][.5 rgb .5][1 rgb 1] } }
  finish{ambient 1}
}

  The normal vector of this smooth triangle points always upwards, never
downwards, and thus it should never get colored red. But the inversion
phenomenon of the normal causes the artifact.

  (I think this was the reason why smooth meshes were double-illuminated by
default. It was a quick trick to get rid of this artifact! However, this
doesn't help with slope patterns.)

  I carefully tested the normal vectors returned by the heightfield object,
and they never point downwards, so the inversion indeed happens at a higher
level in the rendering process.

  However, I understand that removing this inversion could actually break
something else which currently works. One case could perhaps be CSG
illumination and inverted object illumination.

  Any ideas?

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: More info
Date: 22 Jan 2002 12:21:40
Message: <3c4d9fa4@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
:   However, I understand that removing this inversion could actually break
: something else which currently works.

  By the way, it occurred to me what would this seriously break: If we are
looking at an object surface from one side and a light source is illuminating
the object on the other side, this normal inversion takes care that we see
a shadowed surface, not an illuminated surface. If the normal was not inverted,
then the surface would work like it was double-illuminated all the time if
the unmodified normal points at the light source and it wouldn't be illuminated
at all (no matter where you look at it) if the unmodified normal points away
from the light source.

  What a dilemma!

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: Heightfield bug (most probably an inverted normals problem)
Date: 22 Jan 2002 12:37:57
Message: <chrishuff-235D1D.12385522012002@netplex.aussie.org>
I don't have the POV 3.5 source available, but in POV 3.1:

lighting.c, Determine_Apparent_Colour()

...

  VDot(Normal_Direction, Raw_Normal, Ray->Direction);

  if (Normal_Direction > 0.0)
  {
     VScaleEq(Raw_Normal, -1.0);
  }

-- 
 -- 
Christopher James Huff <chr### [at] maccom>


Post a reply to this message

From: Christopher James Huff
Subject: Re: More info (Was: Heightfield bug (most probably an inverted normals problem))
Date: 22 Jan 2002 13:07:35
Message: <chrishuff-2AD539.13083422012002@netplex.aussie.org>
In article <3c4d9de5@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

>   However, I understand that removing this inversion could actually break
> something else which currently works. One case could perhaps be CSG
> illumination and inverted object illumination.

Any case where you can see both sides of a surface...any object that's 
clipped, triangles, bezier patches, height fields, discs, polygons, 
isosurfaces...

The only fix would be to detect for a hit from the "outside" of the 
object that still gives a normal that points away from the ray. This 
only happens with smooth triangles as far as I can tell, so the test 
could be restricted to that case if possible. As for what you do when 
you identify this case...that's a different problem, and I don't think 
it's been solved. Artificially limit the normal to be at 90 degrees to 
the ray? I think that will just make black areas. Ignore the 
intersection entirely?
If the intersection is ignored, you have to worry about the triangles 
behind it...maybe meshes/smooth_triangles should have a "front_only" or 
"cull_backsides" option, but that would break transparent meshes. Maybe 
just ignore the intersection and the first intersection with the same 
mesh that follows it...that should work for all well-behaved meshes, but 
might be complex to code.

-- 
 -- 
Christopher James Huff <chr### [at] maccom>


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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