Skip to content

Commit

Permalink
Address the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
show50726 authored and pixelflinger committed Oct 17, 2024
1 parent 23d1329 commit a5e6df1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion filament/src/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,15 @@ 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();

// 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;
Expand Down
33 changes: 21 additions & 12 deletions filament/src/details/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrameGraphTexture> depth;
FrameGraphId<FrameGraphTexture> picking;
};
auto& pickingRenderPass = fg.addPass<PickingRenderPassData>("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);
Expand Down Expand Up @@ -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);
});
}

Expand Down
6 changes: 3 additions & 3 deletions filament/src/details/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a5e6df1

Please sign in to comment.