Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick transparent renderables #6633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph
// It consists of a mipmapped depth pass, tuned for SSAO
struct StructurePassData {
FrameGraphId<FrameGraphTexture> depth;
FrameGraphId<FrameGraphTexture> picking;
};

// sanitize a bit the user provided scaling factor
Expand All @@ -377,24 +376,14 @@ PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph
data.depth = builder.write(data.depth,
FrameGraphTexture::Usage::DEPTH_ATTACHMENT | FrameGraphTexture::Usage::SAMPLEABLE);

if (config.picking) {
data.picking = builder.createTexture("Picking Buffer", {
.width = width, .height = height,
.format = TextureFormat::RG32UI });

data.picking = builder.write(data.picking,
FrameGraphTexture::Usage::COLOR_ATTACHMENT);
}

builder.declareRenderPass("Structure Target", {
.attachments = { .color = { data.picking }, .depth = data.depth },
.clearFlags = TargetBufferFlags::COLOR0 | TargetBufferFlags::DEPTH
.attachments = { .depth = data.depth },
.clearFlags = TargetBufferFlags::DEPTH
});
},
[=, renderPass = pass](FrameGraphResources const& resources,
auto const& data, DriverApi& driver) mutable {
Variant structureVariant(Variant::DEPTH_VARIANT);
structureVariant.setPicking(config.picking);

auto out = resources.getRenderPassInfo();
renderPass.setRenderFlags(structureRenderFlags);
Expand Down Expand Up @@ -443,7 +432,7 @@ PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph
driver.setMinMaxLevels(in, 0, levelCount - 1);
});

return { depth, structurePass->picking };
return { depth };
}

// ------------------------------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions filament/src/PostProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class PostProcessManager {

struct StructurePassConfig {
float scale = 0.5f;
bool picking{};
};

