#[set(everything)] const constants: { pos: float4; // xywh tex: float4; // xywh col: float4; channel: int; }; #[set(everything)] const sampler_linear: sampler; #[set(everything)] const tex: tex2d; struct vert_in { pos: float2; } struct vert_out { pos: float4; tex: float2; col: float4; } fun layer_view_vert(input: vert_in): vert_out { var output: vert_out; var cpos: float4 = constants.pos; var ctex: float4 = constants.tex; output.pos = float4(input.pos, 0.0, 1.0); output.pos.xy = output.pos.xy * cpos.zw + cpos.xy; output.pos.xy = output.pos.xy * 2.0 - 1.0; output.pos.y = -output.pos.y; output.tex = input.pos * ctex.zw + ctex.xy; output.col = constants.col; return output; } fun layer_view_frag(input: vert_out): float4 { if (constants.channel == 1) { return sample_lod(tex, sampler_linear, input.tex, 0.0).rrra * input.col; } if (constants.channel == 2) { return sample_lod(tex, sampler_linear, input.tex, 0.0).ggga * input.col; } if (constants.channel == 3) { return sample_lod(tex, sampler_linear, input.tex, 0.0).bbba * input.col; } if (constants.channel == 4) { return sample_lod(tex, sampler_linear, input.tex, 0.0).aaaa * input.col; } if (constants.channel == 5) { return sample_lod(tex, sampler_linear, input.tex, 0.0).rgba * input.col; } if (constants.channel == 6) { // Apply mask as red area var tex_sample: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0); if (tex_sample.r < 0.9) { discard; } return float4(1.0, 0.0, 0.0, 1.0); } // else { var tex_sample: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0); tex_sample.rgb = tex_sample.rgb * tex_sample.a; return tex_sample * input.col; // } } #[pipe] struct pipe { vertex = layer_view_vert; fragment = layer_view_frag; }