From 6aa39ec95a840fa03e6b82cd2a100ec9da4cd7ec Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 4 Oct 2016 11:03:12 -0700 Subject: [PATCH] Polish the debugging of the light volumes --- libraries/gpu/src/gpu/Color.slh | 19 +++++++++ libraries/render-utils/src/LightClusters.cpp | 42 ++++++++++++------- .../src/lightClusters_drawClusterContent.slf | 2 +- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/libraries/gpu/src/gpu/Color.slh b/libraries/gpu/src/gpu/Color.slh index 4330b34b90..526cc3dd46 100644 --- a/libraries/gpu/src/gpu/Color.slh +++ b/libraries/gpu/src/gpu/Color.slh @@ -46,6 +46,25 @@ vec3 colorWheel(float normalizedHue) { return vec3(1.f, 0.f, 0.f); } } + +vec3 colorRamp(float normalizedHue) { + float v = normalizedHue * 5.f; + if (v < 0.f) { + return vec3(1.f, 0.f, 0.f); + } else if (v < 1.f) { + return vec3(1.f, v, 0.f); + } else if (v < 2.f) { + return vec3(1.f - (v - 1.f), 1.f, 0.f); + } else if (v < 3.f) { + return vec3(0.f, 1.f, (v - 2.f)); + } else if (v < 4.f) { + return vec3(0.f, 1.f - (v - 3.f), 1.f); + } else if (v < 5.f) { + return vec3((v - 4.f), 0.f, 1.f); + } else { + return vec3(1.f, 0.f, 1.f); + } +} <@endfunc@> <@endif@> \ No newline at end of file diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 2eda0f95a2..b7ab88f119 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -429,7 +429,6 @@ void LightClusters::updateClusters() { } } - // _clusterGrid[i] = (uint32_t)((numLights << 16) | offset); _clusterGrid[i] = (uint32_t)((0xFF000000 & (numLightsSpot << 24)) | (0x00FF0000 & (numLightsPoint << 16)) | (0x0000FFFF & offset)); @@ -595,16 +594,23 @@ const gpu::PipelinePointer DebugLightClusters::getDrawClusterContentPipeline() { void DebugLightClusters::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs) { + if (!(doDrawClusterFromDepth || doDrawContent || doDrawGrid)) { + return; + } + auto deferredTransform = inputs.get0(); auto deferredFramebuffer = inputs.get1(); auto lightingModel = inputs.get2(); auto linearDepthTarget = inputs.get3(); auto lightClusters = inputs.get4(); - + auto args = renderContext->args; - + gpu::Batch batch; + batch.enableStereo(false); + + // Assign the camera transform batch.setViewportTransform(args->_viewport); glm::mat4 projMat; @@ -661,26 +667,30 @@ void DebugLightClusters::run(const render::SceneContextPointer& sceneContext, co batch.setResourceTexture(DEFERRED_BUFFER_LINEAR_DEPTH_UNIT, nullptr); batch.setUniformBuffer(DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT, nullptr); } - + + + + gpu::Batch drawGridAndCleanBatch; + if (doDrawGrid) { // bind the one gpu::Pipeline we need - batch.setPipeline(getDrawClusterGridPipeline()); - + drawGridAndCleanBatch.setPipeline(getDrawClusterGridPipeline()); + auto dims = lightClusters->_frustumGridBuffer->dims; glm::ivec3 summedDims(dims.x*dims.y * dims.z, dims.x*dims.y, dims.x); - batch.drawInstanced(summedDims.x, gpu::LINES, 24, 0); + drawGridAndCleanBatch.drawInstanced(summedDims.x, gpu::LINES, 24, 0); } - batch.setUniformBuffer(LIGHT_GPU_SLOT, nullptr); - batch.setUniformBuffer(LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, nullptr); - batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, nullptr); - batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, nullptr); + drawGridAndCleanBatch.setUniformBuffer(LIGHT_GPU_SLOT, nullptr); + drawGridAndCleanBatch.setUniformBuffer(LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, nullptr); + drawGridAndCleanBatch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, nullptr); + drawGridAndCleanBatch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, nullptr); - batch.setResourceTexture(DEFERRED_BUFFER_COLOR_UNIT, nullptr); - batch.setResourceTexture(DEFERRED_BUFFER_NORMAL_UNIT, nullptr); - batch.setResourceTexture(DEFERRED_BUFFER_EMISSIVE_UNIT, nullptr); - batch.setResourceTexture(DEFERRED_BUFFER_DEPTH_UNIT, nullptr); + drawGridAndCleanBatch.setResourceTexture(DEFERRED_BUFFER_COLOR_UNIT, nullptr); + drawGridAndCleanBatch.setResourceTexture(DEFERRED_BUFFER_NORMAL_UNIT, nullptr); + drawGridAndCleanBatch.setResourceTexture(DEFERRED_BUFFER_EMISSIVE_UNIT, nullptr); + drawGridAndCleanBatch.setResourceTexture(DEFERRED_BUFFER_DEPTH_UNIT, nullptr); args->_context->appendFrameBatch(batch); - + args->_context->appendFrameBatch(drawGridAndCleanBatch); } \ No newline at end of file diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slf b/libraries/render-utils/src/lightClusters_drawClusterContent.slf index 3c9f7bad1c..fe8d850e8a 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slf +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slf @@ -90,6 +90,6 @@ void main(void) { numLightTouching++; } - _fragColor = vec4(colorWheel(numLightTouching/20.0f), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0)); + _fragColor = vec4(colorRamp(1.0 - (numLightTouching / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0)); }