bump_node.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. function bump_node_init() {
  2. array_push(nodes_material_utilities, bump_node_def);
  3. map_set(parser_material_node_vectors, "BUMP", bump_node_vector);
  4. }
  5. function bump_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  6. let strength: string = parser_material_parse_value_input(node.inputs[0]);
  7. // let distance: string = parse_value_input(node.inputs[1]);
  8. let height: string = parser_material_parse_value_input(node.inputs[2]);
  9. let nor: string = parser_material_parse_vector_input(node.inputs[3]);
  10. let sample_bump_res: string = parser_material_store_var_name(node) + "_bump";
  11. parser_material_write(parser_material_kong, "var " + sample_bump_res + "_x: float = ddx(float(" + height + ")) * (" + strength + ") * 16.0;");
  12. parser_material_write(parser_material_kong, "var " + sample_bump_res + "_y: float = ddy(float(" + height + ")) * (" + strength + ") * 16.0;");
  13. return "(normalize(float3(" + sample_bump_res + "_x, " + sample_bump_res + "_y, 1.0) + " + nor + ") * float3(0.5, 0.5, 0.5) + float3(0.5, 0.5, 0.5))";
  14. }
  15. let bump_node_def: ui_node_t = {
  16. id : 0,
  17. name : _tr("Bump"),
  18. type : "BUMP",
  19. x : 0,
  20. y : 0,
  21. color : 0xff522c99,
  22. inputs : [
  23. {
  24. id : 0,
  25. node_id : 0,
  26. name : _tr("Strength"),
  27. type : "VALUE",
  28. color : 0xffa1a1a1,
  29. default_value : f32_array_create_x(1.0),
  30. min : 0.0,
  31. max : 1.0,
  32. precision : 100,
  33. display : 0
  34. },
  35. {
  36. id : 0,
  37. node_id : 0,
  38. name : _tr("Distance"),
  39. type : "VALUE",
  40. color : 0xffa1a1a1,
  41. default_value : f32_array_create_x(0.0),
  42. min : 0.0,
  43. max : 1.0,
  44. precision : 100,
  45. display : 0
  46. },
  47. {
  48. id : 0,
  49. node_id : 0,
  50. name : _tr("Height"),
  51. type : "VALUE",
  52. color : 0xffa1a1a1,
  53. default_value : f32_array_create_x(1.0),
  54. min : 0.0,
  55. max : 1.0,
  56. precision : 100,
  57. display : 0
  58. },
  59. {
  60. id : 0,
  61. node_id : 0,
  62. name : _tr("Normal"),
  63. type : "VECTOR",
  64. color : 0xff6363c7,
  65. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  66. min : 0.0,
  67. max : 1.0,
  68. precision : 100,
  69. display : 0
  70. }
  71. ],
  72. outputs : [ {
  73. id : 0,
  74. node_id : 0,
  75. name : _tr("Normal Map"),
  76. type : "VECTOR",
  77. color : -10238109,
  78. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  79. min : 0.0,
  80. max : 1.0,
  81. precision : 100,
  82. display : 0
  83. } ],
  84. buttons : [],
  85. width : 0,
  86. flags : 0
  87. };