per-material globals weren't set when generating shadow maps

This commit is contained in:
Mathias Agopian
2025-07-22 16:53:42 -07:00
committed by Mathias Agopian
parent 5850a7eee4
commit 4d8f92f087
9 changed files with 52 additions and 32 deletions
+5
View File
@@ -1381,6 +1381,11 @@ void ShadowMap::prepareTime(Transaction const& transaction,
ShadowMapDescriptorSet::prepareTime(transaction, engine, userTime);
}
void ShadowMap::prepareMaterialGlobals(Transaction const& transaction,
std::array<float4, 4> const& materialGlobals) noexcept {
ShadowMapDescriptorSet::prepareMaterialGlobals(transaction, materialGlobals);
}
void ShadowMap::prepareShadowMapping(Transaction const& transaction,
bool const highPrecision) noexcept {
ShadowMapDescriptorSet::prepareShadowMapping(transaction, highPrecision);
+4 -5
View File
@@ -33,9 +33,6 @@
#include <utils/compiler.h>
#include <math/mathfwd.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/mat4.h>
#include <array>
@@ -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<math::float4, 4> 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
+1
View File
@@ -388,6 +388,7 @@ FrameGraphId<FrameGraphTexture> 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);
+21 -2
View File
@@ -244,6 +244,23 @@ void FRenderer::setVsyncTime(uint64_t const steadyClockTimeNano) noexcept {
mVsyncSteadyClockTimeNano = steadyClockTimeNano;
}
std::pair<float, float2> 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);
+4
View File
@@ -189,6 +189,10 @@ private:
void renderInternal(FView const* view);
void renderJob(RootArenaScope& rootArenaScope, FView& view);
std::pair<float, math::float2> prepareUpscaler(math::float2 scale,
TemporalAntiAliasingOptions const& taaOptions,
DynamicResolutionOptions const& dsrOptions);
// keep a reference to our engine
FEngine& mEngine;
FrameSkipper mFrameSkipper;
+4 -18
View File
@@ -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 {
+2 -3
View File
@@ -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;
+7 -3
View File
@@ -22,16 +22,15 @@
#include "details/Engine.h"
#include <private/filament/EngineEnums.h>
#include <private/filament/DescriptorSets.h>
#include <private/filament/UibStructs.h>
#include <backend/DriverEnums.h>
#include <utils/debug.h>
#include <math/mat4.h>
#include <math/vec4.h>
#include <stdint.h>
#include <array>
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<float4, 4> const& materialGlobals) noexcept {
PerViewDescriptorSetUtils::prepareMaterialGlobals(edit(transaction), materialGlobals);
}
void ShadowMapDescriptorSet::prepareShadowMapping(Transaction const& transaction,
bool const highPrecision) noexcept {
auto& s = edit(transaction);
+4 -1
View File
@@ -29,6 +29,8 @@
#include <math/vec4.h>
#include <array>
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<math::float4, 4> const& materialGlobals) noexcept;
static void prepareShadowMapping(Transaction const& transaction,
bool highPrecision) noexcept;