diff --git a/filament/src/ShadowMap.cpp b/filament/src/ShadowMap.cpp index d19127d705..f23648a8d4 100644 --- a/filament/src/ShadowMap.cpp +++ b/filament/src/ShadowMap.cpp @@ -1381,6 +1381,11 @@ void ShadowMap::prepareTime(Transaction const& transaction, ShadowMapDescriptorSet::prepareTime(transaction, engine, userTime); } +void ShadowMap::prepareMaterialGlobals(Transaction const& transaction, + std::array const& materialGlobals) noexcept { + ShadowMapDescriptorSet::prepareMaterialGlobals(transaction, materialGlobals); +} + void ShadowMap::prepareShadowMapping(Transaction const& transaction, bool const highPrecision) noexcept { ShadowMapDescriptorSet::prepareShadowMapping(transaction, highPrecision); diff --git a/filament/src/ShadowMap.h b/filament/src/ShadowMap.h index f98038fc4d..a1202668ea 100644 --- a/filament/src/ShadowMap.h +++ b/filament/src/ShadowMap.h @@ -33,9 +33,6 @@ #include #include -#include -#include -#include #include @@ -199,6 +196,8 @@ public: backend::Viewport const& viewport) noexcept; static void prepareTime(Transaction const& transaction, FEngine const& engine, math::float4 const& userTime) noexcept; + static void prepareMaterialGlobals(Transaction const& transaction, + std::array const& materialGlobals) noexcept; static void prepareShadowMapping(Transaction const& transaction, bool highPrecision) noexcept; static ShadowMapDescriptorSet::Transaction open(backend::DriverApi& driver) noexcept; @@ -326,12 +325,12 @@ private: static float texelSizeWorldSpace(const math::mat4f& W, const math::mat4f& MbMtF, uint16_t shadowDimension) noexcept; - static constexpr const Segment sBoxSegments[12] = { + static constexpr Segment sBoxSegments[12] = { { 0, 1 }, { 1, 3 }, { 3, 2 }, { 2, 0 }, { 4, 5 }, { 5, 7 }, { 7, 6 }, { 6, 4 }, { 0, 4 }, { 1, 5 }, { 3, 7 }, { 2, 6 }, }; - static constexpr const Quad sBoxQuads[6] = { + static constexpr Quad sBoxQuads[6] = { { 2, 0, 1, 3 }, // far { 6, 4, 5, 7 }, // near { 2, 0, 4, 6 }, // left diff --git a/filament/src/ShadowMapManager.cpp b/filament/src/ShadowMapManager.cpp index 78567ed9ee..a4310cb518 100644 --- a/filament/src/ShadowMapManager.cpp +++ b/filament/src/ShadowMapManager.cpp @@ -388,6 +388,7 @@ FrameGraphId ShadowMapManager::render(FEngine& engine, FrameG ShadowMap::prepareCamera(transaction, engine, cameraInfo); ShadowMap::prepareViewport(transaction, shadowMap.getViewport()); ShadowMap::prepareTime(transaction, engine, userTime); + ShadowMap::prepareMaterialGlobals(transaction, view.getMaterialGlobals()); ShadowMap::prepareShadowMapping(transaction, vsmShadowOptions.highPrecision); shadowMap.commit(transaction, engine, driver); diff --git a/filament/src/details/Renderer.cpp b/filament/src/details/Renderer.cpp index 29f78d5f14..c43c1048e6 100644 --- a/filament/src/details/Renderer.cpp +++ b/filament/src/details/Renderer.cpp @@ -244,6 +244,23 @@ void FRenderer::setVsyncTime(uint64_t const steadyClockTimeNano) noexcept { mVsyncSteadyClockTimeNano = steadyClockTimeNano; } +std::pair FRenderer::prepareUpscaler(float2 const scale, + TemporalAntiAliasingOptions const& taaOptions, + DynamicResolutionOptions const& dsrOptions) { + float bias = 0.0f; + float2 derivativesScale{ 1.0f }; + if (dsrOptions.enabled && dsrOptions.quality >= QualityLevel::HIGH) { + bias = std::log2(std::min(scale.x, scale.y)); + } + if (taaOptions.enabled) { + bias += taaOptions.lodBias; + if (taaOptions.upscaling) { + derivativesScale = 0.5f; + } + } + return { bias, derivativesScale }; +} + void FRenderer::skipFrame(uint64_t vsyncSteadyClockTimeNano) { FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT); @@ -799,9 +816,11 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { xvp.bottom = int32_t(guardBand); } + auto [bias, derivativeScale] = prepareUpscaler(scale, taaOptions, dsrOptions); + view.prepare(engine, driver, rootArenaScope, svp, cameraInfo, getShaderUserTime(), needsAlphaChannel); - view.prepareUpscaler(scale, taaOptions, dsrOptions); + view.prepareLodBias(bias, derivativeScale); // Set the PER_VIEW UBO for the passes that use the user materials, but are not the color pass // (e.g. structure, ssao). The PER_VIEW UBO may be different because these passes don't run @@ -816,7 +835,7 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { int32_t(float(xvp.bottom) * aoOptions.resolution), uint32_t(float(xvp.width) * aoOptions.resolution), uint32_t(float(xvp.height) * aoOptions.resolution) }); - //descriptorSet.prepareLodBias(); // FIXME: we need to do that too + descriptorSet.prepareLodBias(bias, derivativeScale); descriptorSet.prepareMaterialGlobals(view.getMaterialGlobals()); descriptorSet.commit(driver); diff --git a/filament/src/details/Renderer.h b/filament/src/details/Renderer.h index 3f36b4343c..e5baa1a493 100644 --- a/filament/src/details/Renderer.h +++ b/filament/src/details/Renderer.h @@ -189,6 +189,10 @@ private: void renderInternal(FView const* view); void renderJob(RootArenaScope& rootArenaScope, FView& view); + std::pair prepareUpscaler(math::float2 scale, + TemporalAntiAliasingOptions const& taaOptions, + DynamicResolutionOptions const& dsrOptions); + // keep a reference to our engine FEngine& mEngine; FrameSkipper mFrameSkipper; diff --git a/filament/src/details/View.cpp b/filament/src/details/View.cpp index 8d4dd3c0f3..1855facbdf 100644 --- a/filament/src/details/View.cpp +++ b/filament/src/details/View.cpp @@ -906,29 +906,15 @@ UTILS_NOINLINE }); } -void FView::prepareUpscaler(float2 const scale, - TemporalAntiAliasingOptions const& taaOptions, - DynamicResolutionOptions const& dsrOptions) const noexcept { - FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT); - float bias = 0.0f; - float2 derivativesScale{ 1.0f }; - if (dsrOptions.enabled && dsrOptions.quality >= QualityLevel::HIGH) { - bias = std::log2(std::min(scale.x, scale.y)); - } - if (taaOptions.enabled) { - bias += taaOptions.lodBias; - if (taaOptions.upscaling) { - derivativesScale = 0.5f; - } - } - getColorPassDescriptorSet().prepareLodBias(bias, derivativesScale); -} - void FView::prepareCamera(FEngine& engine, const CameraInfo& cameraInfo) const noexcept { FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT); getColorPassDescriptorSet().prepareCamera(engine, cameraInfo); } +void FView::prepareLodBias(float const bias, float2 const derivativesScale) const noexcept { + getColorPassDescriptorSet().prepareLodBias(bias, derivativesScale); +} + void FView::prepareViewport( const filament::Viewport& physicalViewport, const filament::Viewport& logicalViewport) const noexcept { diff --git a/filament/src/details/View.h b/filament/src/details/View.h index 3e465ed06d..5854f60730 100644 --- a/filament/src/details/View.h +++ b/filament/src/details/View.h @@ -160,11 +160,10 @@ public: return mName.c_str_safe(); } - void prepareUpscaler(math::float2 scale, - TemporalAntiAliasingOptions const& taaOptions, - DynamicResolutionOptions const& dsrOptions) const noexcept; void prepareCamera(FEngine& engine, const CameraInfo& cameraInfo) const noexcept; + void prepareLodBias(float bias, math::float2 derivativesScale) const noexcept; + void prepareViewport( const Viewport& physicalViewport, const Viewport& logicalViewport) const noexcept; diff --git a/filament/src/ds/ShadowMapDescriptorSet.cpp b/filament/src/ds/ShadowMapDescriptorSet.cpp index 9d139af49f..2e8ff6fa10 100644 --- a/filament/src/ds/ShadowMapDescriptorSet.cpp +++ b/filament/src/ds/ShadowMapDescriptorSet.cpp @@ -22,16 +22,15 @@ #include "details/Engine.h" #include -#include #include #include #include -#include +#include -#include +#include namespace filament { @@ -85,6 +84,11 @@ void ShadowMapDescriptorSet::prepareTime(Transaction const& transaction, PerViewDescriptorSetUtils::prepareTime(edit(transaction), engine, userTime); } +void ShadowMapDescriptorSet::prepareMaterialGlobals(Transaction const& transaction, + std::array const& materialGlobals) noexcept { + PerViewDescriptorSetUtils::prepareMaterialGlobals(edit(transaction), materialGlobals); +} + void ShadowMapDescriptorSet::prepareShadowMapping(Transaction const& transaction, bool const highPrecision) noexcept { auto& s = edit(transaction); diff --git a/filament/src/ds/ShadowMapDescriptorSet.h b/filament/src/ds/ShadowMapDescriptorSet.h index 2139bfb057..9537aa9ce2 100644 --- a/filament/src/ds/ShadowMapDescriptorSet.h +++ b/filament/src/ds/ShadowMapDescriptorSet.h @@ -29,6 +29,8 @@ #include +#include + namespace filament { struct CameraInfo; @@ -69,7 +71,8 @@ public: static void prepareTime(Transaction const& transaction, FEngine const& engine, math::float4 const& userTime) noexcept; - // FIXME: I think this misses prepareMaterialGlobals() + static void prepareMaterialGlobals(Transaction const& transaction, + std::array const& materialGlobals) noexcept; static void prepareShadowMapping(Transaction const& transaction, bool highPrecision) noexcept;