History

Prepare shadowMap pipeline to debug in color

Zach Pomerantz committed 10 years ago

Commit 7744b891 parent b9b407f5 files · +62 −23Browse files

Showing the changes to libraries/render-utils/src/DebugDeferredBuffer.cpp (1 of 5 files). Show all

Unified · Split

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