Files
armorpaint/paint/shaders/layer_view.kong
T

69 lines
1.5 KiB
Plaintext
Raw Normal View History

2025-03-31 18:31:49 +02:00
#[set(everything)]
const constants: {
2025-04-21 19:38:23 +02:00
pos: float4; // xywh
tex: float4; // xywh
col: float4;
2025-03-31 18:31:49 +02:00
channel: int;
};
2025-04-18 09:28:41 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const sampler_linear: sampler;
2025-04-18 09:28:41 +02:00
#[set(everything)]
2025-04-24 22:19:44 +02:00
const tex: tex2d;
2025-04-18 09:28:41 +02:00
2025-03-31 18:31:49 +02:00
struct vert_in {
2025-04-21 19:38:23 +02:00
pos: float2;
2025-03-31 18:31:49 +02:00
}
struct vert_out {
pos: float4;
tex: float2;
col: float4;
}
fun layer_view_vert(input: vert_in): vert_out {
var output: vert_out;
2025-05-16 19:05:00 +02:00
var cpos: float4 = constants.pos;
var ctex: float4 = constants.tex;
2025-04-21 19:38:23 +02:00
output.pos = float4(input.pos, 0.0, 1.0);
2025-05-16 19:05:00 +02:00
output.pos.xy = output.pos.xy * cpos.zw + cpos.xy;
2025-04-21 19:38:23 +02:00
output.pos.xy = output.pos.xy * 2.0 - 1.0;
output.pos.y = -output.pos.y;
2025-05-16 19:05:00 +02:00
output.tex = input.pos * ctex.zw + ctex.xy;
2025-04-21 19:38:23 +02:00
output.col = constants.col;
2025-03-31 18:31:49 +02:00
return output;
}
fun layer_view_frag(input: vert_out): float4 {
if (constants.channel == 1) {
2025-04-19 12:29:49 +02:00
return sample_lod(tex, sampler_linear, input.tex, 0.0).rrra * input.col;
2025-03-31 18:31:49 +02:00
}
if (constants.channel == 2) {
2025-04-19 12:29:49 +02:00
return sample_lod(tex, sampler_linear, input.tex, 0.0).ggga * input.col;
2025-03-31 18:31:49 +02:00
}
if (constants.channel == 3) {
2025-04-19 12:29:49 +02:00
return sample_lod(tex, sampler_linear, input.tex, 0.0).bbba * input.col;
2025-03-31 18:31:49 +02:00
}
if (constants.channel == 4) {
2025-04-19 12:29:49 +02:00
return sample_lod(tex, sampler_linear, input.tex, 0.0).aaaa * input.col;
2025-03-31 18:31:49 +02:00
}
if (constants.channel == 5) {
2025-04-19 12:29:49 +02:00
return sample_lod(tex, sampler_linear, input.tex, 0.0).rgba * input.col;
2025-03-31 18:31:49 +02:00
}
// else {
2025-04-19 12:29:49 +02:00
var tex_sample: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0);
2025-06-08 21:44:05 +02:00
tex_sample.rgb = tex_sample.rgb * tex_sample.a;
2025-03-31 18:31:49 +02:00
return tex_sample * input.col;
// }
}
#[pipe]
struct pipe {
vertex = layer_view_vert;
fragment = layer_view_frag;
}