layer_weight_node.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. function layer_weight_node_init() {
  2. array_push(nodes_material_input, layer_weight_node_def);
  3. map_set(parser_material_node_values, "LAYER_WEIGHT", layer_weight_node_value);
  4. }
  5. function layer_weight_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  6. let blend: string = parser_material_parse_value_input(node.inputs[0]);
  7. if (socket == node.outputs[0]) { // Fresnel
  8. parser_material_kong.frag_dotnv = true;
  9. return "clamp(pow(1.0 - dotnv, (1.0 - " + blend + ") * 10.0), 0.0, 1.0)";
  10. }
  11. else { // Facing
  12. parser_material_kong.frag_dotnv = true;
  13. return "((1.0 - dotnv) * " + blend + ")";
  14. }
  15. }
  16. let layer_weight_node_def: ui_node_t = {
  17. id : 0,
  18. name : _tr("Layer Weight"),
  19. type : "LAYER_WEIGHT",
  20. x : 0,
  21. y : 0,
  22. color : 0xffb34f5a,
  23. inputs : [
  24. {
  25. id : 0,
  26. node_id : 0,
  27. name : _tr("Blend"),
  28. type : "VALUE",
  29. color : 0xffa1a1a1,
  30. default_value : f32_array_create_x(0.5),
  31. min : 0.0,
  32. max : 1.0,
  33. precision : 100,
  34. display : 0
  35. },
  36. {
  37. id : 0,
  38. node_id : 0,
  39. name : _tr("Normal"),
  40. type : "VECTOR",
  41. color : 0xff6363c7,
  42. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  43. min : 0.0,
  44. max : 1.0,
  45. precision : 100,
  46. display : 0
  47. }
  48. ],
  49. outputs : [
  50. {
  51. id : 0,
  52. node_id : 0,
  53. name : _tr("Fresnel"),
  54. type : "VALUE",
  55. color : 0xffa1a1a1,
  56. default_value : f32_array_create_x(0.0),
  57. min : 0.0,
  58. max : 1.0,
  59. precision : 100,
  60. display : 0
  61. },
  62. {
  63. id : 0,
  64. node_id : 0,
  65. name : _tr("Facing"),
  66. type : "VALUE",
  67. color : 0xffa1a1a1,
  68. default_value : f32_array_create_x(0.0),
  69. min : 0.0,
  70. max : 1.0,
  71. precision : 100,
  72. display : 0
  73. }
  74. ],
  75. buttons : [],
  76. width : 0,
  77. flags : 0
  78. };