@@ -36,12 +36,13 @@ export default class ColorShift extends Lightning.shaders.WebGLDefaultShader {
36
36
}
37
37
38
38
setupUniforms ( operation ) {
39
- const gl = this . gl
40
-
41
39
super . setupUniforms ( operation )
42
- this . _setUniform ( 'brightness' , this . _brightness || 0.0 , gl . uniform1f )
43
- this . _setUniform ( 'contrast' , this . _contrast || 1.0 , gl . uniform1f )
44
- this . _setUniform ( 'gamma' , this . _gamma || 1.0 , gl . uniform1f )
40
+ const gl = this . gl
41
+ this . _setUniform (
42
+ 'colorAdjust' ,
43
+ [ this . _brightness || 0.0 , this . _contrast || 1.0 , this . _gamma || 1.0 ] ,
44
+ gl . uniform3fv
45
+ )
45
46
}
46
47
}
47
48
@@ -53,36 +54,34 @@ ColorShift.before = `
53
54
precision lowp float;
54
55
# endif
55
56
#endif
56
-
57
+
57
58
varying vec2 vTextureCoord;
58
59
varying vec4 vColor;
59
60
uniform sampler2D uSampler;
60
- uniform float brightness;
61
- uniform float contrast;
62
- uniform float gamma;
63
-
61
+ uniform vec3 colorAdjust;
62
+
64
63
const mat3 RGBtoOpponentMat = mat3(0.2814, -0.0971, -0.0930, 0.6938, 0.1458,-0.2529, 0.0638, -0.0250, 0.4665);
65
- const mat3 OpponentToRGBMat = mat3(1.1677, 0.9014, 0.7214, -6.4315, 2.5970, 0.1257, -0.5044, 0.0159, 2.0517);
64
+ const mat3 OpponentToRGBMat = mat3(1.1677, 0.9014, 0.7214, -6.4315, 2.5970, 0.1257, -0.5044, 0.0159, 2.0517);
66
65
`
67
66
68
- ColorShift . after = `
67
+ ColorShift . after = `
69
68
vec3 brightnessContrast(vec3 value, float brightness, float contrast)
70
69
{
71
70
return (value - 0.5) * contrast + 0.5 + brightness;
72
- }
73
-
71
+ }
72
+
74
73
vec3 updateGamma(vec3 value, float param)
75
74
{
76
75
return vec3(pow(abs(value.r), param),pow(abs(value.g), param),pow(abs(value.b), param));
77
- }
78
-
76
+ }
77
+
79
78
void main(void){
80
- vec4 fragColor = texture2D(uSampler, vTextureCoord);
81
- vec4 color = vision( filter(fragColor)) * vColor;
82
-
83
- vec3 bc = brightnessContrast(color.rgb,brightness,contrast);
84
- vec3 ga = updateGamma(bc.rgb, gamma);
85
-
86
- gl_FragColor = vec4(ga.rgb, color.a);
87
- }
79
+ vec4 fragColor = texture2D(uSampler, vTextureCoord);
80
+ vec4 color = filter(fragColor) * vColor;
81
+
82
+ vec3 bc = brightnessContrast(color.rgb,colorAdjust[0],colorAdjust[1]);
83
+ vec3 ga = updateGamma(bc.rgb, colorAdjust[2]);
84
+
85
+ gl_FragColor = vec4(ga.rgb, color.a);
86
+ }
88
87
`
0 commit comments