renderer_geometry_instance.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* renderer_geometry_instance.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "servers/rendering/renderer_geometry_instance.h"
  31. void RenderGeometryInstanceBase::set_skeleton(RID p_skeleton) {
  32. data->skeleton = p_skeleton;
  33. _mark_dirty();
  34. data->dirty_dependencies = true;
  35. }
  36. void RenderGeometryInstanceBase::set_material_override(RID p_override) {
  37. data->material_override = p_override;
  38. _mark_dirty();
  39. data->dirty_dependencies = true;
  40. }
  41. void RenderGeometryInstanceBase::set_material_overlay(RID p_overlay) {
  42. data->material_overlay = p_overlay;
  43. _mark_dirty();
  44. data->dirty_dependencies = true;
  45. }
  46. void RenderGeometryInstanceBase::set_surface_materials(const Vector<RID> &p_materials) {
  47. data->surface_materials = p_materials;
  48. _mark_dirty();
  49. data->dirty_dependencies = true;
  50. }
  51. void RenderGeometryInstanceBase::set_mesh_instance(RID p_mesh_instance) {
  52. mesh_instance = p_mesh_instance;
  53. _mark_dirty();
  54. }
  55. void RenderGeometryInstanceBase::set_transform(const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) {
  56. transform = p_transform;
  57. mirror = p_transform.basis.determinant() < 0;
  58. data->aabb = p_aabb;
  59. transformed_aabb = p_transformed_aabb;
  60. Vector3 model_scale_vec = p_transform.basis.get_scale_abs();
  61. // handle non uniform scale here
  62. float max_scale = MAX(model_scale_vec.x, MAX(model_scale_vec.y, model_scale_vec.z));
  63. float min_scale = MIN(model_scale_vec.x, MIN(model_scale_vec.y, model_scale_vec.z));
  64. non_uniform_scale = max_scale >= 0.0 && (min_scale / max_scale) < 0.9;
  65. lod_model_scale = max_scale;
  66. }
  67. void RenderGeometryInstanceBase::set_lod_bias(float p_lod_bias) {
  68. lod_bias = p_lod_bias;
  69. }
  70. void RenderGeometryInstanceBase::set_layer_mask(uint32_t p_layer_mask) {
  71. layer_mask = p_layer_mask;
  72. }
  73. void RenderGeometryInstanceBase::set_fade_range(bool p_enable_near, float p_near_begin, float p_near_end, bool p_enable_far, float p_far_begin, float p_far_end) {
  74. fade_near = p_enable_near;
  75. fade_near_begin = p_near_begin;
  76. fade_near_end = p_near_end;
  77. fade_far = p_enable_far;
  78. fade_far_begin = p_far_begin;
  79. fade_far_end = p_far_end;
  80. }
  81. void RenderGeometryInstanceBase::set_parent_fade_alpha(float p_alpha) {
  82. parent_fade_alpha = p_alpha;
  83. }
  84. void RenderGeometryInstanceBase::set_transparency(float p_transparency) {
  85. force_alpha = CLAMP(1.0 - p_transparency, 0, 1);
  86. }
  87. void RenderGeometryInstanceBase::set_use_baked_light(bool p_enable) {
  88. data->use_baked_light = p_enable;
  89. _mark_dirty();
  90. }
  91. void RenderGeometryInstanceBase::set_use_dynamic_gi(bool p_enable) {
  92. data->use_dynamic_gi = p_enable;
  93. _mark_dirty();
  94. }
  95. void RenderGeometryInstanceBase::set_instance_shader_uniforms_offset(int32_t p_offset) {
  96. shader_uniforms_offset = p_offset;
  97. _mark_dirty();
  98. }
  99. void RenderGeometryInstanceBase::set_cast_double_sided_shadows(bool p_enable) {
  100. data->cast_double_sided_shadows = p_enable;
  101. _mark_dirty();
  102. }
  103. Transform3D RenderGeometryInstanceBase::get_transform() {
  104. return transform;
  105. }
  106. AABB RenderGeometryInstanceBase::get_aabb() {
  107. return data->aabb;
  108. }