normal_map_node.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. function normal_map_node_init() {
  2. array_push(nodes_material_utilities, normal_map_node_def);
  3. map_set(parser_material_node_vectors, "NORMAL_MAP", normal_map_node_vector);
  4. }
  5. function normal_map_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 norm: string = parser_material_parse_vector_input(node.inputs[1]);
  8. let store: string = parser_material_store_var_name(node);
  9. parser_material_write(parser_material_kong, "var " + store + "_texn: float3 = " + norm + " * 2.0 - 1.0;");
  10. parser_material_write(parser_material_kong, "" + store + "_texn.xy = " + strength + " * " + store + "_texn.xy;");
  11. parser_material_write(parser_material_kong, "" + store + "_texn = normalize(" + store + "_texn);");
  12. return "(0.5 * " + store + "_texn + 0.5)";
  13. }
  14. let normal_map_node_def: ui_node_t = {
  15. id : 0,
  16. name : _tr("Normal Map"),
  17. type : "NORMAL_MAP",
  18. x : 0,
  19. y : 0,
  20. color : 0xff522c99,
  21. inputs : [
  22. {
  23. id : 0,
  24. node_id : 0,
  25. name : _tr("Strength"),
  26. type : "VALUE",
  27. color : 0xffa1a1a1,
  28. default_value : f32_array_create_x(1.0),
  29. min : 0.0,
  30. max : 2.0,
  31. precision : 100,
  32. display : 0
  33. },
  34. {
  35. id : 0,
  36. node_id : 0,
  37. name : _tr("Normal Map"),
  38. type : "VECTOR",
  39. color : -10238109,
  40. default_value : f32_array_create_xyz(0.5, 0.5, 1.0),
  41. min : 0.0,
  42. max : 1.0,
  43. precision : 100,
  44. display : 0
  45. }
  46. ],
  47. outputs : [ {
  48. id : 0,
  49. node_id : 0,
  50. name : _tr("Normal Map"),
  51. type : "VECTOR",
  52. color : -10238109,
  53. default_value : f32_array_create_xyz(0.5, 0.5, 1.0),
  54. min : 0.0,
  55. max : 1.0,
  56. precision : 100,
  57. display : 0
  58. } ],
  59. buttons : [],
  60. width : 0,
  61. flags : 0
  62. };