FogDensityComponent.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <AnKi/Scene/Components/FogDensityComponent.h>
  6. #include <AnKi/Scene/SceneNode.h>
  7. #include <AnKi/Scene/SceneGraph.h>
  8. #include <AnKi/GpuMemory/GpuSceneBuffer.h>
  9. namespace anki {
  10. FogDensityComponent::FogDensityComponent(SceneNode* node)
  11. : SceneComponent(node, kClassType)
  12. {
  13. m_gpuSceneVolume.allocate();
  14. }
  15. FogDensityComponent ::~FogDensityComponent()
  16. {
  17. }
  18. void FogDensityComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
  19. {
  20. ANKI_ASSERT(m_type < FogDensityComponentShape::kCount);
  21. updated = m_dirty || info.m_node->movedThisFrame();
  22. if(updated)
  23. {
  24. m_dirty = false;
  25. const Transform& trf = info.m_node->getWorldTransform();
  26. // Upload to the GPU scene
  27. GpuSceneFogDensityVolume gpuVolume;
  28. if(m_type == FogDensityComponentShape::kBox)
  29. {
  30. gpuVolume.m_aabbMinOrSphereCenter = Vec3(-1.0f) * trf.getScale().xyz() + trf.getOrigin().xyz();
  31. gpuVolume.m_aabbMaxOrSphereRadius = Vec3(+1.0f) * trf.getScale().xyz() + trf.getOrigin().xyz();
  32. }
  33. else
  34. {
  35. gpuVolume.m_aabbMaxOrSphereRadius = Vec3(1.0f * max(max(trf.getScale().x(), trf.getScale().y()), trf.getScale().z()));
  36. gpuVolume.m_aabbMinOrSphereCenter = trf.getOrigin().xyz();
  37. }
  38. gpuVolume.m_isBox = m_type == FogDensityComponentShape::kBox;
  39. gpuVolume.m_density = m_density;
  40. m_gpuSceneVolume.uploadToGpuScene(gpuVolume);
  41. }
  42. }
  43. } // end namespace anki