mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 04:42:20 +02:00
Merge pull request #15939 from SamGondelman/shader
Condense directional light shaders using slp defines
This commit is contained in:
commit
2942bfaad0
9 changed files with 38 additions and 194 deletions
|
@ -44,10 +44,10 @@ using namespace render;
|
|||
static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& program);
|
||||
|
||||
void DeferredLightingEffect::init() {
|
||||
loadLightProgram(shader::render_utils::program::directional_ambient_light, false, _directionalAmbientSphereLight);
|
||||
loadLightProgram(shader::render_utils::program::directional_skybox_light_ambient, false, _directionalAmbientSphereLight);
|
||||
loadLightProgram(shader::render_utils::program::directional_skybox_light, false, _directionalSkyboxLight);
|
||||
|
||||
loadLightProgram(shader::render_utils::program::directional_ambient_light_shadow, false, _directionalAmbientSphereLightShadow);
|
||||
loadLightProgram(shader::render_utils::program::directional_skybox_light_ambient_shadow, false, _directionalAmbientSphereLightShadow);
|
||||
loadLightProgram(shader::render_utils::program::directional_skybox_light_shadow, false, _directionalSkyboxLightShadow);
|
||||
|
||||
loadLightProgram(shader::render_utils::program::local_lights_shading, true, _localLight);
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_ambient_light.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/3/14.
|
||||
// Copyright 2016 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 DeferredBufferRead.slh@>
|
||||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
<@include GlobalLight.slh@>
|
||||
<$declareEvalAmbientSphereGlobalColor(supportScattering)$>
|
||||
|
||||
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
||||
#define _texCoord0 _texCoord01.xy
|
||||
#define _texCoord1 _texCoord01.zw
|
||||
layout(location=0) out vec4 _fragColor;
|
||||
|
||||
void main(void) {
|
||||
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0);
|
||||
|
||||
float shadowAttenuation = 1.0;
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||
discard;
|
||||
} else {
|
||||
vec4 midNormalCurvature = vec4(0);
|
||||
vec4 lowNormalCurvature = vec4(0);
|
||||
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
|
||||
float check = float(frag.mode == FRAG_MODE_SCATTERING);
|
||||
midNormalCurvature = check * midNormalCurvature;
|
||||
lowNormalCurvature = check * lowNormalCurvature;
|
||||
|
||||
vec3 color = evalAmbientSphereGlobalColor(
|
||||
getViewInverse(),
|
||||
shadowAttenuation,
|
||||
frag.obscurance,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.albedo,
|
||||
frag.fresnel,
|
||||
frag.metallic,
|
||||
frag.roughness,
|
||||
frag.scattering,
|
||||
midNormalCurvature,
|
||||
lowNormalCurvature);
|
||||
_fragColor = vec4(color, 1.0);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_ambient_light_shadow.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Zach Pomerantz on 1/18/2016.
|
||||
// Copyright 2016 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 DeferredBufferRead.slh@>
|
||||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
<@include GlobalLight.slh@>
|
||||
<$declareEvalAmbientSphereGlobalColor(isScattering)$>
|
||||
|
||||
<@include Shadow.slh@>
|
||||
|
||||
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
||||
#define _texCoord0 _texCoord01.xy
|
||||
#define _texCoord1 _texCoord01.zw
|
||||
layout(location=0) out vec4 _fragColor;
|
||||
|
||||
void main(void) {
|
||||
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0);
|
||||
|
||||
vec4 viewPos = vec4(frag.position.xyz, 1.0);
|
||||
vec4 worldPos = getViewInverse() * viewPos;
|
||||
Light shadowLight = getKeyLight();
|
||||
vec3 worldLightDirection = getLightDirection(shadowLight);
|
||||
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||
discard;
|
||||
} else {
|
||||
vec4 midNormalCurvature = vec4(0);
|
||||
vec4 lowNormalCurvature = vec4(0);
|
||||
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
|
||||
float check = float(frag.mode == FRAG_MODE_SCATTERING);
|
||||
midNormalCurvature = check * midNormalCurvature;
|
||||
lowNormalCurvature = check * lowNormalCurvature;
|
||||
|
||||
vec3 color = evalAmbientSphereGlobalColor(
|
||||
getViewInverse(),
|
||||
shadowAttenuation,
|
||||
frag.obscurance,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.albedo,
|
||||
frag.fresnel,
|
||||
frag.metallic,
|
||||
frag.roughness,
|
||||
frag.scattering,
|
||||
midNormalCurvature,
|
||||
lowNormalCurvature);
|
||||
|
||||
_fragColor = vec4(color, 1.0);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// <$_SCRIBE_FILENAME$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_skybox_light.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 5/8/2015.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
|
@ -15,20 +13,36 @@
|
|||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
<@include GlobalLight.slh@>
|
||||
<$declareEvalSkyboxGlobalColor(isScattering, _SCRIBE_NULL)$>
|
||||
<@if HIFI_USE_AMBIENT@>
|
||||
<$declareEvalAmbientSphereGlobalColor(supportScattering)$>
|
||||
<@else@>
|
||||
<$declareEvalSkyboxGlobalColor(supportScattering, _SCRIBE_NULL)$>
|
||||
<@endif@>
|
||||
|
||||
<@if HIFI_USE_SHADOW@>
|
||||
<@include Shadow.slh@>
|
||||
<@endif@>
|
||||
|
||||
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
||||
#define _texCoord0 _texCoord01.xy
|
||||
#define _texCoord1 _texCoord01.zw
|
||||
|
||||
layout(location=0) out vec4 _fragColor;
|
||||
|
||||
void main(void) {
|
||||
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0);
|
||||
|
||||
<@if HIFI_USE_SHADOW@>
|
||||
vec4 viewPos = vec4(frag.position.xyz, 1.0);
|
||||
vec4 worldPos = getViewInverse() * viewPos;
|
||||
Light shadowLight = getKeyLight();
|
||||
vec3 worldLightDirection = getLightDirection(shadowLight);
|
||||
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
|
||||
<@else@>
|
||||
float shadowAttenuation = 1.0;
|
||||
<@endif@>
|
||||
|
||||
// Light mapped or not ?
|
||||
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||
discard;
|
||||
} else {
|
||||
|
@ -39,6 +53,21 @@ void main(void) {
|
|||
midNormalCurvature = check * midNormalCurvature;
|
||||
lowNormalCurvature = check * lowNormalCurvature;
|
||||
|
||||
<@if HIFI_USE_AMBIENT@>
|
||||
vec3 color = evalAmbientSphereGlobalColor(
|
||||
getViewInverse(),
|
||||
shadowAttenuation,
|
||||
frag.obscurance,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.albedo,
|
||||
frag.fresnel,
|
||||
frag.metallic,
|
||||
frag.roughness,
|
||||
frag.scattering,
|
||||
midNormalCurvature,
|
||||
lowNormalCurvature);
|
||||
<@else@>
|
||||
vec3 color = evalSkyboxGlobalColor(
|
||||
getViewInverse(),
|
||||
shadowAttenuation,
|
||||
|
@ -52,6 +81,7 @@ void main(void) {
|
|||
frag.scattering,
|
||||
midNormalCurvature,
|
||||
lowNormalCurvature);
|
||||
<@endif@>
|
||||
|
||||
_fragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_skybox_light_shadow.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Zach Pomerantz on 1/18/2016.
|
||||
// Copyright 2016 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 DeferredBufferRead.slh@>
|
||||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
<@include GlobalLight.slh@>
|
||||
<$declareEvalSkyboxGlobalColor(isScattering, _SCRIBE_NULL)$>
|
||||
|
||||
<@include Shadow.slh@>
|
||||
|
||||
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
||||
#define _texCoord0 _texCoord01.xy
|
||||
#define _texCoord1 _texCoord01.zw
|
||||
layout(location=0) out vec4 _fragColor;
|
||||
|
||||
void main(void) {
|
||||
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, _texCoord0);
|
||||
|
||||
vec4 viewPos = vec4(frag.position.xyz, 1.0);
|
||||
vec4 worldPos = getViewInverse() * viewPos;
|
||||
Light shadowLight = getKeyLight();
|
||||
vec3 worldLightDirection = getLightDirection(shadowLight);
|
||||
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||
discard;
|
||||
} else {
|
||||
vec4 midNormalCurvature = vec4(0);
|
||||
vec4 lowNormalCurvature = vec4(0);
|
||||
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
|
||||
float check = float(frag.mode == FRAG_MODE_SCATTERING);
|
||||
midNormalCurvature = check * midNormalCurvature;
|
||||
lowNormalCurvature = check * lowNormalCurvature;
|
||||
|
||||
vec3 color = evalSkyboxGlobalColor(
|
||||
getViewInverse(),
|
||||
shadowAttenuation,
|
||||
frag.obscurance,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.albedo,
|
||||
frag.fresnel,
|
||||
frag.metallic,
|
||||
frag.roughness,
|
||||
frag.scattering,
|
||||
midNormalCurvature,
|
||||
lowNormalCurvature);
|
||||
|
||||
|
||||
_fragColor = vec4(color, 1.0);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
VERTEX deferred_light
|
|
@ -1 +0,0 @@
|
|||
VERTEX deferred_light
|
|
@ -1 +1,2 @@
|
|||
VERTEX deferred_light
|
||||
DEFINES ambient:f shadow:f
|
|
@ -1 +0,0 @@
|
|||
VERTEX deferred_light
|
Loading…
Reference in a new issue