diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index 7d6aead855..12bc00855c 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -135,7 +135,14 @@ vec4 fetchDiffusedCurvature(vec2 texcoord) { return texture(diffusedCurvatureMap, texcoord); } - +void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 vec4 lowNormalCurvature) { + midNormalCurvature = fetchCurvature(_texCoord0); + lowNormalCurvature = fetchDiffusedCurvature(_texCoord0); + midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f); + lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f); + midNormalCurvature.w = (midNormalCurvature.w * 2 - 1); + lowNormalCurvature.w = (lowNormalCurvature.w * 2 - 1); +} <@endfunc@> <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 8247554920..93c0557577 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -60,7 +60,8 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc <$declareLightingAmbient(1, 0, 0, supportScattering)$> <$declareLightingDirectional(supportScattering)$> -vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) { +vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, + vec3 albedo, float metallic, vec3 emissive, float roughness) { <$prepareGlobalLight()$> @@ -86,22 +87,18 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa <$declareDeferredCurvature()$> -vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 blurredCurvature, vec4 diffusedCurvature) { +vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, + vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) { <$prepareGlobalLight(1)$> - vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f); - vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f); - float highCurvature = unpackCurvature(blurredCurvature.w); - float lowCurvature = unpackCurvature(diffusedCurvature.w); - // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance, - isScatteringEnabled() * scattering, lowNormal, highCurvature, lowCurvature); + isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature); color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); @@ -112,7 +109,7 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation, - isScatteringEnabled() * scattering, midNormal, lowNormal, lowCurvature); + isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature); color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); @@ -157,12 +154,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 blurredCurvature, vec4 diffusedCurvature) { <$prepareGlobalLight(1)$> - vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f); - vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f); - float highCurvature = unpackCurvature(blurredCurvature.w); - float lowCurvature = unpackCurvature(diffusedCurvature.w); - - // Ambient + // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light, @@ -178,7 +170,7 @@ vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, f evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation, - isScatteringEnabled() * scattering, midNormal, lowNormal, lowCurvature); + isScatteringEnabled() * scattering, , midNormalCurvature, lowNormalCurvature); color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); diff --git a/libraries/render-utils/src/LightDirectional.slh b/libraries/render-utils/src/LightDirectional.slh index b7dd1f3c61..13a97a115f 100644 --- a/libraries/render-utils/src/LightDirectional.slh +++ b/libraries/render-utils/src/LightDirectional.slh @@ -18,9 +18,11 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light, vec4 shading = evalFragShading(normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness); - diffuse = albedo * shading.w * shadow * getLightColor(light) * getLightIntensity(light); + vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); - specular = shading.rgb * shadow * getLightColor(light) * getLightIntensity(light); + diffuse = albedo * shading.w * lightEnergy; + + specular = shading.rgb * lightEnergy; } <@if supportScattering@> @@ -28,14 +30,14 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light, void evalLightingDirectionalScattering(out vec3 diffuse, out vec3 specular, Light light, vec3 eyeDir, vec3 normal, float roughness, float metallic, vec3 fresnel, vec3 albedo, float shadow, - float scattering, vec3 midNormal, vec3 lowNormal, float curvature) { + float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) { vec3 fragLightDir = -normalize(getLightDirection(light)); evalFragShading(diffuse, specular, normal, fragLightDir, eyeDir, metallic, fresnel, roughness, - scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature)); + scattering, midNormalCurvature, lowNormalCurvature); vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index f5d23bba1a..dc32149dc9 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -64,7 +64,7 @@ void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light ligh evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, - scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature)); + scattering, midNormalCurvature, lowNormalCurvature); diffuse *= albedo * lightEnergy; diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 0a03789dce..ece9280267 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -64,7 +64,7 @@ void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, - scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature)); + scattering, midNormalCurvature, lowNormalCurvature); diffuse *= albedo * lightEnergy; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index e8ccffa030..b9847149b9 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -39,10 +39,12 @@ void main(void) { frag.diffuse, frag.specularVal.xyz); _fragColor = vec4(color, 1.0); - } else { //if (frag.mode == FRAG_MODE_SCATTERING) { - - vec4 blurredCurvature = fetchCurvature(_texCoord0); - vec4 diffusedCurvature = fetchDiffusedCurvature(_texCoord0); + } else { + vec4 midNormalCurvature; + vec4 lowNormalCurvature; + if (frag.mode == FRAG_MODE_SCATTERING) { + unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature); + } vec3 color = evalAmbientSphereGlobalColorScattering( getViewInverse(), @@ -55,20 +57,9 @@ void main(void) { frag.emissive, frag.roughness, frag.scattering, - blurredCurvature, - diffusedCurvature); + midNormalCurvature, + lowNormalCurvature); _fragColor = vec4(color, 1.0); - /* } else { - vec3 color = evalAmbientSphereGlobalColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.metallic, - frag.emissive, - frag.roughness); - _fragColor = vec4(color, frag.normalVal.a);*/ + } } diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 851bc026e3..ffafc56eb2 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -39,11 +39,12 @@ void main(void) { frag.diffuse, frag.specularVal.xyz); _fragColor = vec4(color, 1.0); - } else {// if (frag.mode == FRAG_MODE_SCATTERING) { - - vec4 blurredCurvature = fetchCurvature(_texCoord0); - vec4 diffusedCurvature = fetchDiffusedCurvature(_texCoord0); - + } else { + vec4 midNormalCurvature; + vec4 lowNormalCurvature; + if (frag.mode == FRAG_MODE_SCATTERING) { + unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature); + } vec3 color = evalSkyboxGlobalColorScattering( getViewInverse(), shadowAttenuation, @@ -55,22 +56,8 @@ void main(void) { frag.emissive, frag.roughness, frag.scattering, - blurredCurvature, - diffusedCurvature); + midNormalCurvature, + lowNormalCurvature); _fragColor = vec4(color, 1.0); - /* } else { - vec3 color = evalSkyboxGlobalColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.position.xyz, - frag.normal, - frag.diffuse, - frag.metallic, - frag.emissive, - frag.roughness); - - _fragColor = vec4(color, frag.normalVal.a); - */ } }