From 25b37d36ad4b8ae0135c5e6c6c64eefd98b69452 Mon Sep 17 00:00:00 2001 From: show50726 Date: Fri, 4 Oct 2024 01:27:11 +0800 Subject: [PATCH] First push Fix the texture format Decide texture format based on feature level --- filament/src/RenderPass.cpp | 3 +- filament/src/details/Renderer.cpp | 54 ++++++++++++++++++++++++++++--- filament/src/details/View.h | 4 +++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/filament/src/RenderPass.cpp b/filament/src/RenderPass.cpp index dd0dd262617..7072e78e080 100644 --- a/filament/src/RenderPass.cpp +++ b/filament/src/RenderPass.cpp @@ -823,7 +823,8 @@ 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)) + & (mi->isDepthWriteEnabled() | (mode == TransparencyMode::TWO_PASSES_ONE_SIDE) + | Variant::isPickingVariant(variant)) & !(filterTranslucentObjects & translucent) & !(depthFilterAlphaMaskedObjects & rs.alphaToCoverage)) | writeDepthForShadowCasters; diff --git a/filament/src/details/Renderer.cpp b/filament/src/details/Renderer.cpp index 494486e2a14..ea0137556e6 100644 --- a/filament/src/details/Renderer.cpp +++ b/filament/src/details/Renderer.cpp @@ -968,11 +968,54 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { const auto [structure, picking_] = ppm.structure(fg, passBuilder, renderFlags, svp.width, svp.height, { .scale = aoOptions.resolution, - .picking = view.hasPicking() + .picking = view.hasPicking() && !view.isTransparentPickable() }); - const auto picking = picking_; - + auto picking = picking_; + if (view.hasPicking()) { + if (view.isTransparentPickable()) { + 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; + data.depth = builder.createTexture("Depth Buffer", { + .width = svp.width, .height = svp.height, + .format = isES2 ? 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 }); + + 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 + }); + }, + [=, passBuilder = passBuilder](FrameGraphResources const& resources, + auto const& data, DriverApi& driver) mutable { + Variant pickingVariant(Variant::DEPTH_VARIANT); + pickingVariant.setPicking(true); + + auto out = resources.getRenderPassInfo(); + passBuilder.renderFlags(renderFlags); + passBuilder.variant(pickingVariant); + passBuilder.commandTypeFlags(RenderPass::CommandTypeFlags::DEPTH); + + RenderPass const pass{ passBuilder.build(mEngine) }; + RenderPass::execute(pass, mEngine, resources.getPassName(), out.target, out.params); + }); + picking = pickingRenderPass->picking; + } + struct PickingResolvePassData { FrameGraphId picking; }; @@ -992,7 +1035,10 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) { [=, &view](FrameGraphResources const& resources, auto const&, DriverApi& driver) mutable { auto out = resources.getRenderPassInfo(); - view.executePickingQueries(driver, out.target, scale * aoOptions.resolution); + auto finalScale = view.isTransparentPickable() + ? scale + : scale * aoOptions.resolution; + view.executePickingQueries(driver, out.target, finalScale); }); } diff --git a/filament/src/details/View.h b/filament/src/details/View.h index 4f548ded94a..5978ba8bcda 100644 --- a/filament/src/details/View.h +++ b/filament/src/details/View.h @@ -133,6 +133,9 @@ 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 setVisibleLayers(uint8_t select, uint8_t values) noexcept; uint8_t getVisibleLayers() const noexcept { @@ -531,6 +534,7 @@ class FView : public View { Viewport mViewport; bool mCulling = true; bool mFrontFaceWindingInverted = false; + bool mIsTransparentPickable = true; FRenderTarget* mRenderTarget = nullptr;