RGBASplit.hx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package hrt.texgraph.nodes;
  2. class RGBASplitShader extends h3d.shader.ScreenShader {
  3. static var SRC = {
  4. @param var tex : Sampler2D;
  5. @const var channels : Int;
  6. function fragment() {
  7. switch( channels ) {
  8. case 0:
  9. pixelColor = vec4(tex.get(calculatedUV).rrr, 1.);
  10. case 1:
  11. pixelColor = vec4(tex.get(calculatedUV).ggg, 1.);
  12. case 2:
  13. pixelColor = vec4(tex.get(calculatedUV).bbb, 1.);
  14. case 3:
  15. pixelColor = vec4(tex.get(calculatedUV).aaa, 1.);
  16. default:
  17. pixelColor = vec4(0,0,0,0);
  18. }
  19. }
  20. }
  21. }
  22. @name("RGBA Split")
  23. @description("Separate a RGBA image entry in 4 grayscale images")
  24. @width(100)
  25. @group("Channel")
  26. class RGBASplit extends TexNode {
  27. var inputs = [
  28. { name : "RGBA", type: h3d.mat.Texture }
  29. ];
  30. var outputs = [
  31. { name : "R", type: h3d.mat.Texture },
  32. { name : "G", type: h3d.mat.Texture },
  33. { name : "B", type: h3d.mat.Texture },
  34. { name : "A", type: h3d.mat.Texture }
  35. ];
  36. override function apply(vars : Dynamic) : Array<h3d.mat.Texture> {
  37. var engine = h3d.Engine.getCurrent();
  38. var r = createTexture();
  39. var g = createTexture();
  40. var b = createTexture();
  41. var a = createTexture();
  42. var texs = [ r, g, b, a];
  43. var shader = new RGBASplitShader();
  44. shader.tex = cast getInputData(vars, 0);
  45. var pass = new h3d.pass.ScreenFx(shader);
  46. for (idx => t in texs) {
  47. shader.channels = idx;
  48. engine.pushTarget(t);
  49. pass.render();
  50. engine.popTarget();
  51. }
  52. return texs;
  53. }
  54. }