Skip to content

Commit

Permalink
Simplified day/night blending
Browse files Browse the repository at this point in the history
* Added an option to provide different scattering values for day and night
* Adjust post effects for the default world
* Disabled noise for the volumetric fog
  • Loading branch information
Benjamin Glatzel committed Jun 9, 2017
1 parent 3966011 commit 5ea8d67
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 214 deletions.
33 changes: 17 additions & 16 deletions IntrinsicCore/src/IntrinsicCoreResourcesPostEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct PostEffectData : Dod::Resources::ResourceDataBase
PostEffectData()
: Dod::Resources::ResourceDataBase(_INTR_MAX_POST_EFFECT_COUNT)
{
descVolumetricLightingScattering.resize(_INTR_MAX_POST_EFFECT_COUNT);
descVolumetricLightingScatteringDayNight.resize(
_INTR_MAX_POST_EFFECT_COUNT);

descSunOrientation.resize(_INTR_MAX_POST_EFFECT_COUNT);

Expand All @@ -43,7 +44,7 @@ struct PostEffectData : Dod::Resources::ResourceDataBase

// <-

_INTR_ARRAY(float) descVolumetricLightingScattering;
_INTR_ARRAY(glm::vec2) descVolumetricLightingScatteringDayNight;

_INTR_ARRAY(glm::quat) descSunOrientation;

Expand Down Expand Up @@ -75,7 +76,7 @@ struct PostEffectManager

_INTR_INLINE static void resetToDefault(PostEffectRef p_Ref)
{
_descVolumetricLightingScattering(p_Ref) = 0.0f;
_descVolumetricLightingScatteringDayNight(p_Ref) = glm::vec2(0.0f);
_descSunOrientation(p_Ref) = glm::quat();
_descSunIntensity(p_Ref) = 20.0f;
_descDayNightFactor(p_Ref) = 1.0f;
Expand Down Expand Up @@ -107,10 +108,10 @@ struct PostEffectManager
p_Document);

p_Properties.AddMember(
"scattering",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(VolumetricLighting),
_N(float), _descVolumetricLightingScattering(p_Ref),
false, false),
"scatteringDayNight",
_INTR_CREATE_PROP(
p_Document, p_GenerateDesc, _N(VolumetricLighting), _N(vec2),
_descVolumetricLightingScatteringDayNight(p_Ref), false, false),
p_Document.GetAllocator());

