Change shadow debug buffer to reuse shadowMap tex

This commit is contained in:
Zach Pomerantz 2016-01-19 12:01:18 -08:00
parent 7a5562abce
commit 398f83be3f
4 changed files with 14 additions and 13 deletions

View file

@ -63,10 +63,6 @@ Framebuffer* Framebuffer::createShadowmap(uint16 width) {
depthTexture->setSampler(Sampler(samplerDesc)); depthTexture->setSampler(Sampler(samplerDesc));
framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); 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; return framebuffer;
} }

View file

@ -72,10 +72,15 @@ static const std::string DEFAULT_LIGHTING_SHADER {
" }" " }"
}; };
static const std::string DEFAULT_SHADOW_SHADER { static const std::string DEFAULT_SHADOW_SHADER {
"uniform sampler2D shadowMapColor;" "uniform sampler2DShadow shadowMap;"
// The actual shadowMap is a sampler2DShadow, so we cannot normally sample it
"vec4 getFragmentColor() {" "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 { 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("specularMap", Specular));
slotBindings.insert(gpu::Shader::Binding("depthMap", Depth)); slotBindings.insert(gpu::Shader::Binding("depthMap", Depth));
slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting)); 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); gpu::Shader::makeProgram(*program, slotBindings);
auto pipeline = gpu::Pipeline::create(program, std::make_shared<gpu::State>()); auto pipeline = gpu::Pipeline::create(program, std::make_shared<gpu::State>());
@ -225,7 +230,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren
batch.setResourceTexture(Specular, framebufferCache->getDeferredSpecularTexture()); batch.setResourceTexture(Specular, framebufferCache->getDeferredSpecularTexture());
batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture());
batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); 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::vec4 color(1.0f, 1.0f, 1.0f, 1.0f);
const glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); const glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y);

View file

@ -15,6 +15,6 @@
layout(location = 0) out vec4 _fragColor; layout(location = 0) out vec4 _fragColor;
void main(void) { void main(void) {
// stencil in solid color for debugging // pass-through to set z-buffer
_fragColor = vec4(0.0, 0.0, 1.0, 1.0); _fragColor = vec4(1.0, 1.0, 1.0, 0.0);
} }

View file

@ -15,6 +15,6 @@
layout(location = 0) out vec4 _fragColor; layout(location = 0) out vec4 _fragColor;
void main(void) { void main(void) {
// stencil in solid color for debugging // pass-through to set z-buffer
_fragColor = vec4(1.0, 0.0, 0.0, 1.0); _fragColor = vec4(1.0, 1.0, 1.0, 0.0);
} }