phaser/src/renderer/webgl/shaders/FXShadow-frag.js

31 lines
1,002 B
JavaScript
Raw Normal View History

2023-02-13 01:30:22 +00:00
module.exports = [
'#define SHADER_NAME SHADOW_FS',
'precision mediump float;',
'uniform sampler2D uMainSampler;',
'varying vec2 outTexCoord;',
2023-02-13 01:30:22 +00:00
'uniform vec2 lightPosition;',
'uniform vec4 color;',
2023-02-13 01:30:22 +00:00
'uniform float decay;',
'uniform float power;',
'uniform float intensity;',
'uniform int samples;',
'const int MAX = 12;',
2023-02-13 01:30:22 +00:00
'void main ()',
'{',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
' vec2 pc = (lightPosition - outTexCoord) * intensity;',
' float shadow = 0.0;',
' float limit = max(float(MAX), float(samples));',
' for (int i = 0; i < MAX; ++i)',
2023-02-13 01:30:22 +00:00
' {',
' if (i >= samples)',
' {',
' break;',
' }',
' shadow += texture2D(uMainSampler, outTexCoord + float(i) * decay / limit * pc).a * power;',
2023-02-13 01:30:22 +00:00
' }',
' float mask = 1.0 - texture.a;',
' gl_FragColor = mix(texture, color, shadow * mask);',
2023-02-13 01:30:22 +00:00
'}',
].join('\n');