diff --git a/src/render/rt64_raster_shader.cpp b/src/render/rt64_raster_shader.cpp index 7f255e1..7d08fcb 100644 --- a/src/render/rt64_raster_shader.cpp +++ b/src/render/rt64_raster_shader.cpp @@ -42,7 +42,7 @@ namespace RT64 { this->device = device; this->desc = desc; - + const bool useMSAA = (multisampling.sampleCount > 1); std::unique_ptr vertexShader; std::unique_ptr pixelShader; @@ -53,7 +53,7 @@ namespace RT64 { const void *PSBlob = nullptr; uint32_t VSBlobSize = 0; uint32_t PSBlobSize = 0; - const bool outputDepth = desc.outputDepth(); + const bool outputDepth = desc.outputDepth(useMSAA); if (desc.flags.smoothShade) { VSBlob = RasterVSSpecConstantBlobSPIRV; VSBlobSize = uint32_t(std::size(RasterVSSpecConstantBlobSPIRV)); @@ -214,11 +214,11 @@ namespace RT64 { ", [[vk::location(0)]] [[vk::index(0)]] out float4 resultColor : SV_TARGET0" ", [[vk::location(0)]] [[vk::index(1)]] out float4 resultAlpha : SV_TARGET1"; - if (desc.outputDepth()) { + if (desc.outputDepth(multisampling)) { pss << ", out float resultDepth : SV_DEPTH"; } - if (desc.outputDepth()) { + if (desc.outputDepth(multisampling)) { pss << ") { bool outputDepth = true;"; } else { diff --git a/src/render/rt64_shader_common.cpp b/src/render/rt64_shader_common.cpp index cc8ecb6..83b72eb 100644 --- a/src/render/rt64_shader_common.cpp +++ b/src/render/rt64_shader_common.cpp @@ -32,11 +32,14 @@ namespace RT64 { return ss.str(); } - bool ShaderDescription::outputDepth() const { + bool ShaderDescription::outputDepth(bool useMSAA) const { bool copyMode = (otherMode.cycleType() == G_CYC_COPY); bool depthClampNear = flags.NoN; bool depthDecal = (otherMode.zMode() == ZMODE_DEC); bool zSourcePrim = (otherMode.zSource() == G_ZS_PRIM); - return !copyMode && (depthClampNear || depthDecal || zSourcePrim); + + // FIXME: Depth output is forced when using multisampling to avoid problems from interactions when sampling the depth buffer directly on decals. + // The true case of this issue is still pending investigation (https://github.com/rt64/rt64/issues/24). + return !copyMode && (depthClampNear || depthDecal || zSourcePrim || useMSAA); } }; \ No newline at end of file diff --git a/src/render/rt64_shader_common.h b/src/render/rt64_shader_common.h index 4780594..9900de7 100644 --- a/src/render/rt64_shader_common.h +++ b/src/render/rt64_shader_common.h @@ -25,7 +25,7 @@ namespace RT64 { void maskUnusedParameters(); uint64_t hash() const; std::string toShader() const; - bool outputDepth() const; + bool outputDepth(bool useMSAA) const; }; #pragma pack(pop) }; \ No newline at end of file