layer_node.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. function layer_node_init() {
  2. array_push(nodes_material_input, layer_node_def);
  3. map_set(parser_material_node_vectors, "LAYER", layer_node_vector);
  4. map_set(parser_material_node_values, "LAYER", layer_node_value);
  5. }
  6. function layer_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  7. let l: i32 = node.buttons[0].default_value[0];
  8. if (socket == node.outputs[0]) { // Base
  9. node_shader_add_texture(parser_material_kong, "texpaint" + l, "_texpaint" + l);
  10. return "sample(texpaint" + l + ", sampler_linear, tex_coord).rgb";
  11. }
  12. else { // Normal
  13. node_shader_add_texture(parser_material_kong, "texpaint_nor" + l, "_texpaint_nor" + l);
  14. return "sample(texpaint_nor" + l + ", sampler_linear, tex_coord).rgb";
  15. }
  16. }
  17. function layer_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  18. let l: i32 = node.buttons[0].default_value[0];
  19. if (socket == node.outputs[1]) { // Opac
  20. node_shader_add_texture(parser_material_kong, "texpaint" + l, "_texpaint" + l);
  21. return "sample(texpaint" + l + ", sampler_linear, tex_coord).a";
  22. }
  23. else if (socket == node.outputs[2]) { // Occ
  24. node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l);
  25. return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).r";
  26. }
  27. else if (socket == node.outputs[3]) { // Rough
  28. node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l);
  29. return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).g";
  30. }
  31. else if (socket == node.outputs[4]) { // Metal
  32. node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l);
  33. return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).b";
  34. }
  35. else if (socket == node.outputs[6]) {
  36. return "0.0";
  37. } // Emission
  38. else if (socket == node.outputs[7]) { // Height
  39. node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l);
  40. return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).a";
  41. }
  42. else {
  43. return "0.0";
  44. } // Subsurface
  45. }
  46. let layer_node_def: ui_node_t = {
  47. id : 0,
  48. name : _tr("Layer"),
  49. type : "LAYER", // extension
  50. x : 0,
  51. y : 0,
  52. color : 0xff4982a0,
  53. inputs : [],
  54. outputs : [
  55. {
  56. id : 0,
  57. node_id : 0,
  58. name : _tr("Base Color"),
  59. type : "RGBA",
  60. color : 0xffc7c729,
  61. default_value : f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
  62. min : 0.0,
  63. max : 1.0,
  64. precision : 100,
  65. display : 0
  66. },
  67. {
  68. id : 0,
  69. node_id : 0,
  70. name : _tr("Opacity"),
  71. type : "VALUE",
  72. color : 0xffa1a1a1,
  73. default_value : f32_array_create_x(1.0),
  74. min : 0.0,
  75. max : 1.0,
  76. precision : 100,
  77. display : 0
  78. },
  79. {
  80. id : 0,
  81. node_id : 0,
  82. name : _tr("Occlusion"),
  83. type : "VALUE",
  84. color : 0xffa1a1a1,
  85. default_value : f32_array_create_x(1.0),
  86. min : 0.0,
  87. max : 1.0,
  88. precision : 100,
  89. display : 0
  90. },
  91. {
  92. id : 0,
  93. node_id : 0,
  94. name : _tr("Roughness"),
  95. type : "VALUE",
  96. color : 0xffa1a1a1,
  97. default_value : f32_array_create_x(1.0),
  98. min : 0.0,
  99. max : 1.0,
  100. precision : 100,
  101. display : 0
  102. },
  103. {
  104. id : 0,
  105. node_id : 0,
  106. name : _tr("Metallic"),
  107. type : "VALUE",
  108. color : 0xffa1a1a1,
  109. default_value : f32_array_create_x(1.0),
  110. min : 0.0,
  111. max : 1.0,
  112. precision : 100,
  113. display : 0
  114. },
  115. {
  116. id : 0,
  117. node_id : 0,
  118. name : _tr("Normal Map"),
  119. type : "VECTOR",
  120. color : -10238109,
  121. default_value : f32_array_create_xyz(0.5, 0.5, 1.0),
  122. min : 0.0,
  123. max : 1.0,
  124. precision : 100,
  125. display : 0
  126. },
  127. {
  128. id : 0,
  129. node_id : 0,
  130. name : _tr("Emission"),
  131. type : "VALUE",
  132. color : 0xffa1a1a1,
  133. default_value : f32_array_create_x(1.0),
  134. min : 0.0,
  135. max : 1.0,
  136. precision : 100,
  137. display : 0
  138. },
  139. {
  140. id : 0,
  141. node_id : 0,
  142. name : _tr("Height"),
  143. type : "VALUE",
  144. color : 0xffa1a1a1,
  145. default_value : f32_array_create_x(1.0),
  146. min : 0.0,
  147. max : 1.0,
  148. precision : 100,
  149. display : 0
  150. },
  151. {
  152. id : 0,
  153. node_id : 0,
  154. name : _tr("Subsurface"),
  155. type : "VALUE",
  156. color : 0xffa1a1a1,
  157. default_value : f32_array_create_x(1.0),
  158. min : 0.0,
  159. max : 1.0,
  160. precision : 100,
  161. display : 0
  162. }
  163. ],
  164. buttons : [ {
  165. name : _tr("Layer"),
  166. type : "ENUM",
  167. output : -1,
  168. default_value : f32_array_create_x(0),
  169. data : u8_array_create_from_string(""),
  170. min : 0.0,
  171. max : 1.0,
  172. precision : 100,
  173. height : 0
  174. } ],
  175. width : 0,
  176. flags : 0
  177. };