diff options
author | Rob Clark <robdclark@chromium.org> | 2020-04-09 08:18:24 -0700 |
---|---|---|
committer | Rob Clark <robdclark@chromium.org> | 2020-04-09 08:21:42 -0700 |
commit | 31b22da39e37e3471497475b0f70cb7911a14f10 (patch) | |
tree | ad9af436a448f8b04008d69991b1e90416681773 /shaders/skia/214-6.shader_test | |
parent | 7d3768722419076cb935399ff580ad0b99dfdb2c (diff) |
shaders: add skia shaders
Add shaders extracted from skia's unit tests[1]
[1] https://skia.org/dev/testing/testing
Diffstat (limited to 'shaders/skia/214-6.shader_test')
-rw-r--r-- | shaders/skia/214-6.shader_test | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/shaders/skia/214-6.shader_test b/shaders/skia/214-6.shader_test new file mode 100644 index 0000000..c9c8db0 --- /dev/null +++ b/shaders/skia/214-6.shader_test @@ -0,0 +1,130 @@ +[require] +GLSL >= 1.40 + +[fragment shader] +#version 140 + +#extension GL_ARB_fragment_coord_conventions : require +layout(origin_upper_left) in vec4 gl_FragCoord; +out vec4 sk_FragColor; +uniform vec3 uedges_Stage2_c1_c0[8]; +uniform sampler2D uTextureSampler_0_Stage1; +noperspective in vec2 vTransformedCoords_0_Stage0; +vec4 ClampFragmentProcessor_Stage2_c0_c0(vec4 _input) { + vec4 _output; + { + _output = clamp(_input, 0.0, 1.0); + } + return _output; +} +vec4 ConvexPoly_Stage2_c1_c0(vec4 _input) { + vec4 _output; + float alpha = 1.0; + float edge; + edge = dot(uedges_Stage2_c1_c0[0], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[1], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[2], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[3], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[4], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[5], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[6], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + edge = dot(uedges_Stage2_c1_c0[7], vec3(gl_FragCoord.x, gl_FragCoord.y, 1.0)); + edge = edge >= 0.5 ? 1.0 : 0.0; + alpha *= edge; + _output = _input * alpha; + return _output; +} +float _blend_color_saturation(vec3 color) { + return max(max(color.x, color.y), color.z) - min(min(color.x, color.y), color.z); +} +vec3 _blend_set_color_saturation_helper(vec3 minMidMax, float sat) { + if (minMidMax.x < minMidMax.z) { + return vec3(0.0, (sat * (minMidMax.y - minMidMax.x)) / (minMidMax.z - minMidMax.x), sat); + } + return vec3(0.0); +} +vec3 _blend_set_color_saturation(vec3 hueLumColor, vec3 satColor) { + float sat = _blend_color_saturation(satColor); + if (hueLumColor.x <= hueLumColor.y) { + if (hueLumColor.y <= hueLumColor.z) { + hueLumColor.xyz = _blend_set_color_saturation_helper(hueLumColor, sat); + } else if (hueLumColor.x <= hueLumColor.z) { + hueLumColor.xzy = _blend_set_color_saturation_helper(hueLumColor.xzy, sat); + } else { + hueLumColor.zxy = _blend_set_color_saturation_helper(hueLumColor.zxy, sat); + } + } else if (hueLumColor.x <= hueLumColor.z) { + hueLumColor.yxz = _blend_set_color_saturation_helper(hueLumColor.yxz, sat); + } else if (hueLumColor.y <= hueLumColor.z) { + hueLumColor.yzx = _blend_set_color_saturation_helper(hueLumColor.yzx, sat); + } else { + hueLumColor.zyx = _blend_set_color_saturation_helper(hueLumColor.zyx, sat); + } + return hueLumColor; +} +float _blend_color_luminance(vec3 color) { + return dot(vec3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), color); +} +vec3 _blend_set_color_luminance(vec3 hueSatColor, float alpha, vec3 lumColor) { + float lum = _blend_color_luminance(lumColor); + vec3 result = (lum - _blend_color_luminance(hueSatColor)) + hueSatColor; + float minComp = min(min(result.x, result.y), result.z); + float maxComp = max(max(result.x, result.y), result.z); + if (minComp < 0.0 && lum != minComp) { + result = lum + ((result - lum) * lum) / (lum - minComp); + } + if (maxComp > alpha && maxComp != lum) { + return lum + ((result - lum) * (alpha - lum)) / (maxComp - lum); + } + return result; +} +vec4 blend_saturation(vec4 src, vec4 dst) { + float alpha = dst.w * src.w; + vec3 sda = src.xyz * dst.w; + vec3 dsa = dst.xyz * src.w; + return vec4((((_blend_set_color_luminance(_blend_set_color_saturation(dsa, sda), alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha); +} +void main() { + vec4 output_Stage1; + { + output_Stage1 = texture(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0); + } + vec4 output_Stage2; + { + vec4 inputColor = vec4(output_Stage1.xyz, 1.0); + output_Stage2 = blend_saturation(ClampFragmentProcessor_Stage2_c0_c0(inputColor), ConvexPoly_Stage2_c1_c0(inputColor)); + output_Stage2 *= output_Stage1.w; + } + { + sk_FragColor = output_Stage2; + } +} + +[vertex shader] +#version 140 + +uniform vec4 sk_RTAdjust; +uniform mat3 uCoordTransformMatrix_0_Stage0; +in vec2 position; +in vec2 localCoord; +noperspective out vec2 vTransformedCoords_0_Stage0; +void main() { + vTransformedCoords_0_Stage0 = (uCoordTransformMatrix_0_Stage0 * vec3(localCoord, 1.0)).xy; + gl_Position = vec4(position.x, position.y, 0.0, 1.0); + gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * sk_RTAdjust.yw, 0.0, gl_Position.w); +} + |