Showing the changes to libraries/render-utils/src/DebugDeferredBuffer.cpp (1 of 5 files). Show all
Unified · Split
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | #include "GeometryCache.h" |
| 22 | 22 | #include "FramebufferCache.h" |
| 23 | +#include "DeferredLightingEffect.h" | |
| 23 | 24 | |
| 24 | 25 | #include "debug_deferred_buffer_vert.h" |
| 25 | 26 | #include "debug_deferred_buffer_frag.h" |
| @@ -31,45 +32,53 @@ enum Slots { · 5 unmodified lines | ||
| 31 | 32 | Normal, |
| 32 | 33 | Specular, |
| 33 | 34 | Depth, |
| 34 | − Lighting | |
| 35 | + Lighting, | |
| 36 | + Shadow | |
| 35 | 37 | }; |
| 36 | 38 | |
| 37 | −static const std::string DEEFAULT_DIFFUSE_SHADER { | |
| 39 | +static const std::string DEFAULT_DIFFUSE_SHADER { | |
| 38 | 40 | "vec4 getFragmentColor() {" |
| 39 | 41 | " return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" |
| 40 | 42 | " }" |
| 41 | 43 | }; |
| 42 | −static const std::string DEEFAULT_ALPHA_SHADER { | |
| 44 | +static const std::string DEFAULT_ALPHA_SHADER { | |
| 43 | 45 | "vec4 getFragmentColor() {" |
| 44 | 46 | " return vec4(vec3(texture(diffuseMap, uv).a), 1.0);" |
| 45 | 47 | " }" |
| 46 | 48 | }; |
| 47 | −static const std::string DEEFAULT_SPECULAR_SHADER { | |
| 49 | +static const std::string DEFAULT_SPECULAR_SHADER { | |
| 48 | 50 | "vec4 getFragmentColor() {" |
| 49 | 51 | " return vec4(texture(specularMap, uv).xyz, 1.0);" |
| 50 | 52 | " }" |
| 51 | 53 | }; |
| 52 | −static const std::string DEEFAULT_ROUGHNESS_SHADER { | |
| 54 | +static const std::string DEFAULT_ROUGHNESS_SHADER { | |
| 53 | 55 | "vec4 getFragmentColor() {" |
| 54 | 56 | " return vec4(vec3(texture(specularMap, uv).a), 1.0);" |
| 55 | 57 | " }" |
| 56 | 58 | }; |
| 57 | −static const std::string DEEFAULT_NORMAL_SHADER { | |
| 59 | +static const std::string DEFAULT_NORMAL_SHADER { | |
| 58 | 60 | "vec4 getFragmentColor() {" |
| 59 | 61 | " return vec4(normalize(texture(normalMap, uv).xyz), 1.0);" |
| 60 | 62 | " }" |
| 61 | 63 | }; |
| 62 | −static const std::string DEEFAULT_DEPTH_SHADER { | |
| 64 | +static const std::string DEFAULT_DEPTH_SHADER { | |
| 63 | 65 | "vec4 getFragmentColor() {" |
| 64 | 66 | " return vec4(vec3(texture(depthMap, uv).x), 1.0);" |
| 65 | 67 | " }" |
| 66 | 68 | }; |
| 67 | −static const std::string DEEFAULT_LIGHTING_SHADER { | |
| 69 | +static const std::string DEFAULT_LIGHTING_SHADER { | |
| 68 | 70 | "vec4 getFragmentColor() {" |
| 69 | 71 | " return vec4(pow(texture(lightingMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" |
| 70 | 72 | " }" |
| 71 | 73 | }; |
| 72 | −static const std::string DEEFAULT_CUSTOM_SHADER { | |
| 74 | +static const std::string DEFAULT_SHADOW_SHADER { | |
| 75 | + "uniform sampler2D shadowMapColor;" | |
| 76 | + // The actual shadowMap is a sampler2DShadow, so we cannot normally sample it | |
| 77 | + "vec4 getFragmentColor() {" | |
| 78 | + " return vec4(texture(shadowMapColor, uv).xyz, 1.0);" | |
| 79 | + " }" | |
| 80 | +}; | |
| 81 | +static const std::string DEFAULT_CUSTOM_SHADER { | |
| 73 | 82 | "vec4 getFragmentColor() {" |
| 74 | 83 | " return vec4(1.0, 0.0, 0.0, 1.0);" |
| 75 | 84 | " }" |
| @@ -98,21 +107,23 @@ DebugDeferredBuffer::DebugDeferredBuffer() { · 22 unmodified lines | ||
| 98 | 107 | std::string DebugDeferredBuffer::getShaderSourceCode(Modes mode, std::string customFile) { |
| 99 | 108 | switch (mode) { |
| 100 | 109 | case DiffuseMode: |
| 101 | − return DEEFAULT_DIFFUSE_SHADER; | |
| 110 | + return DEFAULT_DIFFUSE_SHADER; | |
| 102 | 111 | case AlphaMode: |
| 103 | − return DEEFAULT_ALPHA_SHADER; | |
| 112 | + return DEFAULT_ALPHA_SHADER; | |
| 104 | 113 | case SpecularMode: |
| 105 | − return DEEFAULT_SPECULAR_SHADER; | |
| 114 | + return DEFAULT_SPECULAR_SHADER; | |
| 106 | 115 | case RoughnessMode: |
| 107 | − return DEEFAULT_ROUGHNESS_SHADER; | |
| 116 | + return DEFAULT_ROUGHNESS_SHADER; | |
| 108 | 117 | case NormalMode: |
| 109 | − return DEEFAULT_NORMAL_SHADER; | |
| 118 | + return DEFAULT_NORMAL_SHADER; | |
| 110 | 119 | case DepthMode: |
| 111 | − return DEEFAULT_DEPTH_SHADER; | |
| 120 | + return DEFAULT_DEPTH_SHADER; | |
| 112 | 121 | case LightingMode: |
| 113 | − return DEEFAULT_LIGHTING_SHADER; | |
| 122 | + return DEFAULT_LIGHTING_SHADER; | |
| 123 | + case ShadowMode: | |
| 124 | + return DEFAULT_SHADOW_SHADER; | |
| 114 | 125 | case CustomMode: |
| 115 | − return getFileContent(customFile, DEEFAULT_CUSTOM_SHADER); | |
| 126 | + return getFileContent(customFile, DEFAULT_CUSTOM_SHADER); | |
| 116 | 127 | } |
| 117 | 128 | Q_UNREACHABLE(); |
| 118 | 129 | return std::string(); |
| @@ -158,6 +169,7 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode, std::st · 39 unmodified lines | ||
| 158 | 169 | slotBindings.insert(gpu::Shader::Binding("specularMap", Specular)); |
| 159 | 170 | slotBindings.insert(gpu::Shader::Binding("depthMap", Depth)); |
| 160 | 171 | slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting)); |
| 172 | + slotBindings.insert(gpu::Shader::Binding("shadowMapColor", Shadow)); | |
| 161 | 173 | gpu::Shader::makeProgram(*program, slotBindings); |
| 162 | 174 | |
| 163 | 175 | auto pipeline = gpu::Pipeline::create(program, std::make_shared<gpu::State>()); |
| @@ -193,7 +205,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren · 29 unmodified lines | ||
| 193 | 205 | gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { |
| 194 | 206 | const auto geometryBuffer = DependencyManager::get<GeometryCache>(); |
| 195 | 207 | const auto framebufferCache = DependencyManager::get<FramebufferCache>(); |
| 196 | − | |
| 208 | + const auto& lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage(); | |
| 197 | 209 | |
| 198 | 210 | glm::mat4 projMat; |
| 199 | 211 | Transform viewMat; |
| @@ -213,6 +225,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren · 13 unmodified lines | ||
| 213 | 225 | batch.setResourceTexture(Specular, framebufferCache->getDeferredSpecularTexture()); |
| 214 | 226 | batch.setResourceTexture(Depth, framebufferCache->getPrimaryDepthTexture()); |
| 215 | 227 | batch.setResourceTexture(Lighting, framebufferCache->getLightingTexture()); |
| 228 | + batch.setResourceTexture(Shadow, lightStage.lights[0]->shadow.framebuffer->getRenderBuffer(0)); | |
| 216 | 229 | |
| 217 | 230 | const glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); |
| 218 | 231 | const glm::vec2 bottomLeft(renderContext->_deferredDebugSize.x, renderContext->_deferredDebugSize.y); |