POV-Ray : Newsgroups : povray.general : normal average bug (?) in beta6 Server Time
13 Aug 2024 17:25:29 EDT (-0400)
  normal average bug (?) in beta6 (Message 8 to 17 of 17)  
<<< Previous 7 Messages Goto Initial 10 Messages
From: Darius Davis
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 04:02:36
Message: <35F07F51.1740@acm.org>
> : Please provide more details
> : (in terms of POV files that work and some that show the bug) and I'll do
> : my best to track it down.

Hi all,

I had the same problem a while ago, and I didn't bother to chase it up. 
After reading this, I sat down and actually found the bug (or at least I
think so - the test images now trace correctly!).

OK, to fix this problem of normals being reversed (sometimes):

LIGHTING.C, function compute_lighted_texture (about line 2502 in v3.02):

Move the following five lines of code (marked |):

 |  if ((opts.Quality_Flags & Q_NORMAL) && (Layer->Tnormal != NULL))
 |  {
 |    Perturb_Normal(Layer_Normal, Layer->Tnormal, IPoint);
 |  }
 |
    /* If the surface normal points away, flip its direction. */

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

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

a bit further down, so it now reads:

    /* If the surface normal points away, flip its direction. */

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

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

 |  if ((opts.Quality_Flags & Q_NORMAL) && (Layer->Tnormal != NULL))
 |  {
 |    Perturb_Normal(Layer_Normal, Layer->Tnormal, IPoint);
 |  }
 |

and now these images will trace correctly.  The problem arises when,
following the normal perturbation, the apparent surface normal actually
points more than 90 degrees away from the vector of the ray currently
being traced (as happens in the failing parts of Nathan Kopp's source
file, where the ray strikes one of the sharply sloped parts of the
slope_map).  In that event, the surface normal vector is incorrectly
reversed so that it now points *into* the box.  Later code then
eliminates the calculation of diffused light on that surface since the
normal is now pointing away from the *light source*.  Interestingly, the
lower of the two panels traces correctly because of a piece of code in
PARSE.C function Post_Process:

    if (Object->Texture->Type == PLAIN_PATTERN)
      if (Object->Texture->Tnormal != NULL)
        Object->Type |= DOUBLE_ILLUMINATE;

The bottom panel has a PLAIN_PATTERN texture and hence has the
DOUBLE_ILLUMINATE flag set, where the top panel does not receive the
flag (it has an AVERAGE_PATTERN texture).  DOUBLE_ILLUMINATE instructs
POV-Ray to illuminate the back face of objects, and as a result of this,
the reversed normal has no effect on the tracing of the lower panel. 
The top panel doesn't have DOUBLE_ILLUMINATE set, and hence the reversed
normal prevents the diffuse lighting calculations from completing.

Those three lines from Post_Process don't appear to be necessary once
compute_lighted_texture is fixed.

I have noticed the definition of DOUBLE_ILLUMINATE in OBJECT.H describes
its use: "Illuminate both sides of surface to avoid normal purturb
bug".  I wonder if what I've found is the normal perturb bug this refers
to?

DOUBLE_ILLUMINATE is used elsewhere in the code for 'smooth' Height
Fields - I'm not sure how the changes I have described may affect HFs or
any other objects.  Please let me know if it causes any problems... I'd
appreciate some help with testing and verifying this.

For the interested, I've attached below a slightly modified version of
Nathan Kopp's sample image which demonstrates the bug even more simply
(BTW, thanks Nathan, that scene file was what I used for the debugging),
and another very short scene file to demonstrate it extremely clearly.

Cheers,

Darius Davis
Dar### [at] acmorg

-------------------------------------------------------------------------------------------

// Average normal bug test.
// Lower box shows ordinary normal map, upper box averaged one (buggy)
camera { location <-5,0,-2> look_at <0,0,0> angle 35 }
light_source { <0,0,-1> color 1 }
#declare TestNormal=
normal
{ gradient x 1
  slope_map
  { [0 <0,0>] [.2 <0,0>] [.2 <0,1>] [.4 <1,1>] [.4 <1,0>]
    [.6 <1,0>] [.6 <1,-1>] [.8 <0,-1>] [.8 <0,0>] [1 <0,0>]
  }
}
#declare TestTexture=texture { pigment { rgb 1 } normal { TestNormal } }
// Simply placing the identical texture within an 'average' texture
makes the bug evident!
#declare TestAverage=
texture
{ average texture_map
  { [TestTexture] }
}
box { <-2.5,.05,0><5,2,.1> texture { TestAverage scale 2} }
box { <-2.5,-.05,0><5,-2,.1> texture { TestTexture scale 2} }

--------------------------------

// another quick, separate self-contained scene file to demonstrate bug
    sphere {2*z, 0.9 texture {pigment {color rgb <1, 0, 0.5>} normal
{crackle 5 scale 0.1}}}
    light_source {<-5, 5, -3> color rgb 1}

--------------------------------


Post a reply to this message

