attribute_node.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function attribute_node_init() {
  2. array_push(nodes_material_input, attribute_node_def);
  3. map_set(parser_material_node_vectors, "ATTRIBUTE", attribute_node_vector);
  4. map_set(parser_material_node_values, "ATTRIBUTE", attribute_node_value);
  5. }
  6. function attribute_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  7. if (socket == node.outputs[0]) { // Color
  8. if (parser_material_kong.context.allow_vcols) {
  9. node_shader_context_add_elem(parser_material_kong.context, "col", "short4norm"); // Vcols only for now
  10. return "input.vcolor";
  11. }
  12. else {
  13. return ("float3(0.0, 0.0, 0.0)");
  14. }
  15. }
  16. else { // Vector
  17. node_shader_context_add_elem(parser_material_kong.context, "tex", "short2norm"); // UVMaps only for now
  18. return "float3(tex_coord.x, tex_coord.y, 0.0)";
  19. }
  20. }
  21. function attribute_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  22. node_shader_add_constant(parser_material_kong, "time: float", "_time");
  23. return "constants.time";
  24. }
  25. let attribute_node_def: ui_node_t = {
  26. id : 0,
  27. name : _tr("Attribute"),
  28. type : "ATTRIBUTE",
  29. x : 0,
  30. y : 0,
  31. color : 0xffb34f5a,
  32. inputs : [],
  33. outputs : [
  34. {
  35. id : 0,
  36. node_id : 0,
  37. name : _tr("Color"),
  38. type : "RGBA",
  39. color : 0xffc7c729,
  40. default_value : f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0),
  41. min : 0.0,
  42. max : 1.0,
  43. precision : 100,
  44. display : 0
  45. },
  46. {
  47. id : 0,
  48. node_id : 0,
  49. name : _tr("Vector"),
  50. type : "VECTOR",
  51. color : 0xff6363c7,
  52. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  53. min : 0.0,
  54. max : 1.0,
  55. precision : 100,
  56. display : 0
  57. },
  58. {
  59. id : 0,
  60. node_id : 0,
  61. name : _tr("Factor"),
  62. type : "VALUE",
  63. color : 0xffa1a1a1,
  64. default_value : f32_array_create_x(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("Alpha"),
  74. type : "VALUE",
  75. color : 0xffa1a1a1,
  76. default_value : f32_array_create_x(0.0),
  77. min : 0.0,
  78. max : 1.0,
  79. precision : 100,
  80. display : 0
  81. }
  82. ],
  83. buttons : [ {
  84. name : _tr("Name"),
  85. type : "STRING",
  86. output : -1,
  87. default_value : f32_array_create_x(0),
  88. data : null,
  89. min : 0.0,
  90. max : 1.0,
  91. precision : 100,
  92. height : 0
  93. } ],
  94. width : 0,
  95. flags : 0
  96. };