checker_texture_node.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. function checker_texture_node_init() {
  2. array_push(nodes_material_texture, checker_texture_node_def);
  3. map_set(parser_material_node_vectors, "TEX_CHECKER", checker_texture_node_vector);
  4. map_set(parser_material_node_values, "TEX_CHECKER", checker_texture_node_value);
  5. }
  6. let str_tex_checker: string = "\
  7. fun tex_checker(co: float3, col1: float3, col2: float3, scale: float): float3 { \
  8. /* Prevent precision issues on unit coordinates */ \
  9. var p: float3 = (co + 0.000001 * 0.999999) * scale; \
  10. var xi: float = abs(floor(p.x)); \
  11. var yi: float = abs(floor(p.y)); \
  12. var zi: float = abs(floor(p.z)); \
  13. /* var check: bool = (xi % 2.0 == yi % 2.0) == zi % 2.0;*/ \
  14. var checka: int = 0; \
  15. var checkb: int = 0; \
  16. if (xi % 2.0 == yi % 2.0) { checka = 1; } \
  17. if (zi % 2.0 != 0.0) { checkb = 1; } \
  18. if (checka == checkb) { return col1; } return col2; \
  19. } \
  20. fun tex_checker_f(co: float3, scale: float): float { \
  21. var p: float3 = (co + 0.000001 * 0.999999) * scale; \
  22. var xi: float = abs(floor(p.x)); \
  23. var yi: float = abs(floor(p.y)); \
  24. var zi: float = abs(floor(p.z)); \
  25. /*return float((xi % 2.0 == yi % 2.0) == zi % 2.0);*/ \
  26. var checka: int = 0; \
  27. var checkb: int = 0; \
  28. if (xi % 2.0 == yi % 2.0) { checka = 1; } \
  29. if (zi % 2.0 != 0.0) { checkb = 1; } \
  30. if (checka == checkb) { return 1.0; } return 0.0; \
  31. \
  32. } \
  33. ";
  34. function checker_texture_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  35. node_shader_add_function(parser_material_kong, str_tex_checker);
  36. let co: string = parser_material_get_coord(node);
  37. let col1: string = parser_material_parse_vector_input(node.inputs[1]);
  38. let col2: string = parser_material_parse_vector_input(node.inputs[2]);
  39. let scale: string = parser_material_parse_value_input(node.inputs[3]);
  40. let res: string = "tex_checker(" + co + ", " + col1 + ", " + col2 + ", " + scale + ")";
  41. return res;
  42. }
  43. function checker_texture_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  44. node_shader_add_function(parser_material_kong, str_tex_checker);
  45. let co: string = parser_material_get_coord(node);
  46. let scale: string = parser_material_parse_value_input(node.inputs[3]);
  47. let res: string = "tex_checker_f(" + co + ", " + scale + ")";
  48. return res;
  49. }
  50. let checker_texture_node_def: ui_node_t = {
  51. id : 0,
  52. name : _tr("Checker Texture"),
  53. type : "TEX_CHECKER",
  54. x : 0,
  55. y : 0,
  56. color : 0xff4982a0,
  57. inputs : [
  58. {
  59. id : 0,
  60. node_id : 0,
  61. name : _tr("Vector"),
  62. type : "VECTOR",
  63. color : 0xff6363c7,
  64. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  65. min : 0.0,
  66. max : 1.0,
  67. precision : 100,
  68. display : 0
  69. },
  70. {
  71. id : 0,
  72. node_id : 0,
  73. name : _tr("Color 1"),
  74. type : "RGBA",
  75. color : 0xffc7c729,
  76. default_value : f32_array_create_xyz(0.8, 0.8, 0.8),
  77. min : 0.0,
  78. max : 1.0,
  79. precision : 100,
  80. display : 0
  81. },
  82. {
  83. id : 0,
  84. node_id : 0,
  85. name : _tr("Color 2"),
  86. type : "RGBA",
  87. color : 0xffc7c729,
  88. default_value : f32_array_create_xyz(0.2, 0.2, 0.2),
  89. min : 0.0,
  90. max : 1.0,
  91. precision : 100,
  92. display : 0
  93. },
  94. {
  95. id : 0,
  96. node_id : 0,
  97. name : _tr("Scale"),
  98. type : "VALUE",
  99. color : 0xffa1a1a1,
  100. default_value : f32_array_create_x(5.0),
  101. min : 0.0,
  102. max : 10.0,
  103. precision : 100,
  104. display : 0
  105. }
  106. ],
  107. outputs : [
  108. {
  109. id : 0,
  110. node_id : 0,
  111. name : _tr("Color"),
  112. type : "RGBA",
  113. color : 0xffc7c729,
  114. default_value : f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0),
  115. min : 0.0,
  116. max : 1.0,
  117. precision : 100,
  118. display : 0
  119. },
  120. {
  121. id : 0,
  122. node_id : 0,
  123. name : _tr("Factor"),
  124. type : "VALUE",
  125. color : 0xffa1a1a1,
  126. default_value : f32_array_create_x(1.0),
  127. min : 0.0,
  128. max : 1.0,
  129. precision : 100,
  130. display : 0
  131. }
  132. ],
  133. buttons : [],
  134. width : 0,
  135. flags : 0
  136. };