Files
armorpaint/paint/shaders/mask_merge.kong
T

103 lines
2.7 KiB
Plaintext
Raw Normal View History

2025-03-31 18:31:49 +02:00
2025-04-18 09:28:41 +02:00
#[set(everything)]
const constants: {
opac: float;
blending: int;
};
2025-03-31 18:31:49 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const sampler_linear: sampler;
2025-03-31 18:31:49 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const tex0: tex2d;
2025-03-31 18:31:49 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const texa: tex2d;
2025-03-31 18:31:49 +02:00
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 {
2025-04-19 12:29:49 +02:00
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;
2025-03-31 18:31:49 +02:00
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);
2025-06-06 23:29:42 +02:00
////
//if (cola < 0.5) {
2025-03-31 18:31:49 +02:00
out_color = lerp(cola, 2.0 * cola * col0, str);
2025-06-06 23:29:42 +02:00
//}
//else {
// out_color = lerp(cola, 1.0 - 2.0 * (1.0 - cola) * (1.0 - col0), str);
//}
////
2025-03-31 18:31:49 +02:00
}
/*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;
}