-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
TextureTint-frag.js
38 lines (38 loc) · 1.04 KB
/
TextureTint-frag.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
module.exports = [
'#define SHADER_NAME PHASER_TEXTURE_TINT_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'',
'varying vec2 outTexCoord;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main()',
'{',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
' vec4 texel = vec4(outTint.rgb * outTint.a, outTint.a);',
' vec4 color = texture;',
'',
' if (outTintEffect == 0.0)',
' {',
' // Multiply texture tint',
' color = texture * texel;',
' }',
' else if (outTintEffect == 1.0)',
' {',
' // Solid color + texture alpha',
' color.rgb = mix(texture.rgb, outTint.rgb * outTint.a, texture.a);',
' color.a = texture.a * texel.a;',
' }',
' else if (outTintEffect == 2.0)',
' {',
' // Solid color, no texture',
' color = texel;',
' }',
'',
' gl_FragColor = color;',
'}',
''
].join('\n');