Skip to content

Commit

Permalink
GBufferRaster improvements (#275)
Browse files Browse the repository at this point in the history
* GBufferRaster: Properly clear the v-buffer

Invalid items (such as when no geometry was found under a pixel) are
identified by checking whether the first component is `UINT_MAX`.

However since the buffer was cleared to 0, it would always report some
geometry even when there was none, causing passes like the
`MegakernelPathTracer` to hallucinate details when looking in the void.

* GBufferRaster: Export viewW, similar to GBufferRT
  • Loading branch information
pierremoreau authored Oct 5, 2021
1 parent 268df89 commit e85ebad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Source/RenderPasses/GBuffer/GBuffer/GBufferRaster.3d.slang
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ RasterizerOrderedTexture2D<float2> gMotionVectors;
RasterizerOrderedTexture2D<float4> gRoughness;
RasterizerOrderedTexture2D<float4> gMetallic;
RasterizerOrderedTexture2D<float4> gFaceNormalW;
RasterizerOrderedTexture2D<float4> gViewW;
RasterizerOrderedTexture2D<float2> gPosNormalFwidth;
RasterizerOrderedTexture2D<float2> gLinearZAndDeriv;

Expand Down Expand Up @@ -105,6 +106,11 @@ GBufferPSOut psMain(VSOut vsOut, uint triangleIndex : SV_PrimitiveID, float3 bar
gFaceNormalW[ipos] = float4(sd.faceN, 0);
}

if (isValid(gViewW))
{
gViewW[ipos] = float4(sd.V, 0);
}

// Compute motion vectors.
if (is_valid(gMotionVectors))
{
Expand Down
8 changes: 7 additions & 1 deletion Source/RenderPasses/GBuffer/GBuffer/GBufferRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "RenderGraph/RenderPassStandardFlags.h"
#include "GBufferRaster.h"

#include <limits>

const char* GBufferRaster::kDesc = "Rasterized G-buffer generation pass";

namespace
Expand All @@ -47,6 +49,7 @@ namespace
{ "roughness", "gRoughness", "Roughness", true /* optional */, ResourceFormat::RGBA8Unorm },
{ "metallic", "gMetallic", "Metallic", true /* optional */, ResourceFormat::RGBA8Unorm },
{ "faceNormalW", "gFaceNormalW", "Face normal in world space", true /* optional */, ResourceFormat::RGBA32Float },
{ "viewW", "gViewW", "View direction in world space", true /* optional */, ResourceFormat::RGBA32Float }, // TODO: Switch to packed 2x16-bit snorm format.
{ "pnFwidth", "gPosNormalFwidth", "position and normal filter width", true /* optional */, ResourceFormat::RG32Float },
{ "linearZ", "gLinearZAndDeriv", "linear z (and derivative)", true /* optional */, ResourceFormat::RG32Float },
};
Expand Down Expand Up @@ -156,7 +159,10 @@ void GBufferRaster::execute(RenderContext* pRenderContext, const RenderData& ren
auto clear = [&](const ChannelDesc& channel)
{
auto pTex = renderData[channel.name]->asTexture();
if (pTex) pRenderContext->clearUAV(pTex->getUAV().get(), float4(0.f));
if (pTex) {
if (channel.name == kVBufferName) pRenderContext->clearUAV(pTex->getUAV().get(), uint4(std::numeric_limits<uint32_t>::max()));
else pRenderContext->clearUAV(pTex->getUAV().get(), float4(0.f));
}
};
for (const auto& channel : kGBufferExtraChannels) clear(channel);

Expand Down

0 comments on commit e85ebad

Please sign in to comment.