From 9d7837dac6d41ce585e2f5e1b7ccfe1bdcc26387 Mon Sep 17 00:00:00 2001 From: yvt Date: Wed, 4 Jan 2017 04:04:29 +0900 Subject: [PATCH] Update GI calculation --- Resources/Shaders/Shadow/Common.fs | 16 +++++++++++----- Resources/Shaders/Shadow/CommonNoSSAO.fs | 8 ++++---- Resources/Shaders/Shadow/MapRadiosity.fs | 12 ++++++++---- Resources/Shaders/Shadow/MapRadiosityLow.fs | 12 ++++++++---- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Resources/Shaders/Shadow/Common.fs b/Resources/Shaders/Shadow/Common.fs index ebadf26c..3f0f5c1c 100644 --- a/Resources/Shaders/Shadow/Common.fs +++ b/Resources/Shaders/Shadow/Common.fs @@ -29,8 +29,8 @@ uniform vec2 ssaoTextureUVScale; float VisibilityOfSunLight_Map(); float VisibilityOfSunLight_Model(); -vec3 Radiosity_Map(float detailAmbientOcclusion); -vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction); +vec3 Radiosity_Map(float detailAmbientOcclusion, float ssao); +vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction, float ssao); float VisibilityOfSunLight() { return VisibilityOfSunLight_Map() * @@ -44,11 +44,17 @@ vec3 EvaluateSunLight(){ vec3 EvaluateAmbientLight(float detailAmbientOcclusion) { #if USE_SSAO float ssao = texture2D(ssaoTexture, gl_FragCoord.xy * ssaoTextureUVScale).x; - detailAmbientOcclusion *= ssao; +#else + float ssao = 1.0; #endif - return Radiosity_Map(detailAmbientOcclusion); + return Radiosity_Map(detailAmbientOcclusion, ssao); } vec3 EvaluateDirectionalAmbientLight(float detailAmbientOcclusion, vec3 direction) { - return BlurredReflection_Map(detailAmbientOcclusion, direction); +#if USE_SSAO + float ssao = texture2D(ssaoTexture, gl_FragCoord.xy * ssaoTextureUVScale).x; +#else + float ssao = 1.0; +#endif + return BlurredReflection_Map(detailAmbientOcclusion, direction, ssao); } diff --git a/Resources/Shaders/Shadow/CommonNoSSAO.fs b/Resources/Shaders/Shadow/CommonNoSSAO.fs index bba65621..b3cc2320 100644 --- a/Resources/Shaders/Shadow/CommonNoSSAO.fs +++ b/Resources/Shaders/Shadow/CommonNoSSAO.fs @@ -22,8 +22,8 @@ float VisibilityOfSunLight_Map(); float VisibilityOfSunLight_Model(); -vec3 Radiosity_Map(float detailAmbientOcclusion); -vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction); +vec3 Radiosity_Map(float detailAmbientOcclusion, float ssao); +vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction, float ssao); float VisibilityOfSunLight() { return VisibilityOfSunLight_Map() * @@ -35,9 +35,9 @@ vec3 EvaluateSunLight(){ } vec3 EvaluateAmbientLight(float detailAmbientOcclusion) { - return Radiosity_Map(detailAmbientOcclusion); + return Radiosity_Map(detailAmbientOcclusion, 1.0); } vec3 EvaluateDirectionalAmbientLight(float detailAmbientOcclusion, vec3 direction) { - return BlurredReflection_Map(detailAmbientOcclusion, direction); + return BlurredReflection_Map(detailAmbientOcclusion, direction, 1.0); } diff --git a/Resources/Shaders/Shadow/MapRadiosity.fs b/Resources/Shaders/Shadow/MapRadiosity.fs index dcaddff8..682a122b 100644 --- a/Resources/Shaders/Shadow/MapRadiosity.fs +++ b/Resources/Shaders/Shadow/MapRadiosity.fs @@ -37,7 +37,7 @@ vec3 DecodeRadiosityValue(vec3 val){ return val; } -vec3 Radiosity_Map(float detailAmbientOcclusion) { +vec3 Radiosity_Map(float detailAmbientOcclusion, float ssao) { vec3 col = DecodeRadiosityValue (texture3D(radiosityTextureFlat, radiosityTextureCoord).xyz); @@ -52,7 +52,9 @@ vec3 Radiosity_Map(float detailAmbientOcclusion) { (texture3D(radiosityTextureZ, radiosityTextureCoord).xyz); col = max(col, 0.); - col *= 1.5; + col *= 1.5 * ssao; + + detailAmbientOcclusion *= ssao; // ambient occlusion float amb = texture3D(ambientShadowTexture, ambientShadowTextureCoord).x; @@ -67,7 +69,7 @@ vec3 Radiosity_Map(float detailAmbientOcclusion) { return col; } -vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction) +vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction, float ssao) { vec3 col = DecodeRadiosityValue (texture3D(radiosityTextureFlat, @@ -83,7 +85,9 @@ vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction) (texture3D(radiosityTextureZ, radiosityTextureCoord).xyz); col = max(col, 0.); - col *= 1.5; + col *= 1.5 * ssao; + + detailAmbientOcclusion *= ssao; // ambient occlusion float amb = texture3D(ambientShadowTexture, ambientShadowTextureCoord).x; diff --git a/Resources/Shaders/Shadow/MapRadiosityLow.fs b/Resources/Shaders/Shadow/MapRadiosityLow.fs index e39d08fe..32d6a98b 100644 --- a/Resources/Shaders/Shadow/MapRadiosityLow.fs +++ b/Resources/Shaders/Shadow/MapRadiosityLow.fs @@ -38,7 +38,7 @@ vec3 DecodeRadiosityValue(vec3 val){ return val; } -vec3 Radiosity_Map(float detailAmbientOcclusion) { +vec3 Radiosity_Map(float detailAmbientOcclusion, float ssao) { vec3 col = DecodeRadiosityValue (texture3D(radiosityTextureFlat, radiosityTextureCoord).xyz); @@ -53,7 +53,9 @@ vec3 Radiosity_Map(float detailAmbientOcclusion) { (texture3D(radiosityTextureZ, radiosityTextureCoord).xyz); col = max(col, 0.); - col *= 1.5; + col *= 1.5 * ssao; + + detailAmbientOcclusion *= ssao; // ambient occlusion float amb = texture3D(ambientShadowTexture, ambientShadowTextureCoord).x; @@ -68,7 +70,7 @@ vec3 Radiosity_Map(float detailAmbientOcclusion) { return col; } -vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction) +vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction, float ssao) { vec3 col = DecodeRadiosityValue (texture3D(radiosityTextureFlat, @@ -84,7 +86,9 @@ vec3 BlurredReflection_Map(float detailAmbientOcclusion, vec3 direction) (texture3D(radiosityTextureZ, radiosityTextureCoord).xyz); col = max(col, 0.); - col *= 1.5; + col *= 1.5 * ssao; + + detailAmbientOcclusion *= ssao; // ambient occlusion float amb = texture3D(ambientShadowTexture, ambientShadowTextureCoord).x;