KhronosGroup / glTF-Sample-Viewer

Physically-Based Rendering in glTF 2.0 using WebGL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

angularAttenuation in Spotlight differs from spec. recommendation

andreasplesch opened this issue · comments

https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/README.md#inner-and-outer-cone-angles

recommends squaring the cosine interpolation:

angularAttenuation *= angularAttenuation;

while the viewer uses smoothstep

return smoothstep(outerConeCos, innerConeCos, actualCos);

smoothstep is using Hermite interpolation which also squares but has additional terms (https://registry.khronos.org/OpenGL-Refpages/gl4/html/smoothstep.xhtml).

The difference is probably minor and the spec. does not actually require following its recommendation, only something similar.

But since the sample viewer is the reference glTF implementation, this difference still creates (slight) confusion.

I suspect smoothstep was chosen because it is really convenient and perhaps a bit faster. So perhaps that is really an issue for the spec. which could update its recommendation. Or the viewer could follow the spec. but leave the smoothstep alternative commented in the code because it seems more elegant and is conforming.

KhronosGroup/glTF@34ae110
introduced the spec. recommendation in 2018.

47a686c
introduced smoothstep later in 2018, perhaps in response to the spec. change.

A quick gltf (
spotlight_gltf.zip
) with a single spotlight shows the visual difference:

smoothstep:
image

squared:
image

where

{\n
// return smoothstep(outerConeCos, innerConeCos, actualCos);\n        
float anAt = (actualCos - outerConeCos)/(innerConeCos - outerConeCos);
return anAt * anAt;
}

was edited in as a devtools override.
smoothstep shows less falloff closer to the innerAngle. It is more noticeable than I thought.

#488

has a PR for above if of interest.

#488 has been merged