diff --git a/Source/Engine/Graphics/Materials/MaterialShaderFeatures.cpp b/Source/Engine/Graphics/Materials/MaterialShaderFeatures.cpp index 490464092..dbd934a8e 100644 --- a/Source/Engine/Graphics/Materials/MaterialShaderFeatures.cpp +++ b/Source/Engine/Graphics/Materials/MaterialShaderFeatures.cpp @@ -76,10 +76,11 @@ void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, SpanEnvironmentProbes.Count(); i++) { const auto p = cache->EnvironmentProbes[i]; - if (p->GetSphere().Contains(drawCall.World.GetTranslation()) != ContainmentType::Disjoint) + if (p->GetSphere().Contains(drawCallOrigin) != ContainmentType::Disjoint) { probe = p; break; @@ -87,7 +88,7 @@ void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, SpanGetProbe()) { - probe->SetupProbeData(&data.EnvironmentProbe); + probe->SetupProbeData(params.RenderContext, &data.EnvironmentProbe); const auto texture = probe->GetProbe()->GetTexture(); context->BindSR(envProbeShaderRegisterIndex, GET_TEXTURE_VIEW_SAFE(texture)); } diff --git a/Source/Engine/Level/Actors/EnvironmentProbe.cpp b/Source/Engine/Level/Actors/EnvironmentProbe.cpp index ea9e7bd07..31f60bb4d 100644 --- a/Source/Engine/Level/Actors/EnvironmentProbe.cpp +++ b/Source/Engine/Level/Actors/EnvironmentProbe.cpp @@ -44,10 +44,10 @@ float EnvironmentProbe::GetScaledRadius() const return _radius * _transform.Scale.MaxValue(); } -void EnvironmentProbe::SetupProbeData(ProbeData* data) const +void EnvironmentProbe::SetupProbeData(const RenderContext& renderContext, ProbeData* data) const { const float radius = GetScaledRadius(); - data->Data0 = Float4(GetPosition(), 0); // TODO: large-worlds + data->Data0 = Float4(GetPosition() - renderContext.View.Origin, 0); data->Data1 = Float4(radius, 1.0f / radius, Brightness, 0); } diff --git a/Source/Engine/Level/Actors/EnvironmentProbe.h b/Source/Engine/Level/Actors/EnvironmentProbe.h index cc84d2f1b..b2dac5f15 100644 --- a/Source/Engine/Level/Actors/EnvironmentProbe.h +++ b/Source/Engine/Level/Actors/EnvironmentProbe.h @@ -89,8 +89,9 @@ public: /// /// Setup probe data structure /// + /// Rendering context /// Packed probe data to set - void SetupProbeData(struct ProbeData* data) const; + void SetupProbeData(const RenderContext& renderContext, struct ProbeData* data) const; /// /// Gets the custom probe (null if using baked one or none). diff --git a/Source/Engine/Renderer/ProbesRenderer.cpp b/Source/Engine/Renderer/ProbesRenderer.cpp index 6038b8362..3582cab32 100644 --- a/Source/Engine/Renderer/ProbesRenderer.cpp +++ b/Source/Engine/Renderer/ProbesRenderer.cpp @@ -12,6 +12,7 @@ #include "Engine/Level/Actors/EnvironmentProbe.h" #include "Engine/Level/Actors/SkyLight.h" #include "Engine/Level/SceneQuery.h" +#include "Engine/Level/LargeWorlds.h" #include "Engine/ContentExporters/AssetExporters.h" #include "Engine/Serialization/FileWriteStream.h" #include "Engine/Engine/Time.h" @@ -430,12 +431,11 @@ bool fixFarPlaneTreeExecute(Actor* actor, const Vector3& position, float& farPla if (auto* pointLight = dynamic_cast(actor)) { const Real dst = Vector3::Distance(pointLight->GetPosition(), position) + pointLight->GetScaledRadius(); - if (dst > farPlane) + if (dst > farPlane && dst * 0.5f < farPlane) { farPlane = (float)dst; } } - return true; } @@ -480,7 +480,8 @@ void ProbesRenderer::onRender(RenderTask* task, GPUContext* context) SceneQuery::TreeExecute(f, position, farPlane); // Setup view - _task->View.SetUpCube(nearPlane, farPlane, position); + LargeWorlds::UpdateOrigin(_task->View.Origin, position); + _task->View.SetUpCube(nearPlane, farPlane, position - _task->View.Origin); } else if (_current.Type == EntryType::SkyLight) { @@ -494,7 +495,8 @@ void ProbesRenderer::onRender(RenderTask* task, GPUContext* context) // TODO: use setLowerHemisphereToBlack feature for SkyLight? // Setup view - _task->View.SetUpCube(nearPlane, farPlane, position); + LargeWorlds::UpdateOrigin(_task->View.Origin, position); + _task->View.SetUpCube(nearPlane, farPlane, position - _task->View.Origin); } // Disable actor during baking (it cannot influence own results) diff --git a/Source/Engine/Renderer/ReflectionsPass.cpp b/Source/Engine/Renderer/ReflectionsPass.cpp index ffbb4cf50..ed7f25eed 100644 --- a/Source/Engine/Renderer/ReflectionsPass.cpp +++ b/Source/Engine/Renderer/ReflectionsPass.cpp @@ -415,7 +415,7 @@ void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* light if (!probe->HasProbeLoaded()) continue; float probeRadius = probe->GetScaledRadius(); - Vector3 probePosition = probe->GetPosition(); // TODO: large-worlds + Float3 probePosition = probe->GetPosition() - renderContext.View.Origin; // Get distance from view center to light center less radius (check if view is inside a sphere) const float sphereModelScale = 2.0f; @@ -430,7 +430,7 @@ void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* light Matrix::Multiply(world, view.ViewProjection(), wvp); // Pack probe properties buffer - probe->SetupProbeData(&data.PData); + probe->SetupProbeData(renderContext, &data.PData); Matrix::Transpose(wvp, data.WVP); // Render reflections