mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
Adding more debugging tool
This commit is contained in:
parent
4c3ddfbff9
commit
2cd2c95940
11 changed files with 178 additions and 42 deletions
|
@ -354,11 +354,8 @@ void RenderableZoneEntityItem::updateKeyAmbientFromEntity(RenderableZoneEntityIt
|
|||
|
||||
|
||||
// Set the keylight
|
||||
ambientLight->setColor(ColorUtils::toVec3(this->getKeyLightProperties().getColor()));
|
||||
ambientLight->setAmbientIntensity(this->getKeyLightProperties().getAmbientIntensity());
|
||||
// ambientLight->setIntensity(this->getKeyLightProperties().getIntensity());
|
||||
ambientLight->setDirection(this->getKeyLightProperties().getDirection());
|
||||
|
||||
|
||||
if (this->getKeyLightProperties().getAmbientURL().isEmpty()) {
|
||||
keyZonePayload.setAmbientURL(this->getSkyboxProperties().getURL());
|
||||
} else {
|
||||
|
|
|
@ -113,7 +113,6 @@ public:
|
|||
void setIntensity(float intensity);
|
||||
|
||||
bool isRanged() const { return (getType() == POINT) || (getType() == SPOT); }
|
||||
bool hasAmbient() const { return (getType() == AMBIENT); }
|
||||
|
||||
// FalloffRradius is the physical radius of the light sphere through which energy shines,
|
||||
// expressed in meters. It is used only to calculate the falloff curve of the light.
|
||||
|
|
|
@ -138,5 +138,4 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext,
|
|||
}
|
||||
*/
|
||||
|
||||
backgroundStage->_currentFrame.clear();
|
||||
}
|
|
@ -146,15 +146,21 @@ void DeferredLightingEffect::init() {
|
|||
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
||||
QString skyboxUrl { PathUtils::resourcesPath() + "images/Default-Sky-9-cubemap.ktx" };
|
||||
// QString skyboxAmbientUrl { PathUtils::resourcesPath() + "images/Default-Sky-9-cubemap.ktx" };
|
||||
{
|
||||
PROFILE_RANGE(render, "Process Default Skybox");
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
||||
_defaultSkyboxTexture = _defaultSkyboxAmbientTexture = textureCache->getImageTexture(skyboxUrl, image::TextureUsage::CUBE_TEXTURE, { { "generateIrradiance", false } });
|
||||
// _defaultSkyboxAmbientTexture = textureCache->getImageTexture(skyboxAmbientUrl, image::TextureUsage::CUBE_TEXTURE, { { "generateIrradiance", true } });
|
||||
auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx";
|
||||
|
||||
_defaultSkybox->setCubemap(_defaultSkyboxTexture);
|
||||
_defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl);
|
||||
_defaultSkyboxAmbientTexture = _defaultSkyboxTexture;
|
||||
|
||||
lp->setAmbientMap(_defaultSkyboxTexture);
|
||||
_defaultSkybox->setCubemap(_defaultSkyboxTexture);
|
||||
}
|
||||
|
||||
|
||||
lp->setAmbientIntensity(0.5f);
|
||||
lp->setAmbientMap(_defaultSkyboxAmbientTexture);
|
||||
|
||||
}
|
||||
|
||||
|
@ -177,7 +183,7 @@ void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBuff
|
|||
if (lightBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(lightBufferUnit, keySunLight->getLightSchemaBuffer());
|
||||
}
|
||||
if (keyAmbiLight->hasAmbient() && (ambientBufferUnit >= 0)) {
|
||||
if (ambientBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(ambientBufferUnit, keyAmbiLight->getAmbientSchemaBuffer());
|
||||
}
|
||||
|
||||
|
@ -315,15 +321,20 @@ static void loadLightVolumeProgram(const char* vertSource, const char* fragSourc
|
|||
}
|
||||
|
||||
void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) {
|
||||
auto globalLight = _allocatedLights.front();
|
||||
/* auto globalLight = _allocatedLights.front();
|
||||
globalLight->setDirection(light->getDirection());
|
||||
globalLight->setColor(light->getColor());
|
||||
globalLight->setIntensity(light->getIntensity());
|
||||
globalLight->setAmbientIntensity(light->getAmbientIntensity());
|
||||
globalLight->setAmbientSphere(light->getAmbientSphere());
|
||||
globalLight->setAmbientMap(light->getAmbientMap());
|
||||
globalLight->setAmbientMap(light->getAmbientMap());*/
|
||||
}
|
||||
|
||||
const model::LightPointer& DeferredLightingEffect::getGlobalLight() const {
|
||||
return _allocatedLights.front();
|
||||
}
|
||||
|
||||
|
||||
#include <shared/Shapes.h>
|
||||
|
||||
model::MeshPointer DeferredLightingEffect::getPointLightMesh() {
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
|
||||
// update global lighting
|
||||
void setGlobalLight(const model::LightPointer& light);
|
||||
const model::LightPointer& getGlobalLight() const;
|
||||
|
||||
const LightStagePointer& getLightStage() { return _lightStage; }
|
||||
const BackgroundStagePointer& getBackgroundStage() { return _backgroundStage; }
|
||||
|
|
|
@ -77,7 +77,6 @@ public:
|
|||
};
|
||||
using Descs = std::vector<Desc>;
|
||||
|
||||
|
||||
Index findLight(const LightPointer& light) const;
|
||||
Index addLight(const LightPointer& light);
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
|||
task.addJob<DrawStatus>("DrawStatus", opaques, DrawStatus(statusIconMap));
|
||||
}
|
||||
|
||||
task.addJob<DebugZoneLighting>("DebugZoneLighting");
|
||||
task.addJob<DebugZoneLighting>("DebugZoneLighting", deferredFrameTransform);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "DeferredLightingEffect.h"
|
||||
|
||||
#include "zone_drawAmbient_frag.h"
|
||||
#include "zone_drawSkybox_frag.h"
|
||||
|
||||
|
||||
using namespace render;
|
||||
|
@ -50,6 +51,9 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& oupu
|
|||
|
||||
void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) {
|
||||
|
||||
auto backgroundStage = DependencyManager::get<DeferredLightingEffect>()->getBackgroundStage();
|
||||
backgroundStage->_currentFrame.clear();
|
||||
|
||||
// call render in the correct order first...
|
||||
render::renderItems(context, inputs);
|
||||
|
||||
|
@ -68,37 +72,63 @@ const gpu::PipelinePointer& DebugZoneLighting::getAmbientPipeline() {
|
|||
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));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), ZONE_DEFERRED_TRANSFORM_BUFFER));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), ZONE_AMBIENT_BUFFER));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), ZONE_AMBIENT_MAP));
|
||||
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
|
||||
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
_ambientPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
return _ambientPipeline;
|
||||
}
|
||||
const gpu::PipelinePointer& DebugZoneLighting::getBackgroundPipeline() {
|
||||
if (!_backgroundPipeline) {
|
||||
auto vs = gpu::StandardShaderLib::getDrawTransformUnitQuadVS();
|
||||
auto ps = gpu::Shader::createPixel(std::string(zone_drawSkybox_frag));
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), ZONE_DEFERRED_TRANSFORM_BUFFER));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), ZONE_SKYBOX_MAP));
|
||||
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
|
||||
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
_backgroundPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
return _backgroundPipeline;
|
||||
}
|
||||
|
||||
void DebugZoneLighting::run(const render::RenderContextPointer& context) {
|
||||
void DebugZoneLighting::run(const render::RenderContextPointer& context, const Inputs& inputs) {
|
||||
RenderArgs* args = context->args;
|
||||
|
||||
auto deferredTransform = inputs;
|
||||
|
||||
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()];
|
||||
keyAmbiLight = DependencyManager::get<DeferredLightingEffect>()->getGlobalLight();
|
||||
}
|
||||
|
||||
/* if (lightBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(lightBufferUnit, keySunLight->getLightSchemaBuffer());
|
||||
}*/
|
||||
auto backgroundStage = DependencyManager::get<DeferredLightingEffect>()->getBackgroundStage();
|
||||
model::SkyboxPointer skybox;
|
||||
if (backgroundStage && backgroundStage->_currentFrame._backgrounds.size()) {
|
||||
auto background = backgroundStage->getBackground(backgroundStage->_currentFrame._backgrounds.front());
|
||||
if (background) {
|
||||
skybox = background->getSkybox();
|
||||
}
|
||||
} else {
|
||||
skybox = DependencyManager::get<DeferredLightingEffect>()->getDefaultSkybox();
|
||||
}
|
||||
|
||||
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
|
||||
|
||||
|
@ -108,21 +138,29 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context) {
|
|||
batch.resetViewTransform();
|
||||
|
||||
Transform model;
|
||||
model.setTranslation(glm::vec3(0.0, 0.0, -10.0));
|
||||
batch.setModelTransform(model);
|
||||
model.setTranslation(glm::vec3(-4.0, 0.0, -10.0));
|
||||
|
||||
batch.setUniformBuffer(ZONE_DEFERRED_TRANSFORM_BUFFER, deferredTransform->getFrameTransformBuffer());
|
||||
|
||||
batch.setPipeline(getAmbientPipeline());
|
||||
batch.setModelTransform(model);
|
||||
if (keyAmbiLight) {
|
||||
if (keyAmbiLight->hasAmbient()) {
|
||||
batch.setUniformBuffer(0, keyAmbiLight->getAmbientSchemaBuffer());
|
||||
}
|
||||
batch.setUniformBuffer(ZONE_AMBIENT_BUFFER, keyAmbiLight->getAmbientSchemaBuffer());
|
||||
|
||||
if (keyAmbiLight->getAmbientMap()) {
|
||||
batch.setResourceTexture(0, keyAmbiLight->getAmbientMap());
|
||||
batch.setResourceTexture(ZONE_AMBIENT_MAP, keyAmbiLight->getAmbientMap());
|
||||
}
|
||||
}
|
||||
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
batch.setPipeline(getBackgroundPipeline());
|
||||
model.setTranslation(glm::vec3(-4.0, 3.0, -10.0));
|
||||
batch.setModelTransform(model);
|
||||
if (skybox) {
|
||||
batch.setResourceTexture(ZONE_SKYBOX_MAP, skybox->getCubemap());
|
||||
}
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "render/Engine.h"
|
||||
|
||||
#include "DeferredFrameTransform.h"
|
||||
|
||||
class ZoneRendererConfig : public render::Task::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
|
||||
|
@ -52,14 +54,22 @@ protected:
|
|||
|
||||
class DebugZoneLighting {
|
||||
public:
|
||||
using JobModel = render::Job::Model<DebugZoneLighting>;
|
||||
using Inputs = DeferredFrameTransformPointer;
|
||||
using JobModel = render::Job::ModelI<DebugZoneLighting, Inputs>;
|
||||
|
||||
DebugZoneLighting() {}
|
||||
|
||||
void run(const render::RenderContextPointer& context);
|
||||
void run(const render::RenderContextPointer& context, const Inputs& inputs);
|
||||
|
||||
protected:
|
||||
|
||||
enum Slots {
|
||||
ZONE_DEFERRED_TRANSFORM_BUFFER = 0,
|
||||
ZONE_AMBIENT_BUFFER,
|
||||
ZONE_AMBIENT_MAP,
|
||||
ZONE_SKYBOX_MAP,
|
||||
};
|
||||
|
||||
gpu::PipelinePointer _keyLightPipeline;
|
||||
gpu::PipelinePointer _ambientPipeline;
|
||||
gpu::PipelinePointer _backgroundPipeline;
|
||||
|
|
|
@ -9,14 +9,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredTransform.slh@>
|
||||
<$declareDeferredFrameTransform()$>
|
||||
|
||||
<@include model/Light.slh@>
|
||||
|
||||
<@include LightingModel.slh@>
|
||||
<! <$declareLightBuffer()$> !>
|
||||
<$declareLightAmbientBuffer()$>
|
||||
|
||||
<@include LightAmbient.slh@>
|
||||
<! <@include LightDirectional.slh@> !>
|
||||
|
||||
<$declareLightingAmbient(_SCRIBE_NULL, 1, _SCRIBE_NULL, _SCRIBE_NULL)$>
|
||||
|
||||
|
@ -25,15 +26,42 @@ out vec4 _fragColor;
|
|||
|
||||
void main(void) {
|
||||
|
||||
const float INNER_RADIUS = 1.0;
|
||||
const float INNER_RADIUS2 = INNER_RADIUS * INNER_RADIUS;
|
||||
const float OUTER_RADIUS = 1.05;
|
||||
const float OUTER_RADIUS2 = OUTER_RADIUS * OUTER_RADIUS;
|
||||
vec2 sphereUV = (varTexCoord0.xy * 2.0 - vec2(1.0)) * OUTER_RADIUS;
|
||||
float sphereR2 = dot(sphereUV.xy, sphereUV.xy);
|
||||
if (sphereR2 > OUTER_RADIUS * OUTER_RADIUS) {
|
||||
discard;
|
||||
}
|
||||
if (sphereR2 > INNER_RADIUS2) {
|
||||
float falloff = (sphereR2 - OUTER_RADIUS2) / (OUTER_RADIUS2 - INNER_RADIUS2);
|
||||
_fragColor = vec4(0.0, 0.0, 0.0, falloff * falloff);
|
||||
return;
|
||||
}
|
||||
vec3 spherePos = normalize(vec3(sphereUV, sqrt(1.0 - sphereR2)));
|
||||
|
||||
|
||||
vec3 fragNormal = vec3(getViewInverse() * vec4(spherePos, 0.0));
|
||||
|
||||
|
||||
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);
|
||||
float roughness = 0.1;
|
||||
float levels = getLightAmbientMapNumMips(lightAmbient);
|
||||
float lod = min(((roughness)* levels), levels);
|
||||
vec3 ambientMap = evalSkyboxLight(fragNormal, lod).xyz;
|
||||
vec3 ambientSH = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz;
|
||||
|
||||
// vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz;
|
||||
// _fragColor = vec4( 0.5 * (fragNormal + vec3(1.0)), 1.0);
|
||||
|
||||
vec3 ambient = (sphereUV.x > 0 ? ambientMap : ambientSH);
|
||||
|
||||
const float INV_GAMMA_22 = 1.0 / 2.2;
|
||||
_fragColor = vec4(pow(ambient, vec3(INV_GAMMA_22)), 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
|
54
libraries/render-utils/src/zone_drawSkybox.slf
Normal file
54
libraries/render-utils/src/zone_drawSkybox.slf
Normal file
|
@ -0,0 +1,54 @@
|
|||
<@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 DeferredTransform.slh@>
|
||||
<$declareDeferredFrameTransform()$>
|
||||
|
||||
// declareSkyboxMap
|
||||
uniform samplerCube skyboxMap;
|
||||
|
||||
vec4 evalSkyboxLight(vec3 direction, float lod) {
|
||||
// textureQueryLevels is not available until #430, so we require explicit lod
|
||||
// float mipmapLevel = lod * textureQueryLevels(skyboxMap);
|
||||
return textureLod(skyboxMap, direction, lod);
|
||||
}
|
||||
|
||||
in vec2 varTexCoord0;
|
||||
out vec4 _fragColor;
|
||||
|
||||
void main(void) {
|
||||
|
||||
const float INNER_RADIUS = 1.0;
|
||||
const float INNER_RADIUS2 = INNER_RADIUS * INNER_RADIUS;
|
||||
const float OUTER_RADIUS = 1.05;
|
||||
const float OUTER_RADIUS2 = OUTER_RADIUS * OUTER_RADIUS;
|
||||
vec2 sphereUV = (varTexCoord0.xy * 2.0 - vec2(1.0)) * OUTER_RADIUS;
|
||||
float sphereR2 = dot(sphereUV.xy, sphereUV.xy);
|
||||
if (sphereR2 > OUTER_RADIUS * OUTER_RADIUS) {
|
||||
discard;
|
||||
}
|
||||
if (sphereR2 > INNER_RADIUS2) {
|
||||
float falloff = (sphereR2 - OUTER_RADIUS2) / (OUTER_RADIUS2 - INNER_RADIUS2);
|
||||
_fragColor = vec4(0.0, 0.0, 0.0, falloff * falloff);
|
||||
return;
|
||||
}
|
||||
vec3 spherePos = normalize(vec3(sphereUV, -sqrt(1.0 - sphereR2)));
|
||||
|
||||
vec3 fragNormal = vec3(getViewInverse() * vec4(spherePos, 0.0));
|
||||
|
||||
float lod = 0;
|
||||
vec3 ambient = evalSkyboxLight(fragNormal, lod).xyz;
|
||||
|
||||
const float INV_GAMMA_22 = 1.0 / 2.2;
|
||||
_fragColor = vec4(pow(ambient, vec3(INV_GAMMA_22)), 1.0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue