mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
Creating a separate shader for the locallighting pass
This commit is contained in:
parent
edb456aa8f
commit
665a79f100
3 changed files with 115 additions and 8 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include "directional_ambient_light_shadow_frag.h"
|
#include "directional_ambient_light_shadow_frag.h"
|
||||||
#include "directional_skybox_light_shadow_frag.h"
|
#include "directional_skybox_light_shadow_frag.h"
|
||||||
|
|
||||||
|
#include "local_lights_shading_frag.h"
|
||||||
#include "point_light_frag.h"
|
#include "point_light_frag.h"
|
||||||
#include "spot_light_frag.h"
|
#include "spot_light_frag.h"
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ void DeferredLightingEffect::init() {
|
||||||
loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations);
|
loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations);
|
||||||
loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations);
|
loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations);
|
||||||
|
|
||||||
|
loadLightProgram(deferred_light_vert, local_lights_shading_frag, false, _localLight, _localLightLocations);
|
||||||
loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations);
|
loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations);
|
||||||
loadLightProgram(deferred_light_vert, spot_light_frag, false, _spotLight, _spotLightLocations);
|
loadLightProgram(deferred_light_vert, spot_light_frag, false, _spotLight, _spotLightLocations);
|
||||||
|
|
||||||
|
@ -570,7 +572,7 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderDeferredLocals::RenderDeferredLocals() :
|
RenderDeferredLocals::RenderDeferredLocals() :
|
||||||
_spotLightsBuffer(std::make_shared<gpu::Buffer>()) {
|
_localLightsBuffer(std::make_shared<gpu::Buffer>()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,16 +630,16 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lightIndices[0] > 0) {
|
if (lightIndices[0] > 0) {
|
||||||
_spotLightsBuffer._buffer->setData(lightIndices.size() * sizeof(int), (const gpu::Byte*) lightIndices.data());
|
_localLightsBuffer._buffer->setData(lightIndices.size() * sizeof(int), (const gpu::Byte*) lightIndices.data());
|
||||||
_spotLightsBuffer._size = lightIndices.size() * sizeof(int);
|
_localLightsBuffer._size = lightIndices.size() * sizeof(int);
|
||||||
|
|
||||||
// Spot light pipeline
|
// Spot light pipeline
|
||||||
batch.setPipeline(deferredLightingEffect->_spotLight);
|
batch.setPipeline(deferredLightingEffect->_localLight);
|
||||||
batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->texcoordFrameTransform, 1, reinterpret_cast<const float*>(&textureFrameTransform));
|
batch._glUniform4fv(deferredLightingEffect->_localLightLocations->texcoordFrameTransform, 1, reinterpret_cast<const float*>(&textureFrameTransform));
|
||||||
|
|
||||||
// Bind the global list of lights and the visible lights this frame
|
// Bind the global list of lights and the visible lights this frame
|
||||||
batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightBufferUnit, deferredLightingEffect->getLightStage()._lightArrayBuffer);
|
batch.setUniformBuffer(deferredLightingEffect->_localLightLocations->lightBufferUnit, deferredLightingEffect->getLightStage()._lightArrayBuffer);
|
||||||
batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightIndexBufferUnit, _spotLightsBuffer);
|
batch.setUniformBuffer(deferredLightingEffect->_localLightLocations->lightIndexBufferUnit, _localLightsBuffer);
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,8 @@ private:
|
||||||
gpu::PipelinePointer _directionalAmbientSphereLightShadow;
|
gpu::PipelinePointer _directionalAmbientSphereLightShadow;
|
||||||
gpu::PipelinePointer _directionalLightShadow;
|
gpu::PipelinePointer _directionalLightShadow;
|
||||||
|
|
||||||
|
gpu::PipelinePointer _localLight;
|
||||||
|
|
||||||
gpu::PipelinePointer _pointLight;
|
gpu::PipelinePointer _pointLight;
|
||||||
gpu::PipelinePointer _spotLight;
|
gpu::PipelinePointer _spotLight;
|
||||||
|
|
||||||
|
@ -97,6 +99,7 @@ private:
|
||||||
LightLocationsPtr _directionalAmbientSphereLightShadowLocations;
|
LightLocationsPtr _directionalAmbientSphereLightShadowLocations;
|
||||||
LightLocationsPtr _directionalLightShadowLocations;
|
LightLocationsPtr _directionalLightShadowLocations;
|
||||||
|
|
||||||
|
LightLocationsPtr _localLightLocations;
|
||||||
LightLocationsPtr _pointLightLocations;
|
LightLocationsPtr _pointLightLocations;
|
||||||
LightLocationsPtr _spotLightLocations;
|
LightLocationsPtr _spotLightLocations;
|
||||||
|
|
||||||
|
@ -159,7 +162,7 @@ public:
|
||||||
const LightingModelPointer& lightingModel,
|
const LightingModelPointer& lightingModel,
|
||||||
const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer);
|
const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer);
|
||||||
|
|
||||||
gpu::BufferView _spotLightsBuffer;
|
gpu::BufferView _localLightsBuffer;
|
||||||
|
|
||||||
RenderDeferredLocals();
|
RenderDeferredLocals();
|
||||||
|
|
||||||
|
|
102
libraries/render-utils/src/local_lights_shading.slf
Normal file
102
libraries/render-utils/src/local_lights_shading.slf
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// local_lights_shading.frag
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 9/6/2016.
|
||||||
|
// Copyright 2014 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
|
||||||
|
//
|
||||||
|
|
||||||
|
// Everything about deferred buffer
|
||||||
|
<@include DeferredBufferRead.slh@>
|
||||||
|
|
||||||
|
<$declareDeferredCurvature()$>
|
||||||
|
|
||||||
|
// Everything about light
|
||||||
|
<@include model/Light.slh@>
|
||||||
|
<$declareLightBuffer(32)$>
|
||||||
|
uniform lightIndexBuffer {
|
||||||
|
int lightIndex[32];
|
||||||
|
};
|
||||||
|
<@include LightingModel.slh@>
|
||||||
|
|
||||||
|
<@include LightPoint.slh@>
|
||||||
|
<$declareLightingPoint(supportScattering)$>
|
||||||
|
<@include LightSpot.slh@>
|
||||||
|
<$declareLightingSpot(supportScattering)$>
|
||||||
|
|
||||||
|
in vec4 _texCoord0;
|
||||||
|
out vec4 _fragColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
|
||||||
|
// Grab the fragment data from the uv
|
||||||
|
vec2 texCoord = _texCoord0.st;
|
||||||
|
|
||||||
|
vec4 fragPosition = unpackDeferredPositionFromZeye(texCoord);
|
||||||
|
DeferredFragment frag = unpackDeferredFragmentNoPosition(texCoord);
|
||||||
|
|
||||||
|
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
frag.position = fragPosition;
|
||||||
|
|
||||||
|
vec4 midNormalCurvature;
|
||||||
|
vec4 lowNormalCurvature;
|
||||||
|
if (frag.mode == FRAG_MODE_SCATTERING) {
|
||||||
|
unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Frag pos in world
|
||||||
|
mat4 invViewMat = getViewInverse();
|
||||||
|
vec4 fragPos = invViewMat * fragPosition;
|
||||||
|
|
||||||
|
// Frag to eye vec
|
||||||
|
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||||
|
|
||||||
|
int numLights = lightIndex[0];
|
||||||
|
for (int i = 0; i < numLights; i++) {
|
||||||
|
// Need the light now
|
||||||
|
Light light = getLight(lightIndex[i + 1]);
|
||||||
|
bool isSpot = light_isSpot(light);
|
||||||
|
// Clip againgst the light volume and Make the Light vector going from fragment to light center in world space
|
||||||
|
vec4 fragLightVecLen2;
|
||||||
|
vec4 fragLightDirLen;
|
||||||
|
float cosSpotAngle;
|
||||||
|
if (isSpot) {
|
||||||
|
if (!clipFragToLightVolumeSpot(light, fragPos.xyz, fragLightVecLen2, fragLightDirLen, cosSpotAngle)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!clipFragToLightVolumePoint(light, fragPos.xyz, fragLightVecLen2)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
|
||||||
|
if (isSpot) {
|
||||||
|
evalLightingSpot(diffuse, specular, light,
|
||||||
|
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
|
||||||
|
frag.metallic, frag.fresnel, frag.albedo, 1.0,
|
||||||
|
frag.scattering, midNormalCurvature, lowNormalCurvature);
|
||||||
|
} else {
|
||||||
|
evalLightingPoint(diffuse, specular, light,
|
||||||
|
fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness,
|
||||||
|
frag.metallic, frag.fresnel, frag.albedo, 1.0,
|
||||||
|
frag.scattering, midNormalCurvature, lowNormalCurvature);
|
||||||
|
}
|
||||||
|
|
||||||
|
_fragColor.rgb += diffuse;
|
||||||
|
_fragColor.rgb += specular;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue