Adding debuging of the ambient lighting

This commit is contained in:
Sam Cake 2017-05-16 01:01:19 -07:00
parent db4387e55d
commit 4c3ddfbff9
4 changed files with 142 additions and 0 deletions

View file

@ -206,6 +206,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
auto statusIconMap = DependencyManager::get<TextureCache>()->getImageTexture(iconMapPath, image::TextureUsage::STRICT_TEXTURE);
task.addJob<DrawStatus>("DrawStatus", opaques, DrawStatus(statusIconMap));
}
task.addJob<DebugZoneLighting>("DebugZoneLighting");
}

View file

@ -10,9 +10,18 @@
//
#include "ZoneRenderer.h"
#include <gpu/Context.h>
#include <gpu/StandardShaderLib.h>
#include <render/FilterTask.h>
#include <render/DrawTask.h>
#include "DeferredLightingEffect.h"
#include "zone_drawAmbient_frag.h"
using namespace render;
class SetupZones {
@ -45,3 +54,75 @@ void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs)
render::renderItems(context, inputs);
}
const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() {
if (!_keyLightPipeline) {
}
return _keyLightPipeline;
}
const gpu::PipelinePointer& DebugZoneLighting::getAmbientPipeline() {
if (!_ambientPipeline) {
auto vs = gpu::StandardShaderLib::getDrawTransformUnitQuadVS();
auto ps = gpu::Shader::createPixel(std::string(zone_drawAmbient_frag));
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
gpu::Shader::BindingSet slotBindings;
//slotBindings.insert(gpu::Shader::Binding(std::string("blurParamsBuffer"), BlurTask_ParamsSlot));
//slotBindings.insert(gpu::Shader::Binding(std::string("sourceMap"), BlurTask_SourceSlot));
gpu::Shader::makeProgram(*program, slotBindings);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
_ambientPipeline = gpu::Pipeline::create(program, state);
}
return _ambientPipeline;
}
const gpu::PipelinePointer& DebugZoneLighting::getBackgroundPipeline() {
if (!_backgroundPipeline) {
}
return _backgroundPipeline;
}
void DebugZoneLighting::run(const render::RenderContextPointer& context) {
RenderArgs* args = context->args;
auto lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage();
const auto light = lightStage->getLight(0);
model::LightPointer keyAmbiLight;
if (lightStage && lightStage->_currentFrame._ambientLights.size()) {
keyAmbiLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front());
} else {
// keyAmbiLight = _allocatedLights[_globalLights.front()];
}
/* if (lightBufferUnit >= 0) {
batch.setUniformBuffer(lightBufferUnit, keySunLight->getLightSchemaBuffer());
}*/
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
batch.setViewportTransform(args->_viewport);
auto viewFrustum = args->getViewFrustum();
batch.setProjectionTransform(viewFrustum.getProjection());
batch.resetViewTransform();
Transform model;
model.setTranslation(glm::vec3(0.0, 0.0, -10.0));
batch.setModelTransform(model);
batch.setPipeline(getAmbientPipeline());
if (keyAmbiLight) {
if (keyAmbiLight->hasAmbient()) {
batch.setUniformBuffer(0, keyAmbiLight->getAmbientSchemaBuffer());
}
if (keyAmbiLight->getAmbientMap()) {
batch.setResourceTexture(0, keyAmbiLight->getAmbientMap());
}
}
batch.draw(gpu::TRIANGLE_STRIP, 4);
});
}

View file

@ -50,4 +50,24 @@ protected:
int _maxDrawn; // initialized by Config
};
class DebugZoneLighting {
public:
using JobModel = render::Job::Model<DebugZoneLighting>;
DebugZoneLighting() {}
void run(const render::RenderContextPointer& context);
protected:
gpu::PipelinePointer _keyLightPipeline;
gpu::PipelinePointer _ambientPipeline;
gpu::PipelinePointer _backgroundPipeline;
const gpu::PipelinePointer& getKeyLightPipeline();
const gpu::PipelinePointer& getAmbientPipeline();
const gpu::PipelinePointer& getBackgroundPipeline();
};
#endif

View file

@ -0,0 +1,39 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// Created by Sam Gateau on 5/16/17.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include model/Light.slh@>
<@include LightingModel.slh@>
<! <$declareLightBuffer()$> !>
<$declareLightAmbientBuffer()$>
<@include LightAmbient.slh@>
<! <@include LightDirectional.slh@> !>
<$declareLightingAmbient(_SCRIBE_NULL, 1, _SCRIBE_NULL, _SCRIBE_NULL)$>
in vec2 varTexCoord0;
out vec4 _fragColor;
void main(void) {
LightAmbient lightAmbient = getLightAmbient();
// _fragColor = vec4(varTexCoord0, 0.0, 1.0);
float z = sqrt( dot(varTexCoord0.xy, varTexCoord0.xy));
vec3 dir = vec3(varTexCoord0.xy, z);
vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), dir).xyz;
_fragColor = vec4(ambient, 1.0);
}