From 398f83be3f4086aba87ee0dd90be737ecc4b9382 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 19 Jan 2016 12:01:18 -0800 Subject: [PATCH] Change shadow debug buffer to reuse shadowMap tex --- libraries/gpu/src/gpu/Framebuffer.cpp | 4 ---- .../render-utils/src/DebugDeferredBuffer.cpp | 15 ++++++++++----- libraries/render-utils/src/model_shadow.slf | 4 ++-- libraries/render-utils/src/skin_model_shadow.slf | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libraries/gpu/src/gpu/Framebuffer.cpp b/libraries/gpu/src/gpu/Framebuffer.cpp index 404ffa0a91..779d70cc88 100755 --- a/libraries/gpu/src/gpu/Framebuffer.cpp +++ b/libraries/gpu/src/gpu/Framebuffer.cpp @@ -63,10 +63,6 @@ Framebuffer* Framebuffer::createShadowmap(uint16 width) { depthTexture->setSampler(Sampler(samplerDesc)); framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); - // Use a render buffer to allow use of the DebugDeferredBuffer Job - gpu::TexturePointer colorbuffer{gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, width)}; - framebuffer->setRenderBuffer(0, colorbuffer); - return framebuffer; } diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index e76a843121..e1ee308883 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -72,10 +72,15 @@ static const std::string DEFAULT_LIGHTING_SHADER { " }" }; static const std::string DEFAULT_SHADOW_SHADER { - "uniform sampler2D shadowMapColor;" - // The actual shadowMap is a sampler2DShadow, so we cannot normally sample it + "uniform sampler2DShadow shadowMap;" "vec4 getFragmentColor() {" - " return vec4(texture(shadowMapColor, uv).xyz, 1.0);" + " for (int i = 255; i >= 0; --i) {" + " float depth = i / 255.0;" + " if (texture(shadowMap, vec3(uv, depth)) > 0.5) {" + " return vec4(vec3(depth), 1.0);" + " }" + " }" + " return vec4(vec3(0.0), 1.0);" " }" }; static const std::string DEFAULT_CUSTOM_SHADER { @@ -169,7 +174,7 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode, std::st slotBindings.insert(gpu::Shader::Binding("specularMap", Specular)); slotBindings.insert(gpu::Shader::Binding("depthMap", Depth)); slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting)); - slotBindings.insert(gpu::Shader::Binding("shadowMapColor", Shadow)); + slotBindings.insert(gpu::Shader::Binding("shadowMap", Shadow)); gpu::Shader::makeProgram(*program, slotBindings); auto pipeline = gpu::Pipeline::create(program, std::make_shared()); @@ -225,7 +230,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren batch.setResourceTexture(Specular, framebufferCache->getDeferredSpecularTexture()); batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); - batch.setResourceTexture(Shadow, lightStage.lights[0]->shadow.framebuffer->getRenderBuffer(0)); + batch.setResourceTexture(Shadow, lightStage.lights[0]->shadow.framebuffer->getDepthStencilBuffer()); const glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); const glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); diff --git a/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf index fd35ec11d7..178ea7b387 100755 --- a/libraries/render-utils/src/model_shadow.slf +++ b/libraries/render-utils/src/model_shadow.slf @@ -15,6 +15,6 @@ layout(location = 0) out vec4 _fragColor; void main(void) { - // stencil in solid color for debugging - _fragColor = vec4(0.0, 0.0, 1.0, 1.0); + // pass-through to set z-buffer + _fragColor = vec4(1.0, 1.0, 1.0, 0.0); } diff --git a/libraries/render-utils/src/skin_model_shadow.slf b/libraries/render-utils/src/skin_model_shadow.slf index 85d1b7424b..178ea7b387 100644 --- a/libraries/render-utils/src/skin_model_shadow.slf +++ b/libraries/render-utils/src/skin_model_shadow.slf @@ -15,6 +15,6 @@ layout(location = 0) out vec4 _fragColor; void main(void) { - // stencil in solid color for debugging - _fragColor = vec4(1.0, 0.0, 0.0, 1.0); + // pass-through to set z-buffer + _fragColor = vec4(1.0, 1.0, 1.0, 0.0); }