Skip to content

Commit

Permalink
disable user scissor while rendering the shadowmaps
Browse files Browse the repository at this point in the history
fixes #5607
  • Loading branch information
pixelflinger committed Jun 2, 2022
1 parent 211cf2b commit 6fb661f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
28 changes: 21 additions & 7 deletions filament/src/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ void RenderPass::setCamera(const CameraInfo& camera) noexcept {
mCameraForwardVector = camera.getForwardVector();
}

void RenderPass::overridePolygonOffset(backend::PolygonOffset* polygonOffset) noexcept {
void RenderPass::overridePolygonOffset(backend::PolygonOffset const* polygonOffset) noexcept {
if ((mPolygonOffsetOverride = (polygonOffset != nullptr))) {
mPolygonOffset = *polygonOffset;
}
}

void RenderPass::overrideScissor(backend::Viewport const* scissor) noexcept {
if ((mScissorOverride = (scissor != nullptr))) {
mScissor = *scissor;
}
}

void RenderPass::appendCommands(CommandTypeFlags const commandTypeFlags) noexcept {
SYSTRACE_CONTEXT();

Expand Down Expand Up @@ -580,10 +586,16 @@ void RenderPass::Executor::recordDriverCommands(FEngine& engine, backend::Driver
if (first != last) {
SYSTRACE_VALUE32("commandCount", last - first);

PolygonOffset dummyPolyOffset;
PipelineState pipeline{ .polygonOffset = mPolygonOffset };
PolygonOffset* const pPipelinePolygonOffset =
mPolygonOffsetOverride ? &dummyPolyOffset : &pipeline.polygonOffset;
PipelineState pipeline{
.polygonOffset = mPolygonOffset,
.scissor = mScissor
}, dummyPipeline;

auto* const pPipelinePolygonOffset =
mPolygonOffsetOverride ? &dummyPipeline.polygonOffset : &pipeline.polygonOffset;

auto* const pScissor =
mScissorOverride ? &dummyPipeline.scissor : &pipeline.scissor;

Handle<HwBufferObject> uboHandle = mUboHandle;
FMaterialInstance const* UTILS_RESTRICT mi = nullptr;
Expand Down Expand Up @@ -616,7 +628,7 @@ void RenderPass::Executor::recordDriverCommands(FEngine& engine, backend::Driver
// this is always taken the first time
mi = info.mi;
ma = mi->getMaterial();
pipeline.scissor = mi->getScissor();
*pScissor = mi->getScissor();
*pPipelinePolygonOffset = mi->getPolygonOffset();
mi->use(driver);
}
Expand Down Expand Up @@ -657,7 +669,9 @@ RenderPass::Executor::Executor(RenderPass const* pass, Command const* b, Command
: mEngine(pass->mEngine), mBegin(b), mEnd(e),
mCustomCommands(pass->mCustomCommands), mUboHandle(pass->mUboHandle),
mPolygonOffset(pass->mPolygonOffset),
mPolygonOffsetOverride(pass->mPolygonOffsetOverride) {
mScissor(pass->mScissor),
mPolygonOffsetOverride(pass->mPolygonOffsetOverride),
mScissorOverride(pass->mScissorOverride) {
assert_invariant(b >= pass->begin());
assert_invariant(e <= pass->end());
}
Expand Down
15 changes: 13 additions & 2 deletions filament/src/RenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ class RenderPass {
~RenderPass() noexcept;

// if non-null, overrides the material's polygon offset
void overridePolygonOffset(backend::PolygonOffset* polygonOffset) noexcept;
void overridePolygonOffset(backend::PolygonOffset const* polygonOffset) noexcept;

// if non-null, overrides the material's scissor
void overrideScissor(backend::Viewport const* scissor) noexcept;

// specifies the geometry to generate commands for
void setGeometry(FScene::RenderableSoa const& soa, utils::Range<uint32_t> vr,
Expand Down Expand Up @@ -330,7 +333,9 @@ class RenderPass {
const CustomCommandVector mCustomCommands;
const backend::Handle<backend::HwBufferObject> mUboHandle;
const backend::PolygonOffset mPolygonOffset;
const bool mPolygonOffsetOverride;
const backend::Viewport mScissor;
const bool mPolygonOffsetOverride : 1;
const bool mScissorOverride : 1;

Executor(RenderPass const* pass, Command const* b, Command const* e) noexcept;

Expand Down Expand Up @@ -430,9 +435,15 @@ class RenderPass {
// whether to override the polygon offset setting
bool mPolygonOffsetOverride = false;

// whether to override the polygon offset setting
bool mScissorOverride = false;

// value of the override
backend::PolygonOffset mPolygonOffset{};

// value of scissor override
backend::Viewport mScissor{};

// a vector for our custom commands
mutable Executor::CustomCommandVector mCustomCommands;
};
Expand Down
4 changes: 4 additions & 0 deletions filament/src/ShadowMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ ShadowMap::~ShadowMap() {

void ShadowMap::render(FScene const& scene, utils::Range<uint32_t> range,
FScene::VisibleMaskType visibilityMask, RenderPass* const pass) noexcept {
const backend::Viewport disabledScissor{ 0, 0,
(uint32_t)std::numeric_limits<int32_t>::max(),
(uint32_t)std::numeric_limits<int32_t>::max() };
pass->setVisibilityMask(visibilityMask);
pass->setGeometry(scene.getRenderableData(), range, scene.getRenderableUBO());
pass->overridePolygonOffset(&mShadowMapInfo.polygonOffset);
pass->overrideScissor(&disabledScissor);
pass->appendCommands(RenderPass::SHADOW);
pass->sortCommands();
}
Expand Down

0 comments on commit 6fb661f

Please sign in to comment.