SkyboxComponent.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSEJ
  5. #include <AnKi/Scene/Components/SkyboxComponent.h>
  6. #include <AnKi/Scene/SceneNode.h>
  7. #include <AnKi/Scene/SceneGraph.h>
  8. #include <AnKi/Resource/ImageResource.h>
  9. #include <AnKi/Resource/ResourceManager.h>
  10. #include <AnKi/Renderer/RenderQueue.h>
  11. namespace anki {
  12. SkyboxComponent::SkyboxComponent(SceneNode* node)
  13. : SceneComponent(node, getStaticClassId())
  14. , m_node(node)
  15. , m_spatial(this)
  16. {
  17. m_spatial.setAlwaysVisible(true);
  18. m_spatial.setUpdatesOctreeBounds(false);
  19. }
  20. SkyboxComponent::~SkyboxComponent()
  21. {
  22. m_spatial.removeFromOctree(m_node->getSceneGraph().getOctree());
  23. }
  24. void SkyboxComponent::loadImageResource(CString filename)
  25. {
  26. ImageResourcePtr img;
  27. const Error err = ResourceManager::getSingleton().loadResource(filename, img);
  28. if(err)
  29. {
  30. ANKI_SCENE_LOGE("Setting skybox image failed. Ignoring error");
  31. return;
  32. }
  33. m_image = std::move(img);
  34. m_type = SkyboxType::kImage2D;
  35. }
  36. Error SkyboxComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
  37. {
  38. updated = m_spatial.update(info.m_node->getSceneGraph().getOctree());
  39. return Error::kNone;
  40. }
  41. void SkyboxComponent::setupSkyboxQueueElement(SkyboxQueueElement& queueElement) const
  42. {
  43. if(m_type == SkyboxType::kImage2D)
  44. {
  45. queueElement.m_skyboxTexture = m_image->getTextureView().get();
  46. }
  47. else
  48. {
  49. queueElement.m_skyboxTexture = nullptr;
  50. queueElement.m_solidColor = m_color;
  51. }
  52. queueElement.m_fog.m_minDensity = m_fog.m_minDensity;
  53. queueElement.m_fog.m_maxDensity = m_fog.m_maxDensity;
  54. queueElement.m_fog.m_heightOfMinDensity = m_fog.m_heightOfMinDensity;
  55. queueElement.m_fog.m_heightOfMaxDensity = m_fog.m_heightOfMaxDensity;
  56. queueElement.m_fog.m_scatteringCoeff = m_fog.m_scatteringCoeff;
  57. queueElement.m_fog.m_absorptionCoeff = m_fog.m_absorptionCoeff;
  58. queueElement.m_fog.m_diffuseColor = m_fog.m_diffuseColor;
  59. }
  60. } // end namespace anki