From 68b2c8c2fbde0fdf58f1ce004c2a9f4bbcbe4f6f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 9 Jul 2019 00:46:24 -0700 Subject: [PATCH] wip adding haze to forward rendering --- libraries/render-utils/src/GlobalLight.slh | 68 +------------------ .../src/directional_ambient_light.slf | 7 +- .../src/directional_ambient_light_shadow.slf | 7 +- .../src/directional_skybox_light.slf | 4 +- .../src/directional_skybox_light_shadow.slf | 8 +-- libraries/render-utils/src/model.slf | 6 +- libraries/render-utils/src/sdf_text3D.slf | 4 +- libraries/render-utils/src/simple.slf | 4 +- .../render-utils/src/simple_procedural.slf | 4 +- 9 files changed, 19 insertions(+), 93 deletions(-) diff --git a/libraries/render-utils/src/GlobalLight.slh b/libraries/render-utils/src/GlobalLight.slh index 1cc357fe5f..1c8914adf3 100644 --- a/libraries/render-utils/src/GlobalLight.slh +++ b/libraries/render-utils/src/GlobalLight.slh @@ -1,5 +1,5 @@ -<@if not HIFI_USE_FORWARD@> <@include Haze.slh@> -<@endif@> <@func declareEvalSkyboxGlobalColor(supportScattering)@> @@ -142,12 +140,10 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu color += directionalDiffuse; color += directionalSpecular; -<@if not HIFI_USE_FORWARD@> // Attenuate the light if haze effect selected if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) { color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS); } -<@endif@> return color; } @@ -184,61 +180,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur <$declareLightingAmbient(1, 1, 1)$> <$declareLightingDirectional()$> -vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) { - <$prepareGlobalLight(position, normal)$> - - SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); - - color += emissive * isEmissiveEnabled(); - - // Ambient - vec3 ambientDiffuse; - vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); - color += ambientDiffuse; - - // Directional - vec3 directionalDiffuse; - vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); - color += directionalDiffuse; - color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); - - return color; -} - -vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity, vec3 prevLighting) { - <$prepareGlobalLight(position, normal)$> - - SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); - - color = prevLighting; - color += emissive * isEmissiveEnabled(); - - // Ambient - vec3 ambientDiffuse; - vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); - color += ambientDiffuse; - - // Directional - vec3 directionalDiffuse; - vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); - color += directionalDiffuse; - color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); - - return color; -} - -<@endfunc@> - -<@func declareEvalGlobalLightingAlphaBlendedWithHaze()@> - -<$declareLightingAmbient(1, 1, 1)$> -<$declareLightingDirectional()$> - -vec3 evalGlobalLightingAlphaBlendedWithHaze( +vec3 evalGlobalLightingAlphaBlended( mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 normalWS, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) { @@ -261,7 +203,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( color += directionalDiffuse; color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); -<@if not HIFI_USE_FORWARD@> // Haze if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { vec4 hazeColor = computeHazeColor( @@ -273,12 +214,11 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( color = mix(color.rgb, hazeColor.rgb, hazeColor.a); } -<@endif@> return color; } -vec3 evalGlobalLightingAlphaBlendedWithHaze( +vec3 evalGlobalLightingAlphaBlended( mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 positionWS, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, SurfaceData surface, float opacity, vec3 prevLighting) { @@ -300,7 +240,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( color += ambientDiffuse + directionalDiffuse; color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); -<@if not HIFI_USE_FORWARD@> // Haze if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { vec4 hazeColor = computeHazeColor( @@ -312,7 +251,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( color = mix(color.rgb, hazeColor.rgb, hazeColor.a); } -<@endif@> return color; } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index ecacff38f6..dd1b59f43e 100644 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -11,15 +11,10 @@ // 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 GlobalLight.slh@> <@include render-utils/ShaderConstants.h@> -<$declareEvalLightmappedColor()$> - +<@include GlobalLight.slh@> <$declareEvalAmbientSphereGlobalColor(supportScattering)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf index c6763eb372..34018125af 100644 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow.slf @@ -11,15 +11,14 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - -<@include Shadow.slh@> <@include DeferredBufferRead.slh@> -<@include GlobalLight.slh@> <@include render-utils/ShaderConstants.h@> -<$declareEvalLightmappedColor()$> +<@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 diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index f6044b2d89..4ef7621b36 100644 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -11,12 +11,10 @@ // 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 GlobalLight.slh@> <@include render-utils/ShaderConstants.h@> -<$declareEvalLightmappedColor()$> +<@include GlobalLight.slh@> <$declareEvalSkyboxGlobalColor(isScattering)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf index 7af0eafd9a..217cf3ba05 100644 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ b/libraries/render-utils/src/directional_skybox_light_shadow.slf @@ -11,15 +11,14 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html //!> - -<@include Shadow.slh@> <@include DeferredBufferRead.slh@> -<@include GlobalLight.slh@> <@include render-utils/ShaderConstants.h@> -<$declareEvalLightmappedColor()$> +<@include GlobalLight.slh@> <$declareEvalSkyboxGlobalColor(isScattering)$> +<@include Shadow.slh@> + layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw @@ -35,7 +34,6 @@ void main(void) { vec3 worldLightDirection = getLightDirection(shadowLight); float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); - // Light mapped or not ? if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { diff --git a/libraries/render-utils/src/model.slf b/libraries/render-utils/src/model.slf index 374248765d..b3167dd598 100644 --- a/libraries/render-utils/src/model.slf +++ b/libraries/render-utils/src/model.slf @@ -23,10 +23,8 @@ <@elif HIFI_USE_TRANSLUCENT@> <@if not HIFI_USE_FORWARD@> <@include LightLocal.slh@> - <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> - <@else@> - <$declareEvalGlobalLightingAlphaBlended()$> <@endif@> + <$declareEvalGlobalLightingAlphaBlended()$> <@else@> <$declareEvalSkyboxGlobalColor()$> <@endif@> @@ -298,7 +296,7 @@ void main(void) { vec4(0), vec4(0), opacity); } - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + _fragColor0 = vec4(evalGlobalLightingAlphaBlended( cam._viewInverse, 1.0, occlusion, diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index c56c8b6436..a5a7cfb6a4 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -16,7 +16,7 @@ <@if HIFI_USE_FORWARD@> <$declareEvalSkyboxGlobalColor()$> <@else@> - <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> + <$declareEvalGlobalLightingAlphaBlended()$> <@endif@> <@include gpu/Transform.slh@> @@ -78,7 +78,7 @@ void main() { DEFAULT_ROUGHNESS), alpha); <@else@> - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + _fragColor0 = vec4(evalGlobalLightingAlphaBlended( cam._viewInverse, 1.0, DEFAULT_OCCLUSION, diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index ce063cd7e7..ac7deedff0 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -31,7 +31,7 @@ <$declareEvalSkyboxGlobalColor()$> <@elif HIFI_USE_TRANSLUCENT@> <@include GlobalLight.slh@> - <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> + <$declareEvalGlobalLightingAlphaBlended()$> <@else@> <@include DeferredBufferWrite.slh@> <@endif@> @@ -101,7 +101,7 @@ void main(void) { DEFAULT_ROUGHNESS), texel.a); <@elif HIFI_USE_TRANSLUCENT@> - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + _fragColor0 = vec4(evalGlobalLightingAlphaBlended( cam._viewInverse, 1.0, DEFAULT_OCCLUSION, diff --git a/libraries/render-utils/src/simple_procedural.slf b/libraries/render-utils/src/simple_procedural.slf index ae5b72012f..5b0eb62cca 100644 --- a/libraries/render-utils/src/simple_procedural.slf +++ b/libraries/render-utils/src/simple_procedural.slf @@ -16,7 +16,7 @@ <@include DefaultMaterials.slh@> <@include GlobalLight.slh@> - <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> + <$declareEvalGlobalLightingAlphaBlended()$> layout(location=0) out vec4 _fragColor0; <@endif@> @@ -167,7 +167,7 @@ void main(void) { if (emissiveAmount > 0.0) { _fragColor0 = vec4(diffuse, alpha); } else { - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + _fragColor0 = vec4(evalGlobalLightingAlphaBlended( cam._viewInverse, 1.0, occlusion,