Skip to content

Commit d2b8f0b

Browse files
committed
Factor in Camera Zoom to radius
1 parent 8174ec2 commit d2b8f0b

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/renderer/webgl/pipelines/PointLightPipeline.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ var PointLightPipeline = new Class({
4747
WebGLPipeline.call(this, config);
4848
},
4949

50-
onBind: function ()
50+
onRender: function (scene, camera)
5151
{
5252
this.set2f('uResolution', this.width, this.height);
53+
this.set1f('uCameraZoom', camera.zoom);
5354
},
5455

5556
batchPointLight: function (light, camera, x0, y0, x1, y1, x2, y2, x3, y3, lightX, lightY)

src/renderer/webgl/shaders/PointLight-frag.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = [
44
'precision mediump float;',
55
'',
66
'uniform vec2 uResolution;',
7+
'uniform float uCameraZoom;',
78
'',
89
'varying vec4 lightPosition;',
910
'varying vec4 lightColor;',
@@ -12,11 +13,11 @@ module.exports = [
1213
'',
1314
'void main ()',
1415
'{',
15-
' vec2 center = (lightPosition.xy + 1.0) * uResolution.xy * 0.5;',
16+
' vec2 center = (lightPosition.xy + 1.0) * (uResolution.xy * 0.5);',
1617
'',
1718
' float distToSurf = length(center - gl_FragCoord.xy);',
1819
'',
19-
' float radius = 1.0 - distToSurf / lightRadius;',
20+
' float radius = 1.0 - distToSurf / (lightRadius * uCameraZoom);',
2021
'',
2122
' float intensity = smoothstep(0.0, 1.0, radius * lightAttenuation);',
2223
'',

src/renderer/webgl/shaders/src/PointLight.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
precision mediump float;
44

55
uniform vec2 uResolution;
6+
uniform float uCameraZoom;
67

78
varying vec4 lightPosition;
89
varying vec4 lightColor;
@@ -11,11 +12,11 @@ varying float lightAttenuation;
1112

1213
void main ()
1314
{
14-
vec2 center = (lightPosition.xy + 1.0) * uResolution.xy * 0.5;
15+
vec2 center = (lightPosition.xy + 1.0) * (uResolution.xy * 0.5);
1516

1617
float distToSurf = length(center - gl_FragCoord.xy);
1718

18-
float radius = 1.0 - distToSurf / lightRadius;
19+
float radius = 1.0 - distToSurf / (lightRadius * uCameraZoom);
1920

2021
float intensity = smoothstep(0.0, 1.0, radius * lightAttenuation);
2122

0 commit comments

Comments
 (0)