Polish the debugging of the light volumes

This commit is contained in:
samcake 2016-10-04 11:03:12 -07:00
parent a378a6eccb
commit 6aa39ec95a
3 changed files with 46 additions and 17 deletions

View file

@ -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@>

View file

@ -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);
}

View file

@ -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));
}