POV-Ray : Newsgroups : povray.beta-test : Heightfield bug (most probably an inverted normals problem) : Re: Heightfield bug (most probably an inverted normals problem) Server Time 8 Dec 2023 18:14:38 EST (-0500)
 Re: Heightfield bug (most probably an inverted normals problem)
 From: Warp Date: 22 Jan 2002 10:53:08 Message: <3c4d8ae3@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#3c4d8ae3%40news.povray.org",
"headline": "Re: Heightfield bug (most probably an inverted normals problem)",
"dateCreated": "2002-01-22T15:53:08+00:00",
"datePublished": "2002-01-22T15:53:08+00:00",
"author": {
"@type": "Person",
"name": "Warp"
}
}
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 -
```