diff --git a/libraries/gpu/src/gpu/Framebuffer.cpp b/libraries/gpu/src/gpu/Framebuffer.cpp index ea650c6ad9..404ffa0a91 100755 --- a/libraries/gpu/src/gpu/Framebuffer.cpp +++ b/libraries/gpu/src/gpu/Framebuffer.cpp @@ -49,7 +49,9 @@ Framebuffer* Framebuffer::create( const Format& colorBufferFormat, const Format& Framebuffer* Framebuffer::createShadowmap(uint16 width) { auto framebuffer = Framebuffer::create(); - auto depthTexture = TexturePointer(Texture::create2D(Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH), width, width)); + + auto depthFormat = Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); // Depth32 texel format + auto depthTexture = TexturePointer(Texture::create2D(depthFormat, width, width)); Sampler::Desc samplerDesc; samplerDesc._borderColor = glm::vec4(1.0f); @@ -59,8 +61,11 @@ Framebuffer* Framebuffer::createShadowmap(uint16 width) { samplerDesc._comparisonFunc = LESS_EQUAL; depthTexture->setSampler(Sampler(samplerDesc)); + framebuffer->setDepthStencilBuffer(depthTexture, depthFormat); - framebuffer->setDepthStencilBuffer(depthTexture, Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH)); + // 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 ab2fa403f1..e76a843121 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -20,6 +20,7 @@ #include "GeometryCache.h" #include "FramebufferCache.h" +#include "DeferredLightingEffect.h" #include "debug_deferred_buffer_vert.h" #include "debug_deferred_buffer_frag.h" @@ -31,45 +32,53 @@ enum Slots { Normal, Specular, Depth, - Lighting + Lighting, + Shadow }; -static const std::string DEEFAULT_DIFFUSE_SHADER { +static const std::string DEFAULT_DIFFUSE_SHADER { "vec4 getFragmentColor() {" " return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" " }" }; -static const std::string DEEFAULT_ALPHA_SHADER { +static const std::string DEFAULT_ALPHA_SHADER { "vec4 getFragmentColor() {" " return vec4(vec3(texture(diffuseMap, uv).a), 1.0);" " }" }; -static const std::string DEEFAULT_SPECULAR_SHADER { +static const std::string DEFAULT_SPECULAR_SHADER { "vec4 getFragmentColor() {" " return vec4(texture(specularMap, uv).xyz, 1.0);" " }" }; -static const std::string DEEFAULT_ROUGHNESS_SHADER { +static const std::string DEFAULT_ROUGHNESS_SHADER { "vec4 getFragmentColor() {" " return vec4(vec3(texture(specularMap, uv).a), 1.0);" " }" }; -static const std::string DEEFAULT_NORMAL_SHADER { +static const std::string DEFAULT_NORMAL_SHADER { "vec4 getFragmentColor() {" " return vec4(normalize(texture(normalMap, uv).xyz), 1.0);" " }" }; -static const std::string DEEFAULT_DEPTH_SHADER { +static const std::string DEFAULT_DEPTH_SHADER { "vec4 getFragmentColor() {" " return vec4(vec3(texture(depthMap, uv).x), 1.0);" " }" }; -static const std::string DEEFAULT_LIGHTING_SHADER { +static const std::string DEFAULT_LIGHTING_SHADER { "vec4 getFragmentColor() {" " return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" " }" }; -static const std::string DEEFAULT_CUSTOM_SHADER { +static const std::string DEFAULT_SHADOW_SHADER { + "uniform sampler2D shadowMapColor;" + // The actual shadowMap is a sampler2DShadow, so we cannot normally sample it + "vec4 getFragmentColor() {" + " return vec4(texture(shadowMapColor, uv).xyz, 1.0);" + " }" +}; +static const std::string DEFAULT_CUSTOM_SHADER { "vec4 getFragmentColor() {" " return vec4(1.0, 0.0, 0.0, 1.0);" " }" @@ -98,21 +107,23 @@ DebugDeferredBuffer::DebugDeferredBuffer() { std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode, std::string customFile) { switch (mode) { case DiffuseMode: - return DEEFAULT_DIFFUSE_SHADER; + return DEFAULT_DIFFUSE_SHADER; case AlphaMode: - return DEEFAULT_ALPHA_SHADER; + return DEFAULT_ALPHA_SHADER; case SpecularMode: - return DEEFAULT_SPECULAR_SHADER; + return DEFAULT_SPECULAR_SHADER; case RoughnessMode: - return DEEFAULT_ROUGHNESS_SHADER; + return DEFAULT_ROUGHNESS_SHADER; case NormalMode: - return DEEFAULT_NORMAL_SHADER; + return DEFAULT_NORMAL_SHADER; case DepthMode: - return DEEFAULT_DEPTH_SHADER; + return DEFAULT_DEPTH_SHADER; case LightingMode: - return DEEFAULT_LIGHTING_SHADER; + return DEFAULT_LIGHTING_SHADER; + case ShadowMode: + return DEFAULT_SHADOW_SHADER; case CustomMode: - return getFileContent(customFile, DEEFAULT_CUSTOM_SHADER); + return getFileContent(customFile, DEFAULT_CUSTOM_SHADER); } Q_UNREACHABLE(); return std::string(); @@ -158,6 +169,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)); gpu::Shader::makeProgram(*program, slotBindings); auto pipeline = gpu::Pipeline::create(program, std::make_shared()); @@ -193,7 +205,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { const auto geometryBuffer = DependencyManager::get(); const auto framebufferCache = DependencyManager::get(); - + const auto& lightStage = DependencyManager::get()->getLightStage(); glm::mat4 projMat; Transform viewMat; @@ -213,6 +225,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)); 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/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index c9ea24644a..eba48cd0c3 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -33,6 +33,7 @@ private: NormalMode, DepthMode, LightingMode, + ShadowMode, CustomMode // Needs to stay last }; diff --git a/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf index d691104bdd..fd35ec11d7 100755 --- a/libraries/render-utils/src/model_shadow.slf +++ b/libraries/render-utils/src/model_shadow.slf @@ -12,9 +12,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -out vec4 _fragColor; +layout(location = 0) out vec4 _fragColor; void main(void) { - // fixed color for now (we may eventually want to use texture alpha) - _fragColor = vec4(1.0, 1.0, 1.0, 0.0); + // stencil in solid color for debugging + _fragColor = vec4(0.0, 0.0, 1.0, 1.0); } diff --git a/libraries/render-utils/src/skin_model_shadow.slf b/libraries/render-utils/src/skin_model_shadow.slf new file mode 100644 index 0000000000..85d1b7424b --- /dev/null +++ b/libraries/render-utils/src/skin_model_shadow.slf @@ -0,0 +1,20 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_shadow.frag +// fragment shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +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); +}