geometry_node.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. function geometry_node_init() {
  2. array_push(nodes_material_input, geometry_node_def);
  3. map_set(parser_material_node_vectors, "NEW_GEOMETRY", geometry_node_vector);
  4. map_set(parser_material_node_values, "NEW_GEOMETRY", geometry_node_value);
  5. }
  6. function geometry_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  7. if (socket == node.outputs[0]) { // Position
  8. parser_material_kong.frag_wposition = true;
  9. return "input.wposition";
  10. }
  11. else if (socket == node.outputs[1]) { // Normal
  12. parser_material_kong.frag_n = true;
  13. return "n";
  14. }
  15. else if (socket == node.outputs[2]) { // Tangent
  16. parser_material_kong.frag_wtangent = true;
  17. return "input.wtangent";
  18. }
  19. else if (socket == node.outputs[3]) { // True Normal
  20. parser_material_kong.frag_n = true;
  21. return "n";
  22. }
  23. else if (socket == node.outputs[4]) { // Incoming
  24. parser_material_kong.frag_vvec = true;
  25. return "vvec";
  26. }
  27. else { // Parametric
  28. parser_material_kong.frag_mposition = true;
  29. return "input.mposition";
  30. }
  31. }
  32. function geometry_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  33. if (socket == node.outputs[6]) { // Backfacing
  34. return "0.0"; // SV_IsFrontFace
  35. // return "(1.0 - float(gl_FrontFacing))";
  36. }
  37. else if (socket == node.outputs[7]) { // Pointiness
  38. let strength: f32 = 1.0;
  39. let radius: f32 = 1.0;
  40. let offset: f32 = 0.0;
  41. let store: string = parser_material_store_var_name(node);
  42. parser_material_kong.frag_n = true;
  43. parser_material_write(parser_material_kong, "var " + store + "_dx: float3 = ddx3(n);");
  44. parser_material_write(parser_material_kong, "var " + store + "_dy: float3 = ddy3(n);");
  45. parser_material_write(parser_material_kong,
  46. "var " + store + "_curvature: float = max(dot(" + store + "_dx, " + store + "_dx), dot(" + store + "_dy, " + store + "_dy));");
  47. parser_material_write(parser_material_kong, store + "_curvature = clamp(pow(" + store + "_curvature, (1.0 / " + radius + ") * 0.25) * " + strength +
  48. " * 2.0 + " + offset + " / 10.0, 0.0, 1.0);");
  49. return store + "_curvature";
  50. }
  51. else { // Random Per Island
  52. return "0.0";
  53. }
  54. }
  55. let geometry_node_def: ui_node_t = {
  56. id : 0,
  57. name : _tr("Geometry"),
  58. type : "NEW_GEOMETRY",
  59. x : 0,
  60. y : 0,
  61. color : 0xffb34f5a,
  62. inputs : [],
  63. outputs : [
  64. {
  65. id : 0,
  66. node_id : 0,
  67. name : _tr("Position"),
  68. type : "VECTOR",
  69. color : 0xff6363c7,
  70. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  71. min : 0.0,
  72. max : 1.0,
  73. precision : 100,
  74. display : 0
  75. },
  76. {
  77. id : 0,
  78. node_id : 0,
  79. name : _tr("Normal"),
  80. type : "VECTOR",
  81. color : 0xff6363c7,
  82. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  83. min : 0.0,
  84. max : 1.0,
  85. precision : 100,
  86. display : 0
  87. },
  88. {
  89. id : 0,
  90. node_id : 0,
  91. name : _tr("Tangent"),
  92. type : "VECTOR",
  93. color : 0xff6363c7,
  94. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  95. min : 0.0,
  96. max : 1.0,
  97. precision : 100,
  98. display : 0
  99. },
  100. {
  101. id : 0,
  102. node_id : 0,
  103. name : _tr("True Normal"),
  104. type : "VECTOR",
  105. color : 0xff6363c7,
  106. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  107. min : 0.0,
  108. max : 1.0,
  109. precision : 100,
  110. display : 0
  111. },
  112. {
  113. id : 0,
  114. node_id : 0,
  115. name : _tr("Incoming"),
  116. type : "VECTOR",
  117. color : 0xff6363c7,
  118. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  119. min : 0.0,
  120. max : 1.0,
  121. precision : 100,
  122. display : 0
  123. },
  124. {
  125. id : 0,
  126. node_id : 0,
  127. name : _tr("Parametric"),
  128. type : "VECTOR",
  129. color : 0xff6363c7,
  130. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  131. min : 0.0,
  132. max : 1.0,
  133. precision : 100,
  134. display : 0
  135. },
  136. {
  137. id : 0,
  138. node_id : 0,
  139. name : _tr("Backfacing"),
  140. type : "VALUE",
  141. color : 0xffa1a1a1,
  142. default_value : f32_array_create_x(0.0),
  143. min : 0.0,
  144. max : 1.0,
  145. precision : 100,
  146. display : 0
  147. },
  148. {
  149. id : 0,
  150. node_id : 0,
  151. name : _tr("Pointiness"),
  152. type : "VALUE",
  153. color : 0xffa1a1a1,
  154. default_value : f32_array_create_x(0.0),
  155. min : 0.0,
  156. max : 1.0,
  157. precision : 100,
  158. display : 0
  159. },
  160. {
  161. id : 0,
  162. node_id : 0,
  163. name : _tr("Random Per Island"),
  164. type : "VALUE",
  165. color : 0xffa1a1a1,
  166. default_value : f32_array_create_x(0.0),
  167. min : 0.0,
  168. max : 1.0,
  169. precision : 100,
  170. display : 0
  171. }
  172. ],
  173. buttons : [],
  174. width : 0,
  175. flags : 0
  176. };