wip adding haze to forward rendering

This commit is contained in:
SamGondelman 2019-07-09 00:46:24 -07:00
parent 41e8a08484
commit 68b2c8c2fb
9 changed files with 19 additions and 93 deletions

View file

@ -1,5 +1,5 @@
<! <!
// DeferredGlobalLight.slh // GlobalLight.slh
// libraries/render-utils/src // libraries/render-utils/src
// //
// Created by Sam Gateau on 2/5/15. // Created by Sam Gateau on 2/5/15.
@ -98,9 +98,7 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
<@endfunc@> <@endfunc@>
<@if not HIFI_USE_FORWARD@>
<@include Haze.slh@> <@include Haze.slh@>
<@endif@>
<@func declareEvalSkyboxGlobalColor(supportScattering)@> <@func declareEvalSkyboxGlobalColor(supportScattering)@>
@ -142,12 +140,10 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
color += directionalDiffuse; color += directionalDiffuse;
color += directionalSpecular; color += directionalSpecular;
<@if not HIFI_USE_FORWARD@>
// Attenuate the light if haze effect selected // Attenuate the light if haze effect selected
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) { if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS); color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS);
} }
<@endif@>
return color; return color;
} }
@ -184,61 +180,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
<$declareLightingAmbient(1, 1, 1)$> <$declareLightingAmbient(1, 1, 1)$>
<$declareLightingDirectional()$> <$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) { vec3 evalGlobalLightingAlphaBlended(
<$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(
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 normalWS, mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 normalWS,
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity)
{ {
@ -261,7 +203,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
color += directionalDiffuse; color += directionalDiffuse;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
<@if not HIFI_USE_FORWARD@>
// Haze // Haze
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
vec4 hazeColor = computeHazeColor( vec4 hazeColor = computeHazeColor(
@ -273,12 +214,11 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
color = mix(color.rgb, hazeColor.rgb, hazeColor.a); color = mix(color.rgb, hazeColor.rgb, hazeColor.a);
} }
<@endif@>
return color; return color;
} }
vec3 evalGlobalLightingAlphaBlendedWithHaze( vec3 evalGlobalLightingAlphaBlended(
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 positionWS, mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 positionWS,
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, SurfaceData surface, float opacity, vec3 prevLighting) vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, SurfaceData surface, float opacity, vec3 prevLighting)
{ {
@ -300,7 +240,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
color += ambientDiffuse + directionalDiffuse; color += ambientDiffuse + directionalDiffuse;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
<@if not HIFI_USE_FORWARD@>
// Haze // Haze
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
vec4 hazeColor = computeHazeColor( vec4 hazeColor = computeHazeColor(
@ -312,7 +251,6 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
color = mix(color.rgb, hazeColor.rgb, hazeColor.a); color = mix(color.rgb, hazeColor.rgb, hazeColor.a);
} }
<@endif@>
return color; return color;
} }

View file

@ -11,15 +11,10 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include DeferredBufferRead.slh@> <@include DeferredBufferRead.slh@>
<@include GlobalLight.slh@>
<@include render-utils/ShaderConstants.h@> <@include render-utils/ShaderConstants.h@>
<$declareEvalLightmappedColor()$> <@include GlobalLight.slh@>
<$declareEvalAmbientSphereGlobalColor(supportScattering)$> <$declareEvalAmbientSphereGlobalColor(supportScattering)$>
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;

View file

@ -11,15 +11,14 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include Shadow.slh@>
<@include DeferredBufferRead.slh@> <@include DeferredBufferRead.slh@>
<@include GlobalLight.slh@>
<@include render-utils/ShaderConstants.h@> <@include render-utils/ShaderConstants.h@>
<$declareEvalLightmappedColor()$> <@include GlobalLight.slh@>
<$declareEvalAmbientSphereGlobalColor(isScattering)$> <$declareEvalAmbientSphereGlobalColor(isScattering)$>
<@include Shadow.slh@>
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
#define _texCoord0 _texCoord01.xy #define _texCoord0 _texCoord01.xy
#define _texCoord1 _texCoord01.zw #define _texCoord1 _texCoord01.zw

View file

@ -11,12 +11,10 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include DeferredBufferRead.slh@> <@include DeferredBufferRead.slh@>
<@include GlobalLight.slh@>
<@include render-utils/ShaderConstants.h@> <@include render-utils/ShaderConstants.h@>
<$declareEvalLightmappedColor()$> <@include GlobalLight.slh@>
<$declareEvalSkyboxGlobalColor(isScattering)$> <$declareEvalSkyboxGlobalColor(isScattering)$>
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;

View file

@ -11,15 +11,14 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//!> //!>
<@include Shadow.slh@>
<@include DeferredBufferRead.slh@> <@include DeferredBufferRead.slh@>
<@include GlobalLight.slh@>
<@include render-utils/ShaderConstants.h@> <@include render-utils/ShaderConstants.h@>
<$declareEvalLightmappedColor()$> <@include GlobalLight.slh@>
<$declareEvalSkyboxGlobalColor(isScattering)$> <$declareEvalSkyboxGlobalColor(isScattering)$>
<@include Shadow.slh@>
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
#define _texCoord0 _texCoord01.xy #define _texCoord0 _texCoord01.xy
#define _texCoord1 _texCoord01.zw #define _texCoord1 _texCoord01.zw
@ -35,7 +34,6 @@ void main(void) {
vec3 worldLightDirection = getLightDirection(shadowLight); vec3 worldLightDirection = getLightDirection(shadowLight);
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
discard; discard;
} else { } else {

View file

@ -23,10 +23,8 @@
<@elif HIFI_USE_TRANSLUCENT@> <@elif HIFI_USE_TRANSLUCENT@>
<@if not HIFI_USE_FORWARD@> <@if not HIFI_USE_FORWARD@>
<@include LightLocal.slh@> <@include LightLocal.slh@>
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$>
<@else@>
<$declareEvalGlobalLightingAlphaBlended()$>
<@endif@> <@endif@>
<$declareEvalGlobalLightingAlphaBlended()$>
<@else@> <@else@>
<$declareEvalSkyboxGlobalColor()$> <$declareEvalSkyboxGlobalColor()$>
<@endif@> <@endif@>
@ -298,7 +296,7 @@ void main(void) {
vec4(0), vec4(0), opacity); vec4(0), vec4(0), opacity);
} }
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( _fragColor0 = vec4(evalGlobalLightingAlphaBlended(
cam._viewInverse, cam._viewInverse,
1.0, 1.0,
occlusion, occlusion,

View file

@ -16,7 +16,7 @@
<@if HIFI_USE_FORWARD@> <@if HIFI_USE_FORWARD@>
<$declareEvalSkyboxGlobalColor()$> <$declareEvalSkyboxGlobalColor()$>
<@else@> <@else@>
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$> <$declareEvalGlobalLightingAlphaBlended()$>
<@endif@> <@endif@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
@ -78,7 +78,7 @@ void main() {
DEFAULT_ROUGHNESS), DEFAULT_ROUGHNESS),
alpha); alpha);
<@else@> <@else@>
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( _fragColor0 = vec4(evalGlobalLightingAlphaBlended(
cam._viewInverse, cam._viewInverse,
1.0, 1.0,
DEFAULT_OCCLUSION, DEFAULT_OCCLUSION,

View file

@ -31,7 +31,7 @@
<$declareEvalSkyboxGlobalColor()$> <$declareEvalSkyboxGlobalColor()$>
<@elif HIFI_USE_TRANSLUCENT@> <@elif HIFI_USE_TRANSLUCENT@>
<@include GlobalLight.slh@> <@include GlobalLight.slh@>
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$> <$declareEvalGlobalLightingAlphaBlended()$>
<@else@> <@else@>
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@endif@> <@endif@>
@ -101,7 +101,7 @@ void main(void) {
DEFAULT_ROUGHNESS), DEFAULT_ROUGHNESS),
texel.a); texel.a);
<@elif HIFI_USE_TRANSLUCENT@> <@elif HIFI_USE_TRANSLUCENT@>
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( _fragColor0 = vec4(evalGlobalLightingAlphaBlended(
cam._viewInverse, cam._viewInverse,
1.0, 1.0,
DEFAULT_OCCLUSION, DEFAULT_OCCLUSION,

View file

@ -16,7 +16,7 @@
<@include DefaultMaterials.slh@> <@include DefaultMaterials.slh@>
<@include GlobalLight.slh@> <@include GlobalLight.slh@>
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$> <$declareEvalGlobalLightingAlphaBlended()$>
layout(location=0) out vec4 _fragColor0; layout(location=0) out vec4 _fragColor0;
<@endif@> <@endif@>
@ -167,7 +167,7 @@ void main(void) {
if (emissiveAmount > 0.0) { if (emissiveAmount > 0.0) {
_fragColor0 = vec4(diffuse, alpha); _fragColor0 = vec4(diffuse, alpha);
} else { } else {
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( _fragColor0 = vec4(evalGlobalLightingAlphaBlended(
cam._viewInverse, cam._viewInverse,
1.0, 1.0,
occlusion, occlusion,