Skip to content

Commit

Permalink
support resolution param
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpopelyshev committed Feb 23, 2019
1 parent f0386c6 commit 3622e69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/lights/light/LightShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default class LightShader extends PIXI.Shader {
// should we apply the translation matrix or not.
uUseViewportQuad: { type: 'bool', value: true },

// size of the renderer viewport
// size of the renderer viewport, CSS
uViewSize: { type: '2f', value: new Float32Array(2) },
//same, in PIXELS
uViewPixels: { type: '2f', value: new Float32Array(2) },

// light color, alpha channel used for intensity.
uLightColor: { type: '4f', value: new Float32Array([1, 1, 1, 1]) },
Expand Down
3 changes: 2 additions & 1 deletion src/lights/shared/commonUniforms.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ uniform sampler2D uNormalSampler;

uniform mat3 translationMatrix;

uniform vec2 uViewSize; // size of the viewport
uniform vec2 uViewPixels; // size of the viewport, in pixels
uniform vec2 uViewSize; // size of the viewport, in CSS

uniform vec4 uLightColor; // light color, alpha channel used for intensity.
uniform vec3 uLightFalloff; // light attenuation coefficients (constant, linear, quadratic)
Expand Down
2 changes: 1 addition & 1 deletion src/lights/shared/computeVertexPosition.glsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vec2 texCoord = gl_FragCoord.xy / uViewSize;
vec2 texCoord = gl_FragCoord.xy / uViewPixels;
texCoord.y = (1.0 - texCoord.y) * uFlipY + texCoord.y * (1.0 - uFlipY); // FBOs positions are flipped.
16 changes: 13 additions & 3 deletions src/renderers/LightRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,19 @@ export default class LightRenderer extends PIXI.ObjectRenderer {
shader.uniforms.uNormalSampler = 1;

let uViewSize = shader.uniforms.uViewSize;
uViewSize[0] = renderer.screen.width;
uViewSize[1] = renderer.screen.height;
shader.uniforms.uViewSize = uViewSize;
if (uViewSize) {
uViewSize[0] = renderer.screen.width;
uViewSize[1] = renderer.screen.height;
shader.uniforms.uViewSize = uViewSize;
}

let uViewPixels = shader.uniforms.uViewPixels;
if (uViewPixels) {
uViewPixels[0] = renderer.view.width;
uViewPixels[1] = renderer.view.height;
shader.uniforms.uViewPixels = uViewPixels;
}

shader.uniforms.uFlipY = renderer._activeRenderTarget.root ? 1.0 : 0.0;
}

Expand Down

0 comments on commit 3622e69

Please sign in to comment.