magic_texture_node.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. function magic_texture_node_init() {
  2. array_push(nodes_material_texture, magic_texture_node_def);
  3. map_set(parser_material_node_vectors, "TEX_MAGIC", magic_texture_node_vector);
  4. map_set(parser_material_node_values, "TEX_MAGIC", magic_texture_node_value);
  5. }
  6. let str_tex_magic: string = "\
  7. fun tex_magic(p: float3): float3 { \
  8. var a: float = 1.0 - (sin(p.x) + sin(p.y)); \
  9. var b: float = 1.0 - sin(p.x - p.y); \
  10. var c: float = 1.0 - sin(p.x + p.y); \
  11. return float3(a, b, c); \
  12. } \
  13. fun tex_magic_f(p: float3): float { \
  14. var c: float3 = tex_magic(p); \
  15. return (c.x + c.y + c.z) / 3.0; \
  16. } \
  17. ";
  18. function magic_texture_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  19. node_shader_add_function(parser_material_kong, str_tex_magic);
  20. let co: string = parser_material_get_coord(node);
  21. let scale: string = parser_material_parse_value_input(node.inputs[1]);
  22. let res: string = "tex_magic(" + co + " * " + scale + " * 4.0)";
  23. return res;
  24. }
  25. function magic_texture_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  26. node_shader_add_function(parser_material_kong, str_tex_magic);
  27. let co: string = parser_material_get_coord(node);
  28. let scale: string = parser_material_parse_value_input(node.inputs[1]);
  29. let res: string = "tex_magic_f(" + co + " * " + scale + " * 4.0)";
  30. return res;
  31. }
  32. let magic_texture_node_def: ui_node_t = {
  33. id : 0,
  34. name : _tr("Magic Texture"),
  35. type : "TEX_MAGIC",
  36. x : 0,
  37. y : 0,
  38. color : 0xff4982a0,
  39. inputs : [
  40. {
  41. id : 0,
  42. node_id : 0,
  43. name : _tr("Vector"),
  44. type : "VECTOR",
  45. color : 0xff6363c7,
  46. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  47. min : 0.0,
  48. max : 1.0,
  49. precision : 100,
  50. display : 0
  51. },
  52. {
  53. id : 0,
  54. node_id : 0,
  55. name : _tr("Scale"),
  56. type : "VALUE",
  57. color : 0xffa1a1a1,
  58. default_value : f32_array_create_x(5.0),
  59. min : 0.0,
  60. max : 10.0,
  61. precision : 100,
  62. display : 0
  63. },
  64. {
  65. id : 0,
  66. node_id : 0,
  67. name : _tr("Distortion"),
  68. type : "VALUE",
  69. color : 0xffa1a1a1,
  70. default_value : f32_array_create_x(1.0),
  71. min : 0.0,
  72. max : 10.0,
  73. precision : 100,
  74. display : 0
  75. }
  76. ],
  77. outputs : [
  78. {
  79. id : 0,
  80. node_id : 0,
  81. name : _tr("Color"),
  82. type : "RGBA",
  83. color : 0xffc7c729,
  84. default_value : f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0),
  85. min : 0.0,
  86. max : 1.0,
  87. precision : 100,
  88. display : 0
  89. },
  90. {
  91. id : 0,
  92. node_id : 0,
  93. name : _tr("Factor"),
  94. type : "VALUE",
  95. color : 0xffa1a1a1,
  96. default_value : f32_array_create_x(1.0),
  97. min : 0.0,
  98. max : 1.0,
  99. precision : 100,
  100. display : 0
  101. }
  102. ],
  103. buttons : [],
  104. width : 0,
  105. flags : 0
  106. };