History

More g-buffer debugging options

Atlante45 committed 10 years ago

Commit 41af3771 parent 1a404bb3 files · +73 −23Browse files

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

Unified · Split

libraries/render-utils/src/DebugDeferredBuffer.cpp+56−10
@@ -11,6 +11,8 @@ · 10 unmodified lines
11 11
12#include "DebugDeferredBuffer.h"12#include "DebugDeferredBuffer.h"
13 13
14#include <QString>
15
14#include <gpu/Batch.h>16#include <gpu/Batch.h>
15#include <gpu/Context.h>17#include <gpu/Context.h>
16#include <render/Scene.h>18#include <render/Scene.h>
@@ -24,8 +26,16 @@ · 7 unmodified lines
24 26
25using namespace render;27using namespace render;
26 28
27static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" };29enum Slots {
28static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES {{30 Diffuse = 0,
31 Normal,
32 Specular,
33 Depth,
34 Lighting,
35
36 NUM_SLOTS
37};
38static const std::array<std::string, Slots::NUM_SLOTS> SLOT_NAMES {{
29 "diffuseMap",39 "diffuseMap",
30 "normalMap",40 "normalMap",
31 "specularMap",41 "specularMap",
@@ -33,14 +43,50 @@ static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES · 1 unmodified line
33 "lightingMap"43 "lightingMap"
34}};44}};
35 45
36std::string getCode(int slot) {46static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" };
37 return std::string("return texture(").append(SLOT_NAMES[slot]).append(", uv);");47
48std::string DebugDeferredBuffer::getCode(Modes mode) {
49 switch (mode) {
50 case DiffuseMode: {
51 QString code = "return vec4(texture(%1, uv).xyz, 1.0);";
52 return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString();
53 }
54 case AlphaMode: {
55 QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);";
56 return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString();
57 }
58 case SpecularMode: {
59 QString code = "return vec4(texture(%1, uv).xyz, 1.0);";
60 return code.arg(SLOT_NAMES[Specular].c_str()).toStdString();
61 }
62 case RoughnessMode: {
63 QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);";
64 return code.arg(SLOT_NAMES[Specular].c_str()).toStdString();
65 }
66 case NormalMode: {
67 QString code = "return vec4(texture(%1, uv).xyz, 1.0);";
68 return code.arg(SLOT_NAMES[Normal].c_str()).toStdString();
69 }
70 case DepthMode: {
71 QString code = "return vec4(vec3(texture(%1, uv).x), 1.0);";
72 return code.arg(SLOT_NAMES[Depth].c_str()).toStdString();
73 }
74 case LightingMode: {
75 QString code = "return vec4(texture(%1, uv).xyz, 1.0);";
76 return code.arg(SLOT_NAMES[Lighting].c_str()).toStdString();
77 }
78 case CustomMode:
79 return std::string("return vec4(1.0);");
80 case NUM_MODES:
81 Q_UNIMPLEMENTED();
82 return std::string("return vec4(1.0);");
83 }
38}84}
39 85
40const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) {86const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) {
41 if (!_pipelines[slot]) {87 if (!_pipelines[mode]) {
42 std::string fragmentShader = debug_deferred_buffer_frag;88 std::string fragmentShader = debug_deferred_buffer_frag;
43 fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(slot));89 fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(mode));
44 90
45 auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert }));91 auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert }));
46 auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader));92 auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader));
@@ -53,9 +99,9 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { · 6 unmodified lines
53 gpu::Shader::makeProgram(*program, slotBindings);99 gpu::Shader::makeProgram(*program, slotBindings);
54 100
55 // Good to go add the brand new pipeline101 // Good to go add the brand new pipeline
56 _pipelines[slot] = gpu::Pipeline::create(program, std::make_shared<gpu::State>());102 _pipelines[mode] = gpu::Pipeline::create(program, std::make_shared<gpu::State>());
57 }103 }
58 return _pipelines[slot];104 return _pipelines[mode];
59}105}
60 106
61 107
@@ -76,7 +122,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren · 14 unmodified lines
76 batch.setViewTransform(viewMat);122 batch.setViewTransform(viewMat);
77 batch.setModelTransform(Transform());123 batch.setModelTransform(Transform());
78 124
79 batch.setPipeline(getPipeline((DebugDeferredBufferSlot)(renderContext->_drawDebugDeferredBuffer - 1)));125 batch.setPipeline(getPipeline(Modes(renderContext->_drawDebugDeferredBuffer - 1)));
80 126
81 batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture());127 batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture());
82 batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture());128 batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture());

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t