add color burn, fragment early discard

This commit is contained in:
2019-02-22 14:52:01 +01:00
parent 099b1bddc5
commit edc2bacc90
4 changed files with 34 additions and 14 deletions

View File

@@ -343,7 +343,7 @@
</node> </node>
</node> </node>
<node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0"> <node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0">
<combobox id="pattern-blend-mode" width="100%" height="28" combo-list="Normal,-,Multiply,Subtract,Darken,Overlay,Color Dodge,Linear Burn,Hard Mix,-,Linear Height,Height"/> <combobox id="pattern-blend-mode" width="100%" height="28" combo-list="Normal,-,Multiply,Subtract,Darken,Overlay,Color Dodge,Color Burn,Linear Burn,Hard Mix,-,Linear Height,Height"/>
</node> </node>
<!-- <!--
<node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0"> <node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0">
@@ -433,7 +433,7 @@
</node> </node>
</node> </node>
<node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0"> <node height="30" width="100%" pad="1" dir="row" margin="0 0 5 0">
<combobox id="dual-blend-mode" width="100%" height="28" combo-list="Normal,-,Multiply,Subtract,Darken,Overlay,Color Dodge,Linear Burn,Hard Mix,-,Linear Height,Height"/> <combobox id="dual-blend-mode" width="100%" height="28" combo-list="Normal,-,Multiply,Subtract,Darken,Overlay,Color Dodge,Color Burn,Linear Burn,Hard Mix,-,Linear Height,Height"/>
</node> </node>
<node align="center" dir="row"> <node align="center" dir="row">
<checkbox id="dual-randflip" height="20" width="20"/> <checkbox id="dual-randflip" height="20" width="20"/>

View File

@@ -52,6 +52,11 @@ void main()
{ {
mediump vec4 base = texture(tex, uv); mediump vec4 base = texture(tex, uv);
mediump vec4 stroke = texture(tex_stroke, uv); mediump vec4 stroke = texture(tex_stroke, uv);
if (stroke.a == 0)
{
frag = base;
return;
}
if (use_pattern) if (use_pattern)
{ {

View File

@@ -1,19 +1,19 @@
mediump float blend_stroke_screen(mediump float base, mediump float stroke) mediump float blend_stroke_screen(mediump float base, mediump float stroke)
{ {
return clamp(base + stroke - (base * stroke), 0.0, 1.0); return base + stroke - (base * stroke);
} }
mediump float blend_stroke_hard_light(mediump float base, mediump float stroke) mediump float blend_stroke_hard_light(mediump float base, mediump float stroke)
{ {
if (stroke < 0.5) if (stroke < 0.5)
return max(1.0, base * (stroke * 2.0)); // multiply return base * (stroke * 2.0); // multiply
else else
return blend_stroke_screen(base, 2.0 * stroke - 1.0); return blend_stroke_screen(base, 2.0 * stroke - 1.0);
} }
mediump float blend_stroke_hard_mix(mediump float base, mediump float stroke) mediump float blend_stroke_hard_mix(mediump float base, mediump float stroke)
{ {
return base + stroke > 0.5 ? 1.0 : 0.0; return base + stroke < 0.5 ? 0.0 : base + stroke;
} }
mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke) mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke)
@@ -23,20 +23,30 @@ mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke)
else if (stroke == 1.0) else if (stroke == 1.0)
return 1.0; return 1.0;
else else
return min(1.0, base / (1.0 - stroke)); return base / (1.0 - stroke);
}
mediump float blend_stroke_color_burn(mediump float base, mediump float stroke)
{
if (base == 0.0)
return 0.0;
else if (stroke == 1.0)
return 1.0;
else
return 1.0 - (1.0 - base) / stroke;
} }
mediump float blend_stroke_linear_height(mediump float base, mediump float stroke, mediump float depth) mediump float blend_stroke_linear_height(mediump float base, mediump float stroke, mediump float depth)
{ {
mediump float partial = (1.0 - stroke) * pow(depth, 0.25) + (base * depth * 10.0); mediump float partial = (1.0 - stroke) * pow(depth, 0.25) + (base * depth * 10.0);
return stroke * partial; return base * partial;
} }
mediump float blend_stroke_height(mediump float base, mediump float stroke, mediump float depth) mediump float blend_stroke_height(mediump float base, mediump float stroke, mediump float depth)
{ {
mediump float A = pow((1.0 - stroke), max(1.0, (1.0 - depth) * 10.0)) * pow(depth, 0.25); mediump float A = pow((1.0 - stroke), max(1.0, (1.0 - depth) * 10.0)) * pow(depth, 0.25);
mediump float B = (base * depth * 5.0); mediump float B = (base * depth * 5.0);
return stroke * (A + B); return base * (A + B);
} }
mediump float blend_stroke(mediump float base, mediump float stroke, mediump float depth, int mode) mediump float blend_stroke(mediump float base, mediump float stroke, mediump float depth, int mode)
@@ -46,10 +56,11 @@ mediump float blend_stroke(mediump float base, mediump float stroke, mediump flo
else if (mode == 2) /* subtract */ return mix(base, max(0.0, base - stroke), depth); else if (mode == 2) /* subtract */ return mix(base, max(0.0, base - stroke), depth);
else if (mode == 3) /* darken */ return mix(base, min(base, stroke), depth); else if (mode == 3) /* darken */ return mix(base, min(base, stroke), depth);
else if (mode == 4) /* overlay */ return mix(base, blend_stroke_hard_light(stroke, base), depth); else if (mode == 4) /* overlay */ return mix(base, blend_stroke_hard_light(stroke, base), depth);
else if (mode == 5) /* col-dodge */ return mix(base, blend_stroke_color_dodge(stroke, base), depth); else if (mode == 5) /* col-dodge */ return mix(base, blend_stroke_color_dodge(base, stroke), depth);
else if (mode == 6) /* lin-burn */ return mix(base, clamp(stroke + base - 1.0, 0.0, 1.0), depth); else if (mode == 6) /* col-burn */ return mix(base, blend_stroke_color_burn(base, stroke), depth);
else if (mode == 7) /* hard-mix */ return mix(base, blend_stroke_hard_mix(base, stroke), depth); else if (mode == 7) /* lin-burn */ return mix(base, clamp(base + stroke - 1.0, 0.0, 1.0), depth);
else if (mode == 8) /* lin-height */ return blend_stroke_linear_height(base, stroke, depth); else if (mode == 8) /* hard-mix */ return mix(base, blend_stroke_hard_mix(base, stroke), depth);
else if (mode == 9) /* height */ return blend_stroke_height(base, stroke, depth); else if (mode == 9) /* lin-height */ return blend_stroke_linear_height(base, stroke, depth);
else if (mode ==10) /* height */ return blend_stroke_height(base, stroke, depth);
else return 1.0; else return 1.0;
} }

View File

@@ -59,6 +59,10 @@ void main()
mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha; mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;
mediump vec4 fg = vec4(col.rgb, brush_alpha); mediump vec4 fg = vec4(col.rgb, brush_alpha);
// early discard
if (fg.a == 0.0)
discard;
if (use_pattern) if (use_pattern)
{ {
mediump vec2 rscale = resolution / vec2(512.0); mediump vec2 rscale = resolution / vec2(512.0);
@@ -84,7 +88,7 @@ void main()
fg.a *= 1.0-rand(uv2+uv)*noise; fg.a *= 1.0-rand(uv2+uv)*noise;
// no need to go further // no need to go further
if (fg.a == 0.0) if (fg.a <= 0.0)
discard; discard;
if (mix_alpha > 0.0) if (mix_alpha > 0.0)