// Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #include #include #include #include #include namespace anki { ReflectionProbeComponent::ReflectionProbeComponent(SceneNode* node) : SceneComponent(node, getStaticClassId()) , m_uuid(node->getSceneGraph().getNewUuid()) , m_spatial(this) { m_worldPos = node->getWorldTransform().getOrigin().xyz(); for(U32 i = 0; i < 6; ++i) { m_frustums[i].init(FrustumType::kPerspective, &node->getMemoryPool()); m_frustums[i].setPerspective(kClusterObjectFrustumNearPlane, 100.0f, kPi / 2.0f, kPi / 2.0f); m_frustums[i].setWorldTransform( Transform(m_worldPos.xyz0(), Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f)); m_frustums[i].setShadowCascadeCount(1); m_frustums[i].update(); } } ReflectionProbeComponent::~ReflectionProbeComponent() { } Error ReflectionProbeComponent::update(SceneComponentUpdateInfo& info, Bool& updated) { const Bool moved = info.m_node->movedThisFrame(); const Bool shapeUpdated = m_dirty; m_dirty = false; updated = moved || shapeUpdated; if(moved) [[unlikely]] { m_worldPos = info.m_node->getWorldTransform().getOrigin().xyz(); for(U32 i = 0; i < 6; ++i) { m_frustums[i].setWorldTransform( Transform(m_worldPos.xyz0(), Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f)); } } if(shapeUpdated) [[unlikely]] { F32 effectiveDistance = max(m_halfSize.x(), m_halfSize.y()); effectiveDistance = max(effectiveDistance, m_halfSize.z()); effectiveDistance = max(effectiveDistance, getExternalSubsystems(*info.m_node).m_config->getSceneProbeEffectiveDistance()); const F32 shadowCascadeDistance = min( effectiveDistance, getExternalSubsystems(*info.m_node).m_config->getSceneProbeShadowEffectiveDistance()); for(U32 i = 0; i < 6; ++i) { m_frustums[i].setFar(effectiveDistance); m_frustums[i].setShadowCascadeDistance(0, shadowCascadeDistance); // Add something really far to force LOD 0 to be used. The importing tools create LODs with holes some times // and that causes the sky to bleed to GI rendering m_frustums[i].setLodDistances({effectiveDistance - 3.0f * kEpsilonf, effectiveDistance - 2.0f * kEpsilonf, effectiveDistance - 1.0f * kEpsilonf}); } } if(updated) [[unlikely]] { // Set a new UUID to force the renderer to update the probe m_uuid = info.m_node->getSceneGraph().getNewUuid(); for(U32 i = 0; i < 6; ++i) { m_frustums[i].update(); } Aabb aabbWorld(-m_halfSize + m_worldPos, m_halfSize + m_worldPos); m_spatial.setBoundingShape(aabbWorld); m_spatial.update(info.m_node->getSceneGraph().getOctree()); } return Error::kNone; } } // end namespace anki