ReflectionProbeComponent.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ANKI_CVAR2(NumericCVar<U32>, Render, ProbeReflections, Resolution, 128, 8, 2048, "The resolution of the reflection probe's reflection")
  14. /// Reflection probe component.
  15. class ReflectionProbeComponent : public SceneComponent
  16. {
  17. ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
  18. public:
  19. ReflectionProbeComponent(SceneNode* node);
  20. ~ReflectionProbeComponent();
  21. ANKI_INTERNAL Vec3 getBoxVolumeSize() const
  22. {
  23. return m_halfSize * 2.0f;
  24. }
  25. ANKI_INTERNAL Bool getEnvironmentTextureNeedsRefresh() const
  26. {
  27. return m_reflectionNeedsRefresh;
  28. }
  29. ANKI_INTERNAL void setEnvironmentTextureAsRefreshed()
  30. {
  31. m_reflectionNeedsRefresh = false;
  32. m_dirty = true; // To force update of the gpu scene
  33. }
  34. ANKI_INTERNAL Vec3 getWorldPosition() const
  35. {
  36. ANKI_ASSERT(m_worldPos.x() != kMaxF32);
  37. return m_worldPos;
  38. }
  39. /// The radius around the probe's center that can infuence the rendering of the env texture.
  40. ANKI_INTERNAL F32 getRenderRadius() const;
  41. ANKI_INTERNAL F32 getShadowsRenderRadius() const;
  42. ANKI_INTERNAL Texture& getReflectionTexture() const
  43. {
  44. return *m_reflectionTex;
  45. }
  46. ANKI_INTERNAL const GpuSceneArrays::ReflectionProbe::Allocation& getGpuSceneAllocation() const
  47. {
  48. return m_gpuSceneProbe;
  49. }
  50. private:
  51. Vec3 m_worldPos = Vec3(kMaxF32);
  52. Vec3 m_halfSize = Vec3(1.0f);
  53. GpuSceneArrays::ReflectionProbe::Allocation m_gpuSceneProbe;
  54. TexturePtr m_reflectionTex;
  55. U32 m_reflectionTexBindlessIndex = kMaxU32;
  56. Bool m_dirty = true;
  57. Bool m_reflectionNeedsRefresh = true;
  58. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  59. };
  60. /// @}
  61. } // end namespace anki