Skip to content

Commit c572f6f

Browse files
author
Spongman
committed
normalize directionalLight directions
1 parent 4465620 commit c572f6f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/webgl/light.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
170170
//in case there's no material color for the geometry
171171
shader.setUniform('uMaterialColor', this._renderer.curFillColor);
172172

173-
this._renderer.directionalLightDirections.push(_x, _y, _z);
173+
// normalize direction
174+
var l = Math.sqrt(_x * _x + _y * _y + _z * _z);
175+
this._renderer.directionalLightDirections.push(_x / l, _y / l, _z / l);
174176
shader.setUniform(
175177
'uLightingDirection',
176178
this._renderer.directionalLightDirections

0 commit comments

Comments
 (0)