From 903984f427a282034a40b1fb0e4c8f09cc70dbba Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Sun, 3 Mar 2024 13:00:15 -0800 Subject: [PATCH] try to fix amd deferred bug --- .../RenderableParticleEffectEntityItem.cpp | 47 ++++++++++++------- .../entities-renderer/textured_particle.slp | 2 +- .../src/textured_particle.slf | 20 +++++--- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index ff9ba9fb03..f4d729585c 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -21,35 +21,46 @@ using namespace render::entities; static uint8_t CUSTOM_PIPELINE_NUMBER = 0; static gpu::Stream::FormatPointer _vertexFormat; -static std::map, gpu::PipelinePointer> _pipelines; +static std::map, gpu::PipelinePointer> _pipelines; static ShapePipelinePointer shapePipelineFactory(const ShapePlumber& plumber, const ShapeKey& key, RenderArgs* args) { // FIXME: custom pipelines like this don't handle shadows or renderLayers correctly if (_pipelines.empty()) { - for (size_t i = 0; i < 4; i++) { - bool transparent = (i % 2 == 0); - bool wireframe = (i / 2) == 0; + using namespace shader::entities_renderer::program; - auto state = std::make_shared(); - state->setCullMode(gpu::State::CULL_BACK); + // forward, translucent + static const std::vector> keys = { + std::make_tuple(false, false, textured_particle), + std::make_tuple(true, false, textured_particle_forward), + std::make_tuple(false, true, textured_particle_translucent), + std::make_tuple(true, true, textured_particle_forward) + }; - if (wireframe) { - state->setFillMode(gpu::State::FILL_LINE); + for (auto& key : keys) { + for (int i = 0; i < 2; ++i) { + bool transparent = std::get<1>(key); + bool wireframe = i == 0; + + auto state = std::make_shared(); + state->setCullMode(gpu::State::CULL_BACK); + + if (wireframe) { + state->setFillMode(gpu::State::FILL_LINE); + } + + state->setDepthTest(true, !transparent, gpu::LESS_EQUAL); + state->setBlendFunction(transparent, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + transparent ? PrepareStencil::testMask(*state) : PrepareStencil::testMaskDrawShape(*state); + + auto program = gpu::Shader::createProgram(std::get<2>(key)); + _pipelines[std::make_tuple(std::get<0>(key), transparent, wireframe)] = gpu::Pipeline::create(program, state); } - - state->setDepthTest(true, !transparent, gpu::LESS_EQUAL); - state->setBlendFunction(transparent, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - transparent ? PrepareStencil::testMask(*state) : PrepareStencil::testMaskDrawShape(*state); - - auto program = gpu::Shader::createProgram(transparent ? shader::entities_renderer::program::textured_particle_translucent : - shader::entities_renderer::program::textured_particle); - _pipelines[std::make_tuple(transparent, wireframe)] = gpu::Pipeline::create(program, state); } } - return std::make_shared(_pipelines[std::make_tuple(key.isTranslucent(), key.isWireframe())], nullptr, nullptr, nullptr); + return std::make_shared(_pipelines[std::make_tuple(args->_renderMethod == Args::RenderMethod::FORWARD, key.isTranslucent(), key.isWireframe())], nullptr, nullptr, nullptr); } struct GpuParticle { diff --git a/libraries/entities-renderer/src/entities-renderer/textured_particle.slp b/libraries/entities-renderer/src/entities-renderer/textured_particle.slp index 1348d72a8d..e9942be5cd 100644 --- a/libraries/entities-renderer/src/entities-renderer/textured_particle.slp +++ b/libraries/entities-renderer/src/entities-renderer/textured_particle.slp @@ -1 +1 @@ -DEFINES translucent:f \ No newline at end of file +DEFINES translucent:f/forward:f \ No newline at end of file diff --git a/libraries/entities-renderer/src/textured_particle.slf b/libraries/entities-renderer/src/textured_particle.slf index 7c26e036e4..65d3b112dc 100644 --- a/libraries/entities-renderer/src/textured_particle.slf +++ b/libraries/entities-renderer/src/textured_particle.slf @@ -15,17 +15,23 @@ LAYOUT(binding=0) uniform sampler2D colorMap; layout(location=0) in vec4 varColor; layout(location=1) in vec2 varTexcoord; -layout(location=0) out vec4 outFragColor; +<@if not HIFI_USE_FORWARD@> + <@include DeferredBufferWrite.slh@> +<@else@> + layout(location=0) out vec4 _fragColor0; +<@endif@> void main(void) { vec4 albedo = texture(colorMap, varTexcoord.xy) * varColor; +<@if not HIFI_USE_FORWARD@> + vec3 NORMAL = vec3(1.0, 0.0, 0.0); <@if not HIFI_USE_TRANSLUCENT@> - // to reduce texel flickering for floating point error we discard when alpha is "almost one" - if (albedo.a < 0.999999) { - discard; - } + packDeferredFragmentUnlit(NORMAL, albedo.a, albedo.rgb); + <@else@> + packDeferredFragmentTranslucent(NORMAL, albedo.a, albedo.rgb, DEFAULT_ROUGHNESS); <@endif@> - - outFragColor = albedo; +<@else@> + _fragColor0 = albedo; +<@endif@> }