-
Notifications
You must be signed in to change notification settings - Fork 28
/
LightShader.js
59 lines (47 loc) · 1.85 KB
/
LightShader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import vertex from './light.vert';
/**
* @class
* @extends PIXI.Shader
* @memberof PIXI.lights
* @param shaderManager {ShaderManager} The WebGL shader manager this shader works for.
*/
export default class LightShader extends PIXI.Shader {
constructor(gl, vertexSrc, fragmentSrc, customUniforms, customAttributes) {
const uniforms = {
translationMatrix: { type: 'mat3', value: new Float32Array(9) },
projectionMatrix: { type: 'mat3', value: new Float32Array(9) },
// textures from the previously rendered FBOs
uSampler: { type: 'sampler2D', value: null },
uNormalSampler: { type: 'sampler2D', value: null },
// should we apply the translation matrix or not.
uUseViewportQuad: { type: 'bool', value: true },
// size of the renderer viewport
uViewSize: { type: '2f', value: new Float32Array(2) },
// light color, alpha channel used for intensity.
uLightColor: { type: '4f', value: new Float32Array([1, 1, 1, 1]) },
// light falloff attenuation coefficients
uLightFalloff: { type: '3f', value: new Float32Array([0, 0, 0]) },
// height of the light above the viewport
uLightHeight: { type: '1f', value: 0.075 }
};
if (customUniforms) {
for (const u in customUniforms) {
uniforms[u] = customUniforms[u];
}
}
const attributes = {
aVertexPosition: 0
};
if (customAttributes) {
for (const a in customAttributes) {
attributes[a] = customAttributes[a];
}
}
super(gl, vertexSrc || LightShader.defaultVertexSrc, fragmentSrc, attributes);
}
}
/**
* @static
* @member {string}
*/
LightShader.defaultVertexSrc = vertex;