Cleanup
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
opac: float;
|
||||
blending: int;
|
||||
};
|
||||
|
||||
#[set(everything)]
|
||||
const sampler_linear: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const tex0: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const texa: tex2d;
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun mask_merge_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun mask_merge_frag(input: vert_out): float4 {
|
||||
var col0: float = sample_lod(tex0, sampler_linear, input.tex, 0.0).r;
|
||||
var cola: float = sample_lod(texa, sampler_linear, input.tex, 0.0).r;
|
||||
var str: float = constants.opac;
|
||||
var out_color: float = 0.0;
|
||||
|
||||
if (constants.blending == 0) { // Mix
|
||||
out_color = lerp(cola, col0, str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 1) { // Darken
|
||||
out_color = lerp(cola, min(cola, col0), str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 2) { // Multiply
|
||||
out_color = lerp(cola, cola * col0, str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 3) { // Burn
|
||||
out_color = lerp(cola, 1.0 - (1.0 - cola) / col0, str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 4) { // Lighten
|
||||
out_color = max(cola, col0 * str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 5) { // Screen
|
||||
out_color = (1.0 - ((1.0 - str) + str * (1.0 - col0)) * (1.0 - cola));
|
||||
}
|
||||
/*else*/ if (constants.blending == 6) { // Dodge
|
||||
out_color = lerp(cola, cola / (1.0 - col0), str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 7) { // Add
|
||||
out_color = lerp(cola, cola + col0, str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 8) { // Overlay
|
||||
// out_color = lerp(cola, cola < 0.5 ? 2.0 * cola * col0 : 1.0 - 2.0 * (1.0 - cola) * (1.0 - col0), str);
|
||||
|
||||
////
|
||||
//if (cola < 0.5) {
|
||||
out_color = lerp(cola, 2.0 * cola * col0, str);
|
||||
//}
|
||||
//else {
|
||||
// out_color = lerp(cola, 1.0 - 2.0 * (1.0 - cola) * (1.0 - col0), str);
|
||||
//}
|
||||
////
|
||||
}
|
||||
/*else*/ if (constants.blending == 9) { // Soft Light
|
||||
out_color = ((1.0 - str) * cola + str * ((1.0 - cola) * col0 * cola + cola * (1.0 - (1.0 - col0) * (1.0 - cola))));
|
||||
}
|
||||
/*else*/ if (constants.blending == 10) { // Linear Light
|
||||
out_color = (cola + str * (2.0 * (col0 - 0.5)));
|
||||
}
|
||||
/*else*/ if (constants.blending == 11) { // Difference
|
||||
out_color = lerp(cola, abs(cola - col0), str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 12) { // Subtract
|
||||
out_color = lerp(cola, cola - col0, str);
|
||||
}
|
||||
/*else*/ if (constants.blending == 13) { // Divide
|
||||
out_color = (1.0 - str) * cola + str * cola / col0;
|
||||
}
|
||||
/*else*/ if (constants.blending == 14) { // Hue, Saturation, Color, Value
|
||||
out_color = lerp(cola, col0, str);
|
||||
}
|
||||
|
||||
return float4(out_color, out_color, out_color, 1.0);
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = mask_merge_vert;
|
||||
fragment = mask_merge_frag;
|
||||
}
|
||||
Reference in New Issue
Block a user