Skip to content

Commit 1ceb042

Browse files
authored
Merge pull request #630 from DR-Aeronautics/sky-color
Sky Color Fix (Addresses Trello Roadmap Card #367 for More accurate sunrise and sunset)
2 parents 567f7ca + 704731a commit 1ceb042

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

Source/RunActivity/Content/ParticleEmitterShader.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void _PSApplyDay2Night(inout float3 Color)
141141
// The following constants define the beginning and the end conditions of the day-night transition
142142
const float startNightTrans = 0.1; // The "NightTrans" values refer to the Y postion of LightVector
143143
const float finishNightTrans = -0.1;
144-
const float minDarknessCoeff = 0.15;
144+
const float minDarknessCoeff = 0.03;
145145

146146
// Internal variables
147147
// The following two are used to interpoate between day and night lighting (y = mx + b)

Source/RunActivity/Content/SkyShader.fx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ VERTEX_OUTPUT VSMoon(VERTEX_INPUT In)
147147

148148
// This function adjusts brightness, saturation and contrast
149149
// By Romain Dura aka Romz
150+
// Colors edit by DR_Aeronautics
150151
float3 ContrastSaturationBrightness(float3 color, float brt, float sat, float con)
151152
{
152153
// Increase or decrease theese values to adjust r, g and b color channels separately
@@ -173,10 +174,18 @@ float4 PSSky(VERTEX_OUTPUT In) : COLOR
173174
float4 starColor = tex2D(StarMapSampler, TexCoord);
174175

175176
// Adjust sky color brightness for time of day
176-
skyColor *= SkyColor.x;
177+
skyColor *= SkyColor.y;
177178

178-
// Stars
179-
skyColor = lerp(starColor, skyColor, SkyColor.y);
179+
// Stars (power function keeps stars hidden until after sunset)
180+
// if-statement handles astronomical/final stage of twilight
181+
if (LightVector.y < -0.2)
182+
{
183+
skyColor = lerp(starColor, skyColor, LightVector.y*6.6+2.22);
184+
}
185+
else
186+
{
187+
skyColor = lerp(starColor, skyColor, pow(abs(SkyColor.y),0.125));
188+
}
180189

181190
// Fogging
182191
skyColor.rgb = lerp(skyColor.rgb, FogColor.rgb, saturate((1 - In.Normal.y) * Fog.x));
@@ -189,11 +198,35 @@ float4 PSSky(VERTEX_OUTPUT In) : COLOR
189198
// Coefficients selected by the author to achieve the desired appearance - fot limits the effect
190199
skyColor += angleRcp * Fog.y;
191200

192-
// increase orange at sunset - fog limits the effect
201+
// increase orange at sunset and yellow at sunrise - fog limits the effect
193202
if (LightVector.x < 0)
194203
{
195-
skyColor.r += SkyColor.z * angleRcp * Fog.z;
196-
skyColor.g += skyColor.r * Fog.w;
204+
// These if-statements prevent the yellow-flash effect
205+
if (LightVector.y > 0.13)
206+
{
207+
skyColor.rg += SkyColor.z*2 * angleRcp * Fog.z;
208+
skyColor.r += SkyColor.z*2 * angleRcp * Fog.z;
209+
}
210+
211+
else
212+
{
213+
skyColor.rg += angleRcp * 0.075 * SkyColor.y;
214+
skyColor.r += angleRcp * 0.075 * SkyColor.y;
215+
}
216+
}
217+
else
218+
{
219+
if (LightVector.y > 0.15)
220+
{
221+
skyColor.rg += SkyColor.z*3 * angleRcp * Fog.z;
222+
skyColor.r += SkyColor.z * angleRcp * Fog.z;
223+
}
224+
225+
else
226+
{
227+
skyColor.rg += angleRcp * 0.075 * SkyColor.y;
228+
skyColor.r += pow(angleRcp * 0.075 * SkyColor.y,2);
229+
}
197230
}
198231

199232
// Keep alpha opague

0 commit comments

Comments
 (0)