p_Properties.AddMember("sunOrientation",
Expand Down Expand Up @@ -162,9 +163,9 @@ struct PostEffectManager
PostEffectData,
_INTR_MAX_POST_EFFECT_COUNT>::_initFromDescriptor(p_Ref, p_Properties);

if (p_Properties.HasMember("scattering"))
_descVolumetricLightingScattering(p_Ref) =
JsonHelper::readPropertyFloat(p_Properties["scattering"]);
if (p_Properties.HasMember("scatteringDayNight"))
_descVolumetricLightingScatteringDayNight(p_Ref) =
JsonHelper::readPropertyVec2(p_Properties["scatteringDayNight"]);

if (p_Properties.HasMember("sunOrientation"))
_descSunOrientation(p_Ref) =
Expand Down Expand Up @@ -230,9 +231,9 @@ struct PostEffectManager
Dod::Ref p_Right,
float p_BlendFactor)
{
_descVolumetricLightingScattering(p_Target) =
glm::mix(_descVolumetricLightingScattering(p_Left),
_descVolumetricLightingScattering(p_Right), p_BlendFactor);
_descVolumetricLightingScatteringDayNight(p_Target) = glm::mix(
_descVolumetricLightingScatteringDayNight(p_Left),
_descVolumetricLightingScatteringDayNight(p_Right), p_BlendFactor);

_descSunOrientation(p_Target) =
glm::slerp(_descSunOrientation(p_Left), _descSunOrientation(p_Right),
Expand Down Expand Up @@ -261,10 +262,10 @@ struct PostEffectManager
// ->

// Description
_INTR_INLINE static float&
_descVolumetricLightingScattering(PostEffectRef p_Ref)
_INTR_INLINE static glm::vec2&
_descVolumetricLightingScatteringDayNight(PostEffectRef p_Ref)
{
return _data.descVolumetricLightingScattering[p_Ref._id];
return _data.descVolumetricLightingScatteringDayNight[p_Ref._id];
}

_INTR_INLINE static glm::quat& _descSunOrientation(PostEffectRef p_Ref)
Expand Down
33 changes: 7 additions & 26 deletions IntrinsicCore/src/IntrinsicCoreWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,39 +479,20 @@ void World::updateDayNightCycle(float p_DeltaT)
}

static const float dayNightCycleDurationInS = 20.0f * 60.0f;
static const float dayNightFadeInPerc = 0.1f;
static const float dayNightFadeInPerc = 0.05f;
static const float nightLightIntens = 0.05f;

_currentTime += p_DeltaT / dayNightCycleDurationInS;
_currentTime = glm::mod(_currentTime, 1.0f);
_currentTime = glm::mod(_currentTime, 0.99f);

float currentDayNightFactor = 0.0f;
float currentPerc = 0.0f;
if (_currentTime < 0.5f)
{
const float dayPerc = _currentTime / 0.5f;
currentPerc = dayPerc;

if (_currentTime < dayNightFadeInPerc)
{
currentDayNightFactor = _currentTime / dayNightFadeInPerc;
}
else if (_currentTime > 0.5f - dayNightFadeInPerc)
{
currentDayNightFactor =
1.0f -
(_currentTime - (0.5f - dayNightFadeInPerc)) / dayNightFadeInPerc;
}
else
{
currentDayNightFactor = 1.0f;
}
}
else
{
const float nightPerc = (_currentTime - 0.5f) / 0.5f;
currentDayNightFactor = 0.0f;
currentPerc = nightPerc;
const float perc = _currentTime / 0.5f;
currentDayNightFactor =
1.0f - glm::smoothstep<float>(1.0f - dayNightFadeInPerc, 1.0f, perc);
currentDayNightFactor *=
glm::smoothstep<float>(0.0f, dayNightFadeInPerc, perc);
}

const float sunAngleRad =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ updatePerInstanceData(Components::CameraRef p_CameraRef,

// Post effect data
{
const glm::vec2 scattering = Core::Resources::PostEffectManager::
_descVolumetricLightingScatteringDayNight(
Core::Resources::PostEffectManager::_blendTargetRef);

_perInstanceData.data0.x =
Core::Resources::PostEffectManager::_descVolumetricLightingScattering(
Core::Resources::PostEffectManager::_blendTargetRef) *
glm::mix(scattering.y, scattering.x, World::_currentDayNightFactor) *
VolumetricLighting::_globalScatteringFactor;
_perInstanceData.data0.z = Clustering::_globalAmbientFactor;
}
Expand Down
20 changes: 11 additions & 9 deletions app/assets/shaders/volumetric_lighting.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,24 @@ void main()
vec3 finalHeightPos = heightRefPosWS;

// Noise
#if 1
#if 0
float noiseAccum = 1.0;
noiseAccum *= noise(posWS * clamp(5.0 / linDepth, 0.005, 0.08) + uboPerInstance.eyeWSVectorX.w * 0.5);
noiseAccum *= noise(posWS * clamp(10.0 / linDepth, 0.005, 0.08) + uboPerInstance.eyeWSVectorX.w * 0.75 + 0.382871);
density *= clamp(noiseAccum, 0.0, 1.0);
//finalHeightPos.y -= noise(posWS * clamp(10.0 / linDepth, 0.005, 0.08) + uboPerInstance.eyeWSVectorX.w * 0.75 + 0.75827618) * 50.0;
noiseAccum *= noise(posWS * clamp(5.0 / linDepth, 0.005, 0.08)
+ uboPerInstance.eyeWSVectorX.w * 0.5);
noiseAccum *= noise(posWS * clamp(10.0 / linDepth, 0.005, 0.08)
+ uboPerInstance.eyeWSVectorX.w * 0.75 + 0.382871);
density *= clamp(noiseAccum * 0.5 + 0.5, 0.0, 1.0);
#endif

const float heightAttenuation = 1.0 - clamp(exp(-(finalHeightPos.y - posWS.y) * heightAttenuationFactor), 0.0, 1.0);
const float heightAttenuation = 1.0 -
clamp(exp(-(finalHeightPos.y - posWS.y) * heightAttenuationFactor), 0.0, 1.0);
density *= heightAttenuation;

// Lighting
vec3 lighting = vec3(0.0);

if (density > EPSILON)
// Sunlight
{
// Sunlight
vec4 posLS;
uint shadowMapIdx = findBestFittingSplit(posVS.xyz, posLS, uboPerInstance.shadowViewProjMatrix);

Expand All @@ -149,7 +150,8 @@ void main()
shadowAttenuation = clamp(calculateShadowESM(shadowSample, posLS.z)*1.1 - 0.1, 0.0, 1.0);
}

const vec3 lightColor = uboPerFrame.sunLightColorAndIntensity.xyz * uboPerFrame.sunLightColorAndIntensity.w;
const vec3 lightColor = uboPerFrame.sunLightColorAndIntensity.xyz
* uboPerFrame.sunLightColorAndIntensity.w;
lighting += shadowAttenuation * lightColor;
}

Expand Down
5 changes: 4 additions & 1 deletion app/managers/post_effects/Default.post_effect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "Default",
"properties": {
"name": "Default",
"scattering": 0.0,
"scatteringDayNight": [
0.0,
0.0
],
"sunOrientation": [
0.0,
0.0,
Expand Down
19 changes: 0 additions & 19 deletions app/managers/post_effects/Foggy.post_effect.json

This file was deleted.

5 changes: 4 additions & 1 deletion app/managers/post_effects/IrradianceTest.post_effect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "IrradianceTest",
"properties": {
"name": "IrradianceTest",
"scattering": 0.0,
"scatteringDayNight": [
0.0,
0.0
],
"sunOrientation": [
0.0,
0.0,
Expand Down
5 changes: 4 additions & 1 deletion app/managers/post_effects/LightingTest.post_effect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "LightingTest",
"properties": {
"name": "LightingTest",
"scattering": 0.0010000000474974514,
"scatteringDayNight": [
0.0,
0.0
],
"sunOrientation": [
0.0,
0.0,
Expand Down
5 changes: 4 additions & 1 deletion app/managers/post_effects/Town.post_effect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "Town",
"properties": {
"name": "Town",
"scattering": 0.0008999999845400453,
"scatteringDayNight": [
0.00019999999494757503,
0.00800000037997961
],
"sunOrientation": [
0.0,
0.0,
Expand Down
Loading

0 comments on commit 5ea8d67

Please sign in to comment.