CombineAlpha.hx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package hrt.shgraph.nodes;
  2. import hxsl.Types.Vec;
  3. import hxsl.*;
  4. using hxsl.Ast;
  5. @name("Combine Alpha")
  6. @description("Create a vector of size 4 from a RGB and an Alpha float")
  7. @group("Channel")
  8. class CombineAlpha extends ShaderNode {
  9. @input("RGB") var rgb = SType.Vec3;
  10. @input("A", true) var a = SType.Float;
  11. @output("RGBA") var output = SType.Vec4;
  12. override public function computeOutputs() {
  13. addOutput("output", TVec(4, VFloat));
  14. }
  15. override public function build(key : String) : TExpr {
  16. var args = [];
  17. var valueArgs = [];
  18. var opTGlobal : TGlobal = Vec4;
  19. args.push({ name: "rgb", type : TVec(3, VFloat) });
  20. valueArgs.push(rgb.getVar());
  21. args.push({ name: "a", type : TFloat });
  22. valueArgs.push(a.getVar());
  23. opTGlobal = Vec4;
  24. return {
  25. p : null,
  26. t : output.type,
  27. e : TBinop(OpAssign, {
  28. e: TVar(output),
  29. p: null,
  30. t : output.type
  31. },
  32. {
  33. e: TCall({
  34. e: TGlobal(opTGlobal),
  35. p: null,
  36. t: TFun([
  37. {
  38. ret: output.type,
  39. args: args
  40. }
  41. ])
  42. }, valueArgs
  43. ),
  44. p: null,
  45. t: output.type
  46. })
  47. };
  48. }
  49. }