2023-02-13 01:30:22 +00:00
|
|
|
module.exports = [
|
|
|
|
'#define SHADER_NAME SHADOW_FS',
|
|
|
|
'precision mediump float;',
|
|
|
|
'uniform sampler2D uMainSampler;',
|
2023-02-13 18:50:27 +00:00
|
|
|
'varying vec2 outTexCoord;',
|
2023-02-13 01:30:22 +00:00
|
|
|
'uniform vec2 lightPosition;',
|
2023-02-13 18:50:27 +00:00
|
|
|
'uniform vec4 color;',
|
2023-02-13 01:30:22 +00:00
|
|
|
'uniform float decay;',
|
|
|
|
'uniform float power;',
|
|
|
|
'uniform float intensity;',
|
2023-02-13 18:50:27 +00:00
|
|
|
'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;',
|
2023-02-13 18:50:27 +00:00
|
|
|
' float limit = max(float(MAX), float(samples));',
|
|
|
|
' for (int i = 0; i < MAX; ++i)',
|
2023-02-13 01:30:22 +00:00
|
|
|
' {',
|
2023-02-13 18:50:27 +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;',
|
2023-02-13 18:50:27 +00:00
|
|
|
' gl_FragColor = mix(texture, color, shadow * mask);',
|
2023-02-13 01:30:22 +00:00
|
|
|
'}',
|
|
|
|
].join('\n');
|