explicit PostProcessManager(FEngine& engine) noexcept;
Expand All @@ -75,7 +74,6 @@ class PostProcessManager {
// structure (depth) pass
struct StructurePassOutput {
FrameGraphId<FrameGraphTexture> structure;
FrameGraphId<FrameGraphTexture> picking;
};
StructurePassOutput structure(FrameGraph& fg,
RenderPass const& pass, uint8_t structureRenderFlags,
Expand Down
4 changes: 3 additions & 1 deletion filament/src/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,

// FIXME: should writeDepthForShadowCasters take precedence over mi->getDepthWrite()?
cmdDepth.primitive.rasterState.depthWrite = (1 // only keep bit 0
& (mi->isDepthWriteEnabled() | (mode == TransparencyMode::TWO_PASSES_ONE_SIDE))
& (mi->isDepthWriteEnabled()
|| (mode == TransparencyMode::TWO_PASSES_ONE_SIDE)
|| Variant::isPickingVariant(variant))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add a boolean material property to support excluding a material from picking?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pixelflinger can explain this in more detail but this function is in the deep inner loop of Filament and written to be branchless. You should be using long circuit operators instead of short circuit. I'm also not sure if we want to test for picking here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using long circuit operators instead of short circuit.

Then I can cast the boolean value to an integer to avoid the compilation error.

I'm also not sure if we want to test for picking here.

It is required to render the transparent objects in the picking pass.

& !(filterTranslucentObjects & translucent)
& !(depthFilterAlphaMaskedObjects & rs.alphaToCoverage))
| writeDepthForShadowCasters;
Expand Down
50 changes: 44 additions & 6 deletions filament/src/details/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,21 +795,59 @@ void FRenderer::renderJob(ArenaScope& arena, FView& view) {
// This is normally used by SSAO and contact-shadows

// TODO: the scaling should depends on all passes that need the structure pass
const auto [structure, picking_] = ppm.structure(fg, pass, renderFlags, svp.width, svp.height, {
.scale = aoOptions.resolution,
.picking = view.hasPicking()
const auto [structure] = ppm.structure(fg, pass, renderFlags, svp.width, svp.height, {
.scale = aoOptions.resolution
});
blackboard["structure"] = structure;
const auto picking = picking_;


if (view.hasPicking()) {
struct PickingRenderPassData {
FrameGraphId<FrameGraphTexture> depth;
FrameGraphId<FrameGraphTexture> picking;
};
auto& pickingRenderPass = fg.addPass<PickingRenderPassData>("Picking Render Pass",
[&](FrameGraph::Builder& builder, auto& data) {
data.depth = builder.createTexture("Depth Buffer", {
.width = svp.width, .height = svp.height,
.format = TextureFormat::DEPTH32F});

data.depth = builder.write(data.depth,
FrameGraphTexture::Usage::DEPTH_ATTACHMENT);

data.picking = builder.createTexture("Picking Buffer", {
.width = svp.width, .height = svp.height,
.format = TextureFormat::RG32UI});

data.picking = builder.write(data.picking,
FrameGraphTexture::Usage::COLOR_ATTACHMENT);

builder.declareRenderPass("Picking Render Target", {
.attachments = { .color = { data.picking }, .depth = data.depth },
.clearFlags = TargetBufferFlags::COLOR0 | TargetBufferFlags::DEPTH
});
},
[=, renderPass = pass](FrameGraphResources const& resources,
auto const& data, DriverApi& driver) mutable {
Variant pickingVariant(Variant::DEPTH_VARIANT);
pickingVariant.setPicking(true);

auto out = resources.getRenderPassInfo();
renderPass.setRenderFlags(renderFlags);
renderPass.setVariant(pickingVariant);
renderPass.appendCommands(mEngine,
RenderPass::CommandTypeFlags::DEPTH);
renderPass.sortCommands(mEngine);
renderPass.execute(mEngine, resources.getPassName(),
out.target, out.params);
});

struct PickingResolvePassData {
FrameGraphId<FrameGraphTexture> picking;
};
fg.addPass<PickingResolvePassData>("Picking Resolve Pass",
[&](FrameGraph::Builder& builder, auto& data) {
data.picking = builder.read(picking,
data.picking = builder.read(pickingRenderPass->picking,
FrameGraphTexture::Usage::COLOR_ATTACHMENT);
builder.declareRenderPass("Picking Resolve Target", {
.attachments = { .color = { data.picking }}
Expand All @@ -819,7 +857,7 @@ void FRenderer::renderJob(ArenaScope& arena, FView& view) {
[=, &view](FrameGraphResources const& resources,
auto const&, DriverApi& driver) mutable {
auto out = resources.getRenderPassInfo();
view.executePickingQueries(driver, out.target, aoOptions.resolution);
view.executePickingQueries(driver, out.target);
});
}

Expand Down
8 changes: 4 additions & 4 deletions filament/src/details/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,15 @@ void FView::drainFrameHistory(FEngine& engine) noexcept {
}

void FView::executePickingQueries(backend::DriverApi& driver,
backend::RenderTargetHandle handle, float scale) noexcept {
backend::RenderTargetHandle handle) noexcept {

while (mActivePickingQueriesList) {
FPickingQuery* const pQuery = mActivePickingQueriesList;
mActivePickingQueriesList = pQuery->next;

// adjust for dynamic resolution and structure buffer scale
const uint32_t x = uint32_t(float(pQuery->x) * (scale * mScale.x));
const uint32_t y = uint32_t(float(pQuery->y) * (scale * mScale.y));
// adjust for dynamic resolution scale
const uint32_t x = uint32_t(float(pQuery->x) * mScale.x);
const uint32_t y = uint32_t(float(pQuery->y) * mScale.y);
driver.readPixels(handle, x, y, 1, 1, {
&pQuery->result.renderable, 4*4, // 4*uint
// FIXME: RGBA_INTEGER is guaranteed to work. R_INTEGER must be queried.
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class FView : public View {
View::PickingQueryResultCallback callback) noexcept;

void executePickingQueries(backend::DriverApi& driver,
backend::RenderTargetHandle handle, float scale) noexcept;
backend::RenderTargetHandle handle) noexcept;

private:

Expand Down