From 965feb6f7a97243e2e9b7facc03e8c03ec0f0be7 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 16 Jul 2019 11:24:19 -0700 Subject: [PATCH] condense direction light shaders using slp defines --- .../src/DeferredLightingEffect.cpp | 4 +- .../src/directional_ambient_light.slf | 57 ----------------- .../src/directional_ambient_light_shadow.slf | 63 ------------------ .../src/directional_skybox_light.slf | 40 ++++++++++-- .../src/directional_skybox_light_shadow.slf | 64 ------------------- .../directional_ambient_light.slp | 1 - .../directional_ambient_light_shadow.slp | 1 - .../render-utils/directional_skybox_light.slp | 1 + .../directional_skybox_light_shadow.slp | 1 - 9 files changed, 38 insertions(+), 194 deletions(-) delete mode 100644 libraries/render-utils/src/directional_ambient_light.slf delete mode 100644 libraries/render-utils/src/directional_ambient_light_shadow.slf delete mode 100644 libraries/render-utils/src/directional_skybox_light_shadow.slf delete mode 100644 libraries/render-utils/src/render-utils/directional_ambient_light.slp delete mode 100644 libraries/render-utils/src/render-utils/directional_ambient_light_shadow.slp delete mode 100644 libraries/render-utils/src/render-utils/directional_skybox_light_shadow.slp diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 3b7c66d42d..8d7fc345ac 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -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); diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf deleted file mode 100644 index dd1b59f43e..0000000000 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ /dev/null @@ -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); - - } -} diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf deleted file mode 100644 index 34018125af..0000000000 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ /dev/null @@ -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); - } -} diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 8e2b38b478..20026283be 100644 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -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); } diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf deleted file mode 100644 index 2f289ed00f..0000000000 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ /dev/null @@ -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); - } -} diff --git a/libraries/render-utils/src/render-utils/directional_ambient_light.slp b/libraries/render-utils/src/render-utils/directional_ambient_light.slp deleted file mode 100644 index 3aeca942ab..0000000000 --- a/libraries/render-utils/src/render-utils/directional_ambient_light.slp +++ /dev/null @@ -1 +0,0 @@ -VERTEX deferred_light diff --git a/libraries/render-utils/src/render-utils/directional_ambient_light_shadow.slp b/libraries/render-utils/src/render-utils/directional_ambient_light_shadow.slp deleted file mode 100644 index 3aeca942ab..0000000000 --- a/libraries/render-utils/src/render-utils/directional_ambient_light_shadow.slp +++ /dev/null @@ -1 +0,0 @@ -VERTEX deferred_light diff --git a/libraries/render-utils/src/render-utils/directional_skybox_light.slp b/libraries/render-utils/src/render-utils/directional_skybox_light.slp index 3aeca942ab..7e0a0dd1db 100644 --- a/libraries/render-utils/src/render-utils/directional_skybox_light.slp +++ b/libraries/render-utils/src/render-utils/directional_skybox_light.slp @@ -1 +1,2 @@ VERTEX deferred_light +DEFINES ambient:f shadow:f \ No newline at end of file diff --git a/libraries/render-utils/src/render-utils/directional_skybox_light_shadow.slp b/libraries/render-utils/src/render-utils/directional_skybox_light_shadow.slp deleted file mode 100644 index 3aeca942ab..0000000000 --- a/libraries/render-utils/src/render-utils/directional_skybox_light_shadow.slp +++ /dev/null @@ -1 +0,0 @@ -VERTEX deferred_light