mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Adding the drawKeyLight shader
This commit is contained in:
parent
0f250e693d
commit
79f700e8ce
3 changed files with 102 additions and 5 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "DeferredLightingEffect.h"
|
||||
|
||||
#include "zone_drawKeyLight_frag.h"
|
||||
#include "zone_drawAmbient_frag.h"
|
||||
#include "zone_drawSkybox_frag.h"
|
||||
|
||||
|
@ -61,7 +62,21 @@ void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs)
|
|||
|
||||
const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() {
|
||||
if (!_keyLightPipeline) {
|
||||
}
|
||||
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("keylightBuffer"), ZONE_KEYLIGHT_BUFFER));
|
||||
|
||||
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);
|
||||
_keyLightPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
return _keyLightPipeline;
|
||||
}
|
||||
|
||||
|
@ -111,7 +126,14 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I
|
|||
auto deferredTransform = inputs;
|
||||
|
||||
auto lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage();
|
||||
const auto light = lightStage->getLight(0);
|
||||
model::LightPointer keyLight;
|
||||
if (lightStage && lightStage->_currentFrame._sunLights.size()) {
|
||||
keyLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front());
|
||||
}
|
||||
else {
|
||||
keyLight = DependencyManager::get<DeferredLightingEffect>()->getGlobalLight();
|
||||
}
|
||||
|
||||
model::LightPointer keyAmbiLight;
|
||||
if (lightStage && lightStage->_currentFrame._ambientLights.size()) {
|
||||
keyAmbiLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front());
|
||||
|
@ -138,12 +160,20 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I
|
|||
batch.resetViewTransform();
|
||||
|
||||
Transform model;
|
||||
model.setTranslation(glm::vec3(-4.0, 0.0, -10.0));
|
||||
|
||||
batch.setUniformBuffer(ZONE_DEFERRED_TRANSFORM_BUFFER, deferredTransform->getFrameTransformBuffer());
|
||||
|
||||
batch.setPipeline(getKeyLightPipeline());
|
||||
model.setTranslation(glm::vec3(-4.0, -3.0, -10.0));
|
||||
batch.setModelTransform(model);
|
||||
if (keyLight) {
|
||||
batch.setUniformBuffer(ZONE_KEYLIGHT_BUFFER, keyLight->getLightSchemaBuffer());
|
||||
}
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
batch.setPipeline(getAmbientPipeline());
|
||||
batch.setModelTransform(model);
|
||||
model.setTranslation(glm::vec3(-4.0, 0.0, -10.0));
|
||||
batch.setModelTransform(model);
|
||||
if (keyAmbiLight) {
|
||||
batch.setUniformBuffer(ZONE_AMBIENT_BUFFER, keyAmbiLight->getAmbientSchemaBuffer());
|
||||
|
||||
|
|
|
@ -65,7 +65,8 @@ protected:
|
|||
|
||||
enum Slots {
|
||||
ZONE_DEFERRED_TRANSFORM_BUFFER = 0,
|
||||
ZONE_AMBIENT_BUFFER,
|
||||
ZONE_KEYLIGHT_BUFFER,
|
||||
ZONE_AMBIENT_BUFFER,
|
||||
ZONE_AMBIENT_MAP,
|
||||
ZONE_SKYBOX_MAP,
|
||||
};
|
||||
|
|
66
libraries/render-utils/src/zone_drawKeyLight.slf
Normal file
66
libraries/render-utils/src/zone_drawKeyLight.slf
Normal file
|
@ -0,0 +1,66 @@
|
|||
<@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()$>
|
||||
|
||||
<@include model/Light.slh@>
|
||||
|
||||
<@include LightingModel.slh@>
|
||||
<$declareLightBuffer()$>
|
||||
|
||||
<@include LightDirectional.slh@>
|
||||
<$declareLightingDirectional(_SCRIBE_NULL)$>
|
||||
|
||||
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));
|
||||
|
||||
|
||||
LightAmbient lightAmbient = getLightAmbient();
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue