object_info_node.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. function object_info_node_init() {
  2. array_push(nodes_material_input, object_info_node_def);
  3. map_set(parser_material_node_vectors, "OBJECT_INFO", object_info_node_vector);
  4. map_set(parser_material_node_values, "OBJECT_INFO", object_info_node_value);
  5. }
  6. function object_info_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  7. if (socket == node.outputs[0]) { // Location
  8. parser_material_kong.frag_wposition = true;
  9. return "input.wposition";
  10. }
  11. else { // Color
  12. return "float3(0.0, 0.0, 0.0)";
  13. }
  14. }
  15. function object_info_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  16. if (socket == node.outputs[2]) { // Alpha
  17. return "0.0";
  18. }
  19. else if (socket == node.outputs[3]) { // Object Index
  20. node_shader_add_constant(parser_material_kong, "object_info_index: float", "_object_info_index");
  21. return "constants.object_info_index";
  22. }
  23. else if (socket == node.outputs[4]) { // Material Index
  24. node_shader_add_constant(parser_material_kong, "object_info_material_index: float", "_object_info_material_index");
  25. return "constants.object_info_material_index";
  26. }
  27. else { // Random
  28. node_shader_add_constant(parser_material_kong, "object_info_random: float", "_object_info_random");
  29. return "constants.object_info_random";
  30. }
  31. }
  32. let object_info_node_def: ui_node_t = {
  33. id : 0,
  34. name : _tr("Object Info"),
  35. type : "OBJECT_INFO",
  36. x : 0,
  37. y : 0,
  38. color : 0xffb34f5a,
  39. inputs : [],
  40. outputs : [
  41. {
  42. id : 0,
  43. node_id : 0,
  44. name : _tr("Location"),
  45. type : "VECTOR",
  46. color : 0xff6363c7,
  47. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  48. min : 0.0,
  49. max : 1.0,
  50. precision : 100,
  51. display : 0
  52. },
  53. {
  54. id : 0,
  55. node_id : 0,
  56. name : _tr("Color"),
  57. type : "RGBA",
  58. color : 0xffc7c729,
  59. default_value : f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
  60. min : 0.0,
  61. max : 1.0,
  62. precision : 100,
  63. display : 0
  64. },
  65. {
  66. id : 0,
  67. node_id : 0,
  68. name : _tr("Alpha"),
  69. type : "VALUE",
  70. color : 0xffa1a1a1,
  71. default_value : f32_array_create_x(0.0),
  72. min : 0.0,
  73. max : 1.0,
  74. precision : 100,
  75. display : 0
  76. },
  77. {
  78. id : 0,
  79. node_id : 0,
  80. name : _tr("Object Index"),
  81. type : "VALUE",
  82. color : 0xffa1a1a1,
  83. default_value : f32_array_create_x(0.0),
  84. min : 0.0,
  85. max : 1.0,
  86. precision : 100,
  87. display : 0
  88. },
  89. {
  90. id : 0,
  91. node_id : 0,
  92. name : _tr("Material Index"),
  93. type : "VALUE",
  94. color : 0xffa1a1a1,
  95. default_value : f32_array_create_x(0.0),
  96. min : 0.0,
  97. max : 1.0,
  98. precision : 100,
  99. display : 0
  100. },
  101. {
  102. id : 0,
  103. node_id : 0,
  104. name : _tr("Random"),
  105. type : "VALUE",
  106. color : 0xffa1a1a1,
  107. default_value : f32_array_create_x(0.0),
  108. min : 0.0,
  109. max : 1.0,
  110. precision : 100,
  111. display : 0
  112. }
  113. ],
  114. buttons : [],
  115. width : 0,
  116. flags : 0
  117. };