From a5e6df1ad39a6e466cd96dd253f01885e234904a Mon Sep 17 00:00:00 2001 From: show50726 Date: Fri, 11 Oct 2024 22:11:55 +0800 Subject: [PATCH] Address the comments --- filament/src/RenderPass.cpp | 3 ++- filament/src/details/Renderer.cpp | 33 ++++++++++++++++++++----------- filament/src/details/View.h | 6 +++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/filament/src/RenderPass.cpp b/filament/src/RenderPass.cpp index 7072e78e080..2df6a88c67a 100644 --- a/filament/src/RenderPass.cpp +++ b/filament/src/RenderPass.cpp @@ -817,6 +817,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(RenderPass::CommandTypeFla const BlendingMode blendingMode = ma->getBlendingMode(); const bool translucent = (blendingMode != BlendingMode::OPAQUE && blendingMode != BlendingMode::MASKED); + const bool isPickingVariant = Variant::isPickingVariant(variant); cmd.key |= mi->getSortingKey(); // already all set-up for direct or'ing cmd.info.rasterState.culling = mi->getCullingMode(); @@ -824,7 +825,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(RenderPass::CommandTypeFla // FIXME: should writeDepthForShadowCasters take precedence over mi->getDepthWrite()? cmd.info.rasterState.depthWrite = (1 // only keep bit 0 & (mi->isDepthWriteEnabled() | (mode == TransparencyMode::TWO_PASSES_ONE_SIDE) - | Variant::isPickingVariant(variant)) + | isPickingVariant) & !(filterTranslucentObjects & translucent) & !(depthFilterAlphaMaskedObjects & rs.alphaToCoverage)) | writeDepthForShadowCasters; diff --git a/filament/src/details/Renderer.cpp b/filament/src/details/Renderer.cpp index f106aa9c7c6..9ebad01c7b4 100644 --- a/filament/src/details/Renderer.cpp +++ b/filament/src/details/Renderer.cpp @@ -962,35 +962,47 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { // -------------------------------------------------------------------------------------------- // structure pass -- automatically culled if not used // Currently it consists of a simple depth pass. - // This is normally used by SSAO and contact-shadows + // This is normally used by SSAO and contact-shadows. + // Also, picking is handled here if transparent picking is disabled. // TODO: the scaling should depends on all passes that need the structure pass const auto [structure, picking_] = ppm.structure(fg, passBuilder, renderFlags, svp.width, svp.height, { .scale = aoOptions.resolution, - .picking = view.hasPicking() && !view.isTransparentPickable() + .picking = view.hasPicking() && !view.isTransparentPickingEnabled() }); auto picking = picking_; + // -------------------------------------------------------------------------------------------- + // Picking pass -- automatically culled if not used + // Picking is handled here if transparent picking is enabled. + if (view.hasPicking()) { - if (view.isTransparentPickable()) { + if (view.isTransparentPickingEnabled()) { struct PickingRenderPassData { FrameGraphId depth; FrameGraphId picking; }; auto& pickingRenderPass = fg.addPass("Picking Render Pass", [&](FrameGraph::Builder& builder, auto& data) { - bool const isES2 = mEngine.getDriverApi().getFeatureLevel() == FeatureLevel::FEATURE_LEVEL_0; + bool const isFL0 = mEngine.getDriverApi().getFeatureLevel() == + FeatureLevel::FEATURE_LEVEL_0; + + // TODO: Specify the precision for picking pass + uint32_t const width = std::max(32u, + (uint32_t)std::ceil(float(svp.width) * aoOptions.resolution)); + uint32_t const height = std::max(32u, + (uint32_t)std::ceil(float(svp.height) * aoOptions.resolution)); data.depth = builder.createTexture("Depth Buffer", { - .width = svp.width, .height = svp.height, - .format = isES2 ? TextureFormat::DEPTH24 : TextureFormat::DEPTH32F }); + .width = width, .height = height, + .format = isFL0 ? TextureFormat::DEPTH24 : 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 = isES2 ? TextureFormat::RGBA8 : TextureFormat::RG32F }); + .width = width, .height = height, + .format = isFL0 ? TextureFormat::RGBA8 : TextureFormat::RG32F }); data.picking = builder.write(data.picking, FrameGraphTexture::Usage::COLOR_ATTACHMENT); @@ -1035,10 +1047,7 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { [=, &view](FrameGraphResources const& resources, auto const&, DriverApi& driver) mutable { auto out = resources.getRenderPassInfo(); - auto finalScale = view.isTransparentPickable() - ? scale - : scale * aoOptions.resolution; - view.executePickingQueries(driver, out.target, finalScale); + view.executePickingQueries(driver, out.target, scale * aoOptions.resolution); }); } diff --git a/filament/src/details/View.h b/filament/src/details/View.h index 4716764baac..ff61732a68e 100644 --- a/filament/src/details/View.h +++ b/filament/src/details/View.h @@ -133,8 +133,8 @@ class FView : public View { void setFrontFaceWindingInverted(bool inverted) noexcept { mFrontFaceWindingInverted = inverted; } bool isFrontFaceWindingInverted() const noexcept { return mFrontFaceWindingInverted; } - void setIsTransparentPickable(bool pickable) noexcept { mIsTransparentPickable = pickable; } - bool isTransparentPickable() const noexcept { return mIsTransparentPickable; } + void setTransparentPickingEnabled(bool enabled) noexcept { mIsTransparentPickingEnabled = enabled; } + bool isTransparentPickingEnabled() const noexcept { return mIsTransparentPickingEnabled; } void setVisibleLayers(uint8_t select, uint8_t values) noexcept; @@ -534,7 +534,7 @@ class FView : public View { Viewport mViewport; bool mCulling = true; bool mFrontFaceWindingInverted = false; - bool mIsTransparentPickable = false; + bool mIsTransparentPickingEnabled = true; FRenderTarget* mRenderTarget = nullptr;