ReflectionProbeComponent.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Scene/Frustum.h>
  8. #include <AnKi/Scene/GpuSceneArray.h>
  9. #include <AnKi/Collision/Aabb.h>
  10. namespace anki {
  11. /// @addtogroup scene
  12. /// @{
  13. inline NumericCVar<U32> g_reflectionProbeResolutionCVar("Scene", "ReflectionProbeResolution", 128, 8, 2048,
  14. "The resolution of the reflection probe's reflection");
  15. /// Reflection probe component.
  16. class ReflectionProbeComponent : public SceneComponent
  17. {
  18. ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
  19. public:
  20. ReflectionProbeComponent(SceneNode* node);
  21. ~ReflectionProbeComponent();
  22. ANKI_INTERNAL Vec3 getBoxVolumeSize() const
  23. {
  24. return m_halfSize * 2.0f;
  25. }
  26. ANKI_INTERNAL Bool getEnvironmentTextureNeedsRefresh() const
  27. {
  28. return m_reflectionNeedsRefresh;
  29. }
  30. ANKI_INTERNAL void setEnvironmentTextureAsRefreshed()
  31. {
  32. m_reflectionNeedsRefresh = false;
  33. m_dirty = true; // To force update of the gpu scene
  34. }
  35. ANKI_INTERNAL Vec3 getWorldPosition() const
  36. {
  37. ANKI_ASSERT(m_worldPos.x() != kMaxF32);
  38. return m_worldPos;
  39. }
  40. /// The radius around the probe's center that can infuence the rendering of the env texture.
  41. ANKI_INTERNAL F32 getRenderRadius() const;
  42. ANKI_INTERNAL F32 getShadowsRenderRadius() const;
  43. ANKI_INTERNAL Texture& getReflectionTexture() const
  44. {
  45. return *m_reflectionTex;
  46. }
  47. ANKI_INTERNAL const GpuSceneArrays::ReflectionProbe::Allocation& getGpuSceneAllocation() const
  48. {
  49. return m_gpuSceneProbe;
  50. }
  51. private:
  52. Vec3 m_worldPos = Vec3(kMaxF32);
  53. Vec3 m_halfSize = Vec3(1.0f);
  54. GpuSceneArrays::ReflectionProbe::Allocation m_gpuSceneProbe;
  55. TexturePtr m_reflectionTex;
  56. U32 m_reflectionTexBindlessIndex = kMaxU32;
  57. Bool m_dirty = true;
  58. Bool m_reflectionNeedsRefresh = true;
  59. Error update(SceneComponentUpdateInfo& info, Bool& updated) override;
  60. };
  61. /// @}
  62. } // end namespace anki