Skip to content

Commit 96c881b

Browse files
bug fix: Stop ignoring spot lights angle (since #76)
1 parent c176567 commit 96c881b

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

examples/test/spot_light.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
lighting: [
2121
{
2222
type: 'spot',
23-
angle: 1,
23+
angle: 0.1,
2424
color: [1, 1, 1],
2525
coords: [[2, 2, 2]],
2626
target: [[0, 0, 0]]

src/primitives/polygon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default function ({ color, coords, edgeForm = {}, opacity = 1, vertexNorm
235235
236236
void getSpotLightInfo(const in SpotLight spotLight, out IncidentLight light) {
237237
light.direction = normalize(spotLight.position + vViewPosition);
238-
light.color = spotLight.color * max(dot(light.direction, spotLight.direction), 0.0);
238+
light.color = spotLight.color * max(smoothstep(coneCos, coneCos, dot(light.direction, spotLight.direction)), 0.0);
239239
}
240240
#endif
241241

src/primitives/sphere.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function ({ color, coords, opacity = 1, radius = 1 }, extent) {
8888
8989
void getSpotLightInfo(const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light) {
9090
light.direction = normalize(spotLight.position - geometry.position);
91-
light.color = spotLight.color * max(dot(light.direction, spotLight.direction), 0.0);
91+
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
9292
}
9393
#endif
9494

src/primitives/tube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export default function ({ color, coords, opacity = 1, radius = 1 }, extent) {
178178
float angleCos = dot(light.direction, spotLight.direction);
179179
180180
if (angleCos > 0.0) {
181-
light.color = spotLight.color * max(dot(light.direction, spotLight.direction), 0.0);
181+
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
182182
} else {
183183
light.color = vec3(0.0);
184184
}

src/primitives/uniformPolyhedron.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export default function ({ color, coords, edgeForm = {}, edgeLength = 1, opacity
416416
417417
void getSpotLightInfo(const in SpotLight spotLight, out IncidentLight light) {
418418
light.direction = normalize(spotLight.position + vViewPosition);
419-
light.color = spotLight.color * max(dot(light.direction, spotLight.direction), 0.0);
419+
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
420420
}
421421
#endif
422422

vendors/three.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19991,7 +19991,7 @@
1999119991
uniforms.distance = distance;
1999219992

1999319993
uniforms.coneCos = Math.cos( light.angle );
19994-
uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
19994+
uniforms.penumbraCos = Math.cos( light.angle );
1999519995
uniforms.decay = light.decay;
1999619996

1999719997
if ( light.castShadow ) {

0 commit comments

Comments
 (0)