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
1111
1212 #include "DebugDeferredBuffer.h"
1313
14+#include <QString>
15+
1416 #include <gpu/Batch.h>
1517 #include <gpu/Context.h>
1618 #include <render/Scene.h>
@@ -24,8 +26,16 @@ · 7 unmodified lines
2426
2527 using namespace render;
2628
27−static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" };
28−static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES {{
29+enum Slots {
30+ Diffuse = 0,
31+ Normal,
32+ Specular,
33+ Depth,
34+ Lighting,
35+
36+ NUM_SLOTS
37+};
38+static const std::array<std::string, Slots::NUM_SLOTS> SLOT_NAMES {{
2939 "diffuseMap",
3040 "normalMap",
3141 "specularMap",
@@ -33,14 +43,50 @@ static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES · 1 unmodified line
3343 "lightingMap"
3444 }};
3545
36−std::string getCode(int slot) {
37− return std::string("return texture(").append(SLOT_NAMES[slot]).append(", uv);");
46+static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" };
47+
48+std::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+ }
3884 }
3985
40−const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) {
41− if (!_pipelines[slot]) {
86+const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) {
87+ if (!_pipelines[mode]) {
4288 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));
4490
4591 auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert }));
4692 auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader));
@@ -53,9 +99,9 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { · 6 unmodified lines
5399 gpu::Shader::makeProgram(*program, slotBindings);
54100
55101 // 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>());
57103 }
58− return _pipelines[slot];
104+ return _pipelines[mode];
59105 }
60106
61107
@@ -76,7 +122,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren · 14 unmodified lines
76122 batch.setViewTransform(viewMat);
77123 batch.setModelTransform(Transform());
78124
79− batch.setPipeline(getPipeline((DebugDeferredBufferSlot)(renderContext->_drawDebugDeferredBuffer - 1)));
125+ batch.setPipeline(getPipeline(Modes(renderContext->_drawDebugDeferredBuffer - 1)));
80126
81127 batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture());
82128 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