Skip to content

Commit

Permalink
First push
Browse files Browse the repository at this point in the history
Fix the texture format

Decide texture format based on feature level
  • Loading branch information
show50726 authored and pixelflinger committed Oct 17, 2024
1 parent 68265ae commit 25b37d3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
3 changes: 2 additions & 1 deletion filament/src/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
54 changes: 50 additions & 4 deletions filament/src/details/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
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<FrameGraphTexture> picking;
};
Expand All @@ -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);
});
}

Expand Down
4 changes: 4 additions & 0 deletions filament/src/details/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -531,6 +534,7 @@ class FView : public View {
Viewport mViewport;
bool mCulling = true;
bool mFrontFaceWindingInverted = false;
bool mIsTransparentPickable = true;

FRenderTarget* mRenderTarget = nullptr;

Expand Down

0 comments on commit 25b37d3

Please sign in to comment.