From 89f18aee3b54661075204d238e2da5136a4e4c30 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 18 May 2016 13:14:42 -0700 Subject: [PATCH 1/2] Simplifying the deferredbuffer clear and enableing z test for lighting pass --- .../src/DeferredLightingEffect.cpp | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 1d9ce65581..fd7826070d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -149,17 +149,12 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { batch.setFramebuffer(deferredFbo); - // Clear Color, Depth and Stencil + // Clear Color, Depth and Stencil for deferred buffer batch.clearFramebuffer( - gpu::Framebuffer::BUFFER_COLOR0 | + gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR1 | gpu::Framebuffer::BUFFER_COLOR2 | gpu::Framebuffer::BUFFER_DEPTH | gpu::Framebuffer::BUFFER_STENCIL, - vec4(vec3(0), 1), 1.0, 0.0, true); - - // clear the normal and specular buffers - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR1, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true); - const float MAX_SPECULAR_EXPONENT = 128.0f; - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR2, glm::vec4(0.0f, 0.0f, 0.0f, 1.0f / MAX_SPECULAR_EXPONENT), true); + vec4(vec3(0), 0), 1.0, 0.0, true); }); } @@ -469,9 +464,15 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo batch.setInputBuffer(0, mesh->getVertexBuffer()); batch.setInputFormat(mesh->getVertexFormat()); - auto& part = mesh->getPartBuffer().get(); - - batch.drawIndexed(model::Mesh::topologyToPrimitive(part._topology), part._numIndices, part._startIndex); + { + auto& part = mesh->getPartBuffer().get(0); + batch.drawIndexed(model::Mesh::topologyToPrimitive(part._topology), part._numIndices, part._startIndex); + } + // keep for debug + /* { + auto& part = mesh->getPartBuffer().get(1); + batch.drawIndexed(model::Mesh::topologyToPrimitive(part._topology), part._numIndices, part._startIndex); + }*/ } } } @@ -548,14 +549,13 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo // Stencil test all the light passes for objects pixels only, not the background state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - + if (lightVolume) { state->setCullMode(gpu::State::CULL_BACK); - - // No need for z test since the depth buffer is not bound state->setDepthTest(true, false, gpu::LESS_EQUAL); - // TODO: We should bind the true depth buffer both as RT and texture for the depth test + state->setDepthTest(true, false, gpu::LESS_EQUAL); + // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases - state->setDepthClampEnable(true); + //state->setDepthClampEnable(true); // additive blending state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); @@ -662,10 +662,14 @@ model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { _spotLightMesh->setIndexBuffer(gpu::BufferView(new gpu::Buffer(sizeof(unsigned short) * indices, (gpu::Byte*) indexData), gpu::Element::INDEX_UINT16)); delete[] indexData; - model::Mesh::Part part(0, indices, 0, model::Mesh::TRIANGLES); - //DEBUG: model::Mesh::Part part(0, indices, 0, model::Mesh::LINE_STRIP); - _spotLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(sizeof(part), (gpu::Byte*) &part), gpu::Element::PART_DRAWCALL)); + std::vector parts; + parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::TRIANGLES)); + //DEBUG: + parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::LINE_STRIP)); + + + _spotLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(model::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); } return _spotLightMesh; } From 2d7118dacc87260faca4f232727823ca7b8985d2 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 19 May 2016 10:21:00 -0700 Subject: [PATCH 2/2] clening up the code --- libraries/render-utils/src/DeferredLightingEffect.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index fd7826070d..0a562de3ba 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -468,11 +468,6 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo auto& part = mesh->getPartBuffer().get(0); batch.drawIndexed(model::Mesh::topologyToPrimitive(part._topology), part._numIndices, part._startIndex); } - // keep for debug - /* { - auto& part = mesh->getPartBuffer().get(1); - batch.drawIndexed(model::Mesh::topologyToPrimitive(part._topology), part._numIndices, part._startIndex); - }*/ } } } @@ -555,7 +550,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo state->setDepthTest(true, false, gpu::LESS_EQUAL); // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases - //state->setDepthClampEnable(true); // additive blending state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); @@ -665,8 +659,7 @@ model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { std::vector parts; parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::TRIANGLES)); - //DEBUG: - parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::LINE_STRIP)); + parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::LINE_STRIP)); // outline version _spotLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(model::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL));