Skip to content

Commit 7458031

Browse files
committed
Updated shaders
1 parent 94836b1 commit 7458031

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

src/renderer/webgl/shaders/ColorMatrix-frag.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,38 @@ module.exports = [
55
'',
66
'uniform sampler2D uMainSampler;',
77
'uniform float uColorMatrix[20];',
8+
'uniform float uAlpha;',
89
'',
910
'varying vec2 outTexCoord;',
1011
'',
1112
'void main ()',
1213
'{',
1314
' vec4 c = texture2D(uMainSampler, outTexCoord);',
1415
'',
15-
' gl_FragColor.r = uColorMatrix[0] * c.r + uColorMatrix[1] * c.g + uColorMatrix[2] * c.b + uColorMatrix[4];',
16-
' gl_FragColor.g = uColorMatrix[5] * c.r + uColorMatrix[6] * c.g + uColorMatrix[7] * c.b + uColorMatrix[9];',
17-
' gl_FragColor.b = uColorMatrix[10] * c.r + uColorMatrix[11] * c.g + uColorMatrix[12] * c.b + uColorMatrix[14];',
18-
' gl_FragColor.a = c.a;',
16+
' if (uAlpha == 0.0)',
17+
' {',
18+
' gl_FragColor = c;',
19+
'',
20+
' return;',
21+
' }',
22+
'',
23+
' if (c.a > 0.0)',
24+
' {',
25+
' c.rgb /= c.a;',
26+
' }',
27+
'',
28+
' vec4 result;',
29+
'',
30+
' result.r = (uColorMatrix[0] * c.r) + (uColorMatrix[1] * c.g) + (uColorMatrix[2] * c.b) + (uColorMatrix[3] * c.a) + uColorMatrix[4];',
31+
' result.g = (uColorMatrix[5] * c.r) + (uColorMatrix[6] * c.g) + (uColorMatrix[7] * c.b) + (uColorMatrix[8] * c.a) + uColorMatrix[9];',
32+
' result.b = (uColorMatrix[10] * c.r) + (uColorMatrix[11] * c.g) + (uColorMatrix[12] * c.b) + (uColorMatrix[13] * c.a) + uColorMatrix[14];',
33+
' result.a = (uColorMatrix[15] * c.r) + (uColorMatrix[16] * c.g) + (uColorMatrix[17] * c.b) + (uColorMatrix[18] * c.a) + uColorMatrix[19];',
34+
'',
35+
' vec3 rgb = mix(c.rgb, result.rgb, uAlpha);',
36+
'',
37+
' rgb *= result.a;',
38+
'',
39+
' gl_FragColor = vec4(rgb, result.a);',
1940
'}',
2041
''
2142
].join('\n');

src/renderer/webgl/shaders/Copy-frag.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ module.exports = [
1010
'',
1111
'void main ()',
1212
'{',
13-
' // gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);',
14-
'',
1513
' gl_FragColor = texture2D(uMainSampler, outTexCoord) * uBrightness;',
1614
'}',
1715
''

src/renderer/webgl/shaders/Quad-vert.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module.exports = [
33
'',
44
'precision mediump float;',
55
'',
6-
'uniform mat4 uProjectionMatrix;',
7-
'',
86
'attribute vec2 inPosition;',
97
'attribute vec2 inTexCoord;',
108
'',
@@ -13,11 +11,10 @@ module.exports = [
1311
'',
1412
'void main ()',
1513
'{',
16-
' // gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
17-
' gl_Position = vec4(inPosition, 0, 1);',
18-
'',
1914
' outFragCoord = inPosition.xy * 0.5 + 0.5;',
2015
' outTexCoord = inTexCoord;',
16+
'',
17+
' gl_Position = vec4(inPosition, 0, 1);',
2118
'}',
2219
''
2320
].join('\n');

0 commit comments

Comments
 (0)