Merge pull request #841 from justburner/HSLBlendGPU

Update Shader Fx: HSL Blend GPU
This commit is contained in:
manongjohn 2021-12-04 08:55:21 -05:00 committed by GitHub
commit d1b5c84110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 30 deletions

View file

@ -531,11 +531,12 @@
<item>"SHADER_spinblurGPU.radius" "Safe Radius" </item> <item>"SHADER_spinblurGPU.radius" "Safe Radius" </item>
<item>"SHADER_spinblurGPU.blur" "Blur" </item> <item>"SHADER_spinblurGPU.blur" "Blur" </item>
<item>"SHADER_HSLBlendGPU" "GPU HSL Blend" </item> <item>"SHADER_HSLBlendGPU" "GPU HSL Blend" </item>
<item>"SHADER_HSLBlendGPU.bhue" "Hue" </item> <item>"SHADER_HSLBlendGPU.bhue" "Hue" </item>
<item>"SHADER_HSLBlendGPU.bsat" "Saturation" </item> <item>"SHADER_HSLBlendGPU.bsat" "Saturation" </item>
<item>"SHADER_HSLBlendGPU.blum" "Luminosity" </item> <item>"SHADER_HSLBlendGPU.blum" "Luminosity" </item>
<item>"SHADER_HSLBlendGPU.balpha" "Blend Alpha" </item> <item>"SHADER_HSLBlendGPU.balpha" "Opacity" </item>
<item>"SHADER_HSLBlendGPU.bmask" "Clipping Mask" </item>
<!----------------------------------------------------------------------------------------> <!---------------------------------------------------------------------------------------->

View file

@ -60,4 +60,10 @@
0 1 0 1
</Range> </Range>
</Parameter> </Parameter>
<Parameter>
bool bmask
<Default>
0
</Default>
</Parameter>
</Parameters> </Parameters>

View file

@ -8,12 +8,13 @@ uniform mat3 worldToOutput;
uniform sampler2D inputImage[2]; uniform sampler2D inputImage[2];
uniform mat3 outputToInput[2]; uniform mat3 outputToInput[2];
uniform bool bhue; uniform bool bhue; // Blend HUE?
uniform bool bsat; uniform bool bsat; // Blend Saturation?
uniform bool blum; uniform bool blum; // Blend Luminosity?
uniform float balpha; uniform float balpha; // Blending Alpha
uniform bool bmask; // Base mask?
// ---------------------------
// Blending calculations from: // Blending calculations from:
// https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_blend_equation_advanced.txt // https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_blend_equation_advanced.txt
@ -84,35 +85,40 @@ vec3 SetLumSat(vec3 cbase, vec3 csat, vec3 clum)
return SetLum(color, clum); return SetLum(color, clum);
} }
// ---------------------------
void main( void ) void main( void )
{ {
// Read sources // Read sources
vec2 s_texPos = (outputToInput[0] * vec3(gl_FragCoord.xy, 1.0)).xy; vec2 fg_texPos = (outputToInput[0] * vec3(gl_FragCoord.xy, 1.0)).xy;
vec2 d_texPos = (outputToInput[1] * vec3(gl_FragCoord.xy, 1.0)).xy; vec2 bg_texPos = (outputToInput[1] * vec3(gl_FragCoord.xy, 1.0)).xy;
vec4 s_frag = texture2D(inputImage[0], s_texPos); vec4 fg_frag = texture2D(inputImage[0], fg_texPos);
vec4 d_frag = texture2D(inputImage[1], d_texPos); vec4 bg_frag = texture2D(inputImage[1], bg_texPos);
// De-premultiplication // De-premultiplication
vec3 s_pix = vec3(0.0); vec3 fg_pix = vec3(0.0);
if (s_frag.a > 0.0) s_pix = s_frag.rgb / s_frag.a; if (fg_frag.a > 0.0) fg_pix = fg_frag.rgb / fg_frag.a;
vec3 d_pix = vec3(0.0); vec3 bg_pix = vec3(0.0);
if (d_frag.a > 0.0) d_pix = d_frag.rgb / d_frag.a; if (bg_frag.a > 0.0) bg_pix = bg_frag.rgb / bg_frag.a;
// Figure out output alpha // Figure out output alpha
float s_alpha = s_frag.a * balpha; float fg_alpha = fg_frag.a * balpha;
float d_alpha = d_frag.a; float bg_alpha = bg_frag.a;
gl_FragColor.a = s_alpha + d_alpha * (1.0 - s_alpha); if (bmask) {
if (gl_FragColor.a <= 0.0) discard; gl_FragColor.a = bg_alpha;
// Perform blending
if (s_alpha > 0.0 && d_alpha > 0.0) {
vec3 o_pix = SetLumSat(bhue ? s_pix : d_pix, bsat ? s_pix : d_pix, blum ? s_pix : d_pix);
gl_FragColor.rgb = mix(d_pix, o_pix, balpha);
} else if (s_alpha > 0.0) {
gl_FragColor.rgb = s_pix;
} else { } else {
gl_FragColor.rgb = d_pix; gl_FragColor.a = fg_alpha + bg_alpha * (1.0 - fg_alpha);
}
if (gl_FragColor.a <= 0.0) discard;
// Perform blending
if (fg_alpha > 0.0 && bg_alpha > 0.0) {
vec3 o_pix = SetLumSat(bhue ? fg_pix : bg_pix, bsat ? fg_pix : bg_pix, blum ? fg_pix : bg_pix);
gl_FragColor.rgb = mix(bg_pix, o_pix, balpha);
} else if (fg_alpha > 0.0) {
gl_FragColor.rgb = fg_pix;
} else {
gl_FragColor.rgb = bg_pix;
} }
// Premultiplication // Premultiplication

View file

@ -4,5 +4,6 @@
<control>bsat</control> <control>bsat</control>
<control>blum</control> <control>blum</control>
<control>balpha</control> <control>balpha</control>
<control>bmask</control>
</page> </page>
</fxlayout> </fxlayout>