FogDensityComponent.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. Error FogDensityComponent::serialize(SceneSerializer& serializer)
  44. {
  45. U32 type = U32(m_type);
  46. ANKI_SERIALIZE(type, 1);
  47. m_type = FogDensityComponentShape(type);
  48. ANKI_SERIALIZE(m_density, 1);
  49. return Error::kNone;
  50. }
  51. } // end namespace anki