From: Nieminen Mika
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 06:17:32
Message: <35efb02c.0@news.povray.org>
Darius Davis <Dar### [at] acmorg> wrote:
: For the interested, I've attached below a slightly modified version of
: Nathan Kopp's sample image

  Ahem... That image was made and posted by me...

-- 
                                                           - Warp. -


Post a reply to this message

From: Geoff Stockham
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 09:18:00
Message: <35efda78.0@news.povray.org>
Peter Popov wrote in message <35eb0763.0@news.povray.org>...
>I need to know if others have noticed this before I consider sending a bug
>report.


Why couldn't you find an unusual interesting bug instead of a normal average
one?

Geoff


Post a reply to this message

From: Nieminen Mika
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 12:18:25
Message: <35f004c1.0@news.povray.org>
Geoff Stockham <g.j### [at] dundeeacuk> wrote:
: Why couldn't you find an unusual interesting bug instead of a normal average
: one?

  That was funny! I'm still laughing :D

-- 
                                                           - Warp. -


Post a reply to this message

From: Nathan Kopp
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 12:45:13
Message: <35F00A35.D9C4429D@ltu.edu>
Darius,

Your changes make sence to me.  Good job in finding the bug!  Have you sent
anything to the POV-Ray team yet?

-Nathan

P.S. It was Mr. Mika who posted the pictures, not me.  ;-)


Post a reply to this message

From: Peter Popov
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 15:55:34
Message: <35f037a6.0@news.povray.org>
Darius Davis wrote in message <35F### [at] acmorg>...
>Hi all,
>
>I had the same problem a while ago, and I didn't bother to chase it up.
>After reading this, I sat down and actually found the bug (or at least I
>think so - the test images now trace correctly!).
>
>OK, to fix this problem of normals being reversed (sometimes):
>
><code>

Hey, this was bugging me for over a year and all it took you was a week to
fix? Thank you, sir! I had given two projects due to this and now I'll go
and dig them out of the drawer. Great job!

><clip>
>Darius Davis
>Dar### [at] acmorg
>
><code>

With his hat off,

Peter


Post a reply to this message

From: Peter Popov
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 15:55:55
Message: <35f037bb.0@news.povray.org>
Geoff Stockham wrote in message <35efda78.0@news.povray.org>...
>
>Peter Popov wrote in message <35eb0763.0@news.povray.org>...
>>I need to know if others have noticed this before I consider sending a bug
>>report.
>
>
>Why couldn't you find an unusual interesting bug instead of a normal
average
>one?
>
>Geoff


I like this one :)

I'm working on an unusual interesting bug. It is green with yellow polka
dots, has 5 legs (Bug War II veteran) and it's body is a asinh julia
fractal.

Just kidding.

Peter

P.S. BTW, do you when and under what circumstances the slang "bug" was first
used? It's an old computer freaks' joke.


Post a reply to this message

From: Ron Parker
Subject: Re: normal average bug (?) in beta6
Date: 4 Sep 1998 16:44:15
Message: <35f0430f.0@news.povray.org>
On Fri, 4 Sep 1998 21:44:49 +0300, Peter Popov <pet### [at] usanet> wrote:
>P.S. BTW, do you when and under what circumstances the slang "bug" was first
>used? It's an old computer freaks' joke.

Some people think Adm. Grace Hopper coined the phrase when she found a moth in
a relay in the Mark I computer.  But that "common knowledge" ignores the 
following, quoted from the alt.folklore.urban FAQ:

the OED sez
bug:
b A defect or fault in a machine, plan, or the like. orig. U.S.
1889 Pall Mall Gaz. 11 Mar. 1/1 Mr. Edison, I was informed, had been up 
the two previous nights discovering `a bug' in his phonograph-an expression 
for solving a difficulty, and implying that some imaginary insect has 
secreted itself inside and is causing all the trouble.


Post a reply to this message

From: Darius Davis
Subject: Re: normal average bug (?) in beta6
Date: 6 Sep 1998 08:12:00
Message: <35F35CBF.1F2D@acm.org>
Nieminen Mika wrote:
> : For the interested, I've attached below a slightly modified version of
> : Nathan Kopp's sample image
> 
>   Ahem... That image was made and posted by me...

Sorry!  Too many hours looking at the screen looking for the bug :)

Thanks very much for the sample, anyway.  It sure helps finding these
sorts of problems...


Cheers,

Darius Davis
Dar### [at] acmorg


Post a reply to this message

From: Darius Davis
Subject: Re: normal average bug (?) in beta6
Date: 6 Sep 1998 08:17:57
Message: <35F35E22.744B@acm.org>
Nathan Kopp wrote:
> Your changes make sence to me.  Good job in finding the bug!  Have you sent
> anything to the POV-Ray team yet?

Yep, they *should* have got a carbon copy of the message I posted.  My
e-mail server has just conveniently died at the moment I sent it, so I
haven't got any reply from them yet...

Cheers,

Darius
Dar### [at] acmorg


Post a reply to this message

<<< Previous 7 Messages Goto Initial 10 Messages

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