camera_data_node.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. function camera_data_node_init() {
  2. array_push(nodes_material_input, camera_data_node_def);
  3. map_set(parser_material_node_vectors, "CAMERA", camera_data_node_vector);
  4. map_set(parser_material_node_values, "CAMERA", camera_data_node_value);
  5. }
  6. function camera_data_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  7. parser_material_kong.frag_vvec_cam = true;
  8. return "vvec_cam";
  9. }
  10. function camera_data_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  11. if (socket == node.outputs[1]) { // View Z Depth
  12. node_shader_add_constant(parser_material_kong, "camera_proj: float2", "_camera_plane_proj");
  13. parser_material_kong.frag_wvpposition = true;
  14. return "(constants.camera_proj.y / ((input.wvpposition.z / input.wvpposition.w) - constants.camera_proj.x))";
  15. }
  16. else { // View Distance
  17. node_shader_add_constant(parser_material_kong, "eye: float3", "_camera_pos");
  18. parser_material_kong.frag_wposition = true;
  19. return "distance(constants.eye, input.wposition)";
  20. }
  21. }
  22. let camera_data_node_def: ui_node_t = {
  23. id : 0,
  24. name : _tr("Camera Data"),
  25. type : "CAMERA",
  26. x : 0,
  27. y : 0,
  28. color : 0xffb34f5a,
  29. inputs : [],
  30. outputs : [
  31. {
  32. id : 0,
  33. node_id : 0,
  34. name : _tr("View Vector"),
  35. type : "VECTOR",
  36. color : 0xff6363c7,
  37. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  38. min : 0.0,
  39. max : 1.0,
  40. precision : 100,
  41. display : 0
  42. },
  43. {
  44. id : 0,
  45. node_id : 0,
  46. name : _tr("View Z Depth"),
  47. type : "VALUE",
  48. color : 0xffa1a1a1,
  49. default_value : f32_array_create_x(0.0),
  50. min : 0.0,
  51. max : 1.0,
  52. precision : 100,
  53. display : 0
  54. },
  55. {
  56. id : 0,
  57. node_id : 0,
  58. name : _tr("View Distance"),
  59. type : "VALUE",
  60. color : 0xffa1a1a1,
  61. default_value : f32_array_create_x(0.0),
  62. min : 0.0,
  63. max : 1.0,
  64. precision : 100,
  65. display : 0
  66. }
  67. ],
  68. buttons : [],
  69. width : 0,
  70. flags : 0
  71. };