layer_view.kong 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #[set(everything)]
  2. const constants: {
  3. pos: float4; // xywh
  4. tex: float4; // xywh
  5. col: float4;
  6. channel: int;
  7. };
  8. #[set(everything)]
  9. const sampler_linear: sampler;
  10. #[set(everything)]
  11. const tex: tex2d;
  12. struct vert_in {
  13. pos: float2;
  14. }
  15. struct vert_out {
  16. pos: float4;
  17. tex: float2;
  18. col: float4;
  19. }
  20. fun layer_view_vert(input: vert_in): vert_out {
  21. var output: vert_out;
  22. var cpos: float4 = constants.pos;
  23. var ctex: float4 = constants.tex;
  24. output.pos = float4(input.pos, 0.0, 1.0);
  25. output.pos.xy = output.pos.xy * cpos.zw + cpos.xy;
  26. output.pos.xy = output.pos.xy * 2.0 - 1.0;
  27. output.pos.y = -output.pos.y;
  28. output.tex = input.pos * ctex.zw + ctex.xy;
  29. output.col = constants.col;
  30. return output;
  31. }
  32. fun layer_view_frag(input: vert_out): float4 {
  33. if (constants.channel == 1) {
  34. return sample_lod(tex, sampler_linear, input.tex, 0.0).rrra * input.col;
  35. }
  36. if (constants.channel == 2) {
  37. return sample_lod(tex, sampler_linear, input.tex, 0.0).ggga * input.col;
  38. }
  39. if (constants.channel == 3) {
  40. return sample_lod(tex, sampler_linear, input.tex, 0.0).bbba * input.col;
  41. }
  42. if (constants.channel == 4) {
  43. return sample_lod(tex, sampler_linear, input.tex, 0.0).aaaa * input.col;
  44. }
  45. if (constants.channel == 5) {
  46. return sample_lod(tex, sampler_linear, input.tex, 0.0).rgba * input.col;
  47. }
  48. // else {
  49. var tex_sample: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0);
  50. tex_sample.rgb = tex_sample.rgb * tex_sample.a;
  51. return tex_sample * input.col;
  52. // }
  53. }
  54. #[pipe]
  55. struct pipe {
  56. vertex = layer_view_vert;
  57. fragment = layer_view_frag;
  58. }