From 90799e10da2ff09add13c9cc3f9e4d91713b1750 Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Sun, 3 Jan 2021 16:31:51 -0500 Subject: [PATCH 1/4] Fix z-write enabled for transparent draws. Fix z-write being enabled for transparencies in GeometryCache::getSimplePipeline and Procedural::Procedural (fixes https://github.com/vircadia/vircadia/issues/224). Z-write is controlled by the 'writeMask' parameter of gpu::State::setDepthTest. --- libraries/procedural/src/procedural/Procedural.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 88c111f8fd..66dde1ca56 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -125,7 +125,7 @@ Procedural::Procedural() { opaqueStencil(_opaqueState); _transparentState->setCullMode(gpu::State::CULL_NONE); - _transparentState->setDepthTest(true, true, gpu::LESS_EQUAL); + _transparentState->setDepthTest(true, false, gpu::LESS_EQUAL); _transparentState->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index ea66ac19ec..68daba92e3 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2207,7 +2207,7 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp } else { state->setCullMode(gpu::State::CULL_BACK); } - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, !config.isTransparent(), gpu::LESS_EQUAL); if (config.hasDepthBias()) { state->setDepthBias(1.0f); state->setDepthBiasSlopeScale(1.0f); From 4f71cb594538901eaeb27fc55773c6a979c41ac4 Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Sun, 3 Jan 2021 22:59:31 -0500 Subject: [PATCH 2/4] Disable z-write when drawing web entities with alpha < 1. --- libraries/render-utils/src/GeometryCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 68daba92e3..8a483a0352 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2135,7 +2135,7 @@ gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool auto pipeline = (transparent || forward) ? web_browser_forward : web_browser; gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, !transparent, gpu::LESS_EQUAL); // FIXME: do we need a testMaskDrawNoAA? PrepareStencil::testMaskDrawShapeNoAA(*state); state->setBlendFunction(transparent, From 12095fed96eff31ade799f75863f34e996cd9d8b Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Tue, 5 Jan 2021 00:05:11 -0500 Subject: [PATCH 3/4] Disable z-write for fonts, grid entities and teleport beams as suggested in the review here: https://github.com/vircadia/vircadia/pull/953#pullrequestreview-560779456 --- interface/src/raypick/ParabolaPointer.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 2 +- libraries/render-utils/src/text/Font.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index 216248f8b5..f9babcd999 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -415,7 +415,7 @@ gpu::PipelinePointer ParabolaPointer::RenderState::ParabolaRenderItem::getParabo for (auto& key : keys) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, false, gpu::LESS_EQUAL); if (std::get<0>(key)) { PrepareStencil::testMask(*state); } else { diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8a483a0352..e5c6178a83 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2027,7 +2027,7 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo for (auto& key : keys) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, false, gpu::LESS_EQUAL); if (std::get<0>(key)) { PrepareStencil::testMask(*state); } else { diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index a30bbad0e5..e0b3a020fe 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -276,7 +276,7 @@ void Font::setupGPU() { for (auto& key : keys) { auto state = std::make_shared(); state->setCullMode(gpu::State::CULL_BACK); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setBlendFunction(std::get<0>(key), gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); From 1cdc3610c3a41a89681545202a84fa714a8bac8e Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Tue, 5 Jan 2021 00:05:11 -0500 Subject: [PATCH 4/4] Disable z-write for transparent fonts, grid entities and teleport beams as suggested in the review here: https://github.com/vircadia/vircadia/pull/953#pullrequestreview-560779456 --- interface/src/raypick/ParabolaPointer.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 2 +- libraries/render-utils/src/text/Font.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index 216248f8b5..2915793c40 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -415,7 +415,7 @@ gpu::PipelinePointer ParabolaPointer::RenderState::ParabolaRenderItem::getParabo for (auto& key : keys) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, !std::get<0>(key), gpu::LESS_EQUAL); if (std::get<0>(key)) { PrepareStencil::testMask(*state); } else { diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8a483a0352..325e228120 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2027,7 +2027,7 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo for (auto& key : keys) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, !std::get<0>(key), gpu::LESS_EQUAL); if (std::get<0>(key)) { PrepareStencil::testMask(*state); } else { diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index a30bbad0e5..425e4f2da5 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -276,7 +276,7 @@ void Font::setupGPU() { for (auto& key : keys) { auto state = std::make_shared(); state->setCullMode(gpu::State::CULL_BACK); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(true, !std::get<0>(key), gpu::LESS_EQUAL); state->setBlendFunction(std::get<0>(key), gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);