<p></p>
<p>From what I understand, this is quite a mess!</p>
<ul>
<li>it can be used in dotProduct with <code>PrimLightDirection </code>in <code>computeSpotFactor</code><br>
but then, the <code>cosAngle </code> dotProduct is negated (after negation, it is expected positive, > minCos)</li>
<li>it can be used in dotProduct with <code>PrimVtxNormal</code> in <code>shadeVertex</code> for diffuse part<br>
again, the <code>cosAngle </code> dotProduct is expected to be positive,</li>
<li>after being copied to <code>l2vSpecDir</code> and transformed into specular direction, it is also used for specular part<br>
again, the <code>cosAngle </code> dotProduct is expected to be positive,</li>
</ul>
<p>The light direction (pointed by <code>PrimLightDirection </code> offset) is used as parameter <code>GL_SPOT_DIRECTION </code> for the <code>glLightfv </code>function.<br>
>From what I understand, it sets the main direction of <strong>propagation</strong> of light (from light source which is at top of the cone,  to center of enlighted surface which is a circular section of the cone).</p>
<p>Thus, the 1st usage suggests that the l2vDirection is vertex to light and not light to vertex as the name does NOT tell!<br>
The 2nd and 3rd usage confirm this - if ever the normal of vertex is oriented outside the visible face...</p>
<p>This would explain the <code>-1*scale</code>...</p>
<p><strong>But</strong> for source at infinite distance, <code>(lightFlags anyMask: FlagDirectional)</code>, the light to vertex direction is constant and equal to the <code>PrimLightDirection</code>, so that's what is simply copied in <code>computeDirection</code>...<br>
I perfectly understand that, <strong>EXCEPT THIS</strong>, there is no -1 scale in this branch???</p>
<p>So I definitely understand nothing to this code, this is highly contradictory.<br>
Maybe it only works for <code>(vbFlags bitAnd: VBTwoSidedLighting)</code> which enables a <code>cosAngle</code> of opposite sign?</p>
<p>Despite knowing that the code is incorrect, it's very hard to modify a code that one does not understand, there is a high risk of breaking the fragile edifice.</p>
<p>What is required is test cases of some sort for non regression. Des that only exist?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/434#issuecomment-760950333">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEW5KPOJTNJFHHGSEWMLS2BBIBANCNFSM4JCWMRPA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AIJPEW5BLCZAZ4N2YTHWZG3S2BBIBA5CNFSM4JCWMRPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFVNS4PI.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/434#issuecomment-760950333",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/434#issuecomment-760950333",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>