renderer_geometry_instance.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**************************************************************************/
  2. /* renderer_geometry_instance.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_pivot_data(float p_sorting_offset, bool p_use_aabb_center) {
  68. sorting_offset = p_sorting_offset;
  69. use_aabb_center = p_use_aabb_center;
  70. }
  71. void RenderGeometryInstanceBase::set_lod_bias(float p_lod_bias) {
  72. lod_bias = p_lod_bias;
  73. }
  74. void RenderGeometryInstanceBase::set_layer_mask(uint32_t p_layer_mask) {
  75. layer_mask = p_layer_mask;
  76. }
  77. 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) {
  78. fade_near = p_enable_near;
  79. fade_near_begin = p_near_begin;
  80. fade_near_end = p_near_end;
  81. fade_far = p_enable_far;
  82. fade_far_begin = p_far_begin;
  83. fade_far_end = p_far_end;
  84. }
  85. void RenderGeometryInstanceBase::set_parent_fade_alpha(float p_alpha) {
  86. parent_fade_alpha = p_alpha;
  87. }
  88. void RenderGeometryInstanceBase::set_transparency(float p_transparency) {
  89. force_alpha = CLAMP(1.0 - p_transparency, 0, 1);
  90. }
  91. void RenderGeometryInstanceBase::set_use_baked_light(bool p_enable) {
  92. data->use_baked_light = p_enable;
  93. _mark_dirty();
  94. }
  95. void RenderGeometryInstanceBase::set_use_dynamic_gi(bool p_enable) {
  96. data->use_dynamic_gi = p_enable;
  97. _mark_dirty();
  98. }
  99. void RenderGeometryInstanceBase::set_instance_shader_uniforms_offset(int32_t p_offset) {
  100. shader_uniforms_offset = p_offset;
  101. _mark_dirty();
  102. }
  103. void RenderGeometryInstanceBase::set_cast_double_sided_shadows(bool p_enable) {
  104. data->cast_double_sided_shadows = p_enable;
  105. _mark_dirty();
  106. }
  107. Transform3D RenderGeometryInstanceBase::get_transform() {
  108. return transform;
  109. }
  110. AABB RenderGeometryInstanceBase::get_aabb() {
  111. return data->aabb;
  112. }