Skip to content

Commit

Permalink
Finale graphical effects
Browse files Browse the repository at this point in the history
Should only activate on finale.
  • Loading branch information
riperiperi committed Dec 8, 2024
1 parent c5bc1b0 commit 34f6ea8
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 15 deletions.
10 changes: 8 additions & 2 deletions TSOClient/tso.client/Rendering/City/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,11 @@ private Color PowColor(Color col, float pow)
public void SetTimeOfDay(double time)
{
time = Math.Min(0.999999999, time);
Time = (float)time;
m_TintColor = TimeOfDayConfig.ColorFromTime(time);

Time = (float)time;
time = FinaleUtils.BiasSunTime(time);

if (Weather.Darken > 0)
{
//tint the outside colour, usually with some darkening effect.
Expand All @@ -1240,6 +1242,8 @@ public void SetTimeOfDay(double time)
modTime = (time - DayOffset) * 0.5 / DayDuration;
}

modTime = FinaleUtils.BiasSunTime(modTime);

Transform *= Matrix.CreateRotationY((float)((modTime+0.5) * Math.PI * 2.0)); //Controls the rotation of the sun/moon around the city.
Transform *= Matrix.CreateRotationZ((float)(Math.PI*(45.0/180.0))); //Sun is at an angle of 45 degrees to horizon at it's peak. idk why, it's winter maybe? looks nice either way
Transform *= Matrix.CreateRotationY((float)(Math.PI * 0.3)); //Offset from front-back a little. This might need some adjusting for the nicest sunset/sunrise locations.
Expand Down Expand Up @@ -1820,7 +1824,9 @@ private void DrawFacades(Vector2 mid, int passIndex, bool useLocked, BoundingFru

VertexShader.CurrentTechnique = VertexShader.Techniques[1];
VertexShader.CurrentTechnique.Passes[passIndex].Apply();
var night = Time < 0.25f || Time > 0.75f;

double biasTime = FinaleUtils.BiasSunTime(Time);
var night = biasTime < 0.25f || biasTime > 0.75f;

if (!useLocked || NearFacades == null)
{
Expand Down
1 change: 1 addition & 0 deletions TSOClient/tso.common/FSO.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<Compile Include="Rendering\Emoji\EmojiCache.cs" />
<Compile Include="Rendering\Emoji\EmojiDictionary.cs" />
<Compile Include="Rendering\Emoji\EmojiProvider.cs" />
<Compile Include="Rendering\FinaleUtils.cs" />
<Compile Include="Rendering\Framework\3DComponent.cs" />
<Compile Include="Rendering\Framework\3DLayer.cs" />
<Compile Include="Rendering\Framework\3DScene.cs" />
Expand Down
88 changes: 88 additions & 0 deletions TSOClient/tso.common/Rendering/FinaleUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Microsoft.Xna.Framework;
using System;

namespace FSO.Common.Rendering
{
public static class FinaleUtils
{
private static Color[] FinaleColors = new Color[]
{
new Color(2, 2, 2),
new Color(2, 2, 2),
Color.Lerp(new Color(0, 0, 0), new Color(50, 70, 122)*1.25f, 0.5f),
new Color(70, 70, 70)*1.25f,
new Color(217, 109, 50), //sunrise
new Color(255, 255, 255),
new Color(255, 255, 255), //peak
new Color(255, 255, 255), //peak
new Color(255, 255, 255),
new Color(255, 255, 255),
Color.Lerp(new Color(255, 255, 255), new Color(217, 109, 50), 0.33f),
Color.Lerp(new Color(255, 255, 255), new Color(217, 109, 25), 0.66f),
new Color(225, 64, 0), //sunset
new Color(0, 0, 0)
};

private static double DayOffset = 0.25;
private static double DayDuration = 0.60;

private static double TargetEnd = 1.04;

public static double BiasSunTime(double modTime)
{
if (IsFinale())
{
double dayMid = DayOffset + DayDuration / 2;
double mainEnd = DayOffset + DayDuration;

double rescaleDay = (TargetEnd - dayMid) / (mainEnd - dayMid);

if (modTime > dayMid)
{
modTime = dayMid + (modTime - dayMid) / rescaleDay;
}
}

return modTime;
}

public static Vector3 BiasSunIntensity(Vector3 intensity, float time)
{
if (IsFinale())
{
if (time > 0.70)
{
intensity = Vector3.Lerp(new Vector3(0.6f), new Vector3(1, 0.2f, 0.1f), (time - 0.70f) / 0.25f);
}
else if (time > 0.5)
{
intensity = Vector3.Lerp(intensity, new Vector3(0.6f), (time - 0.5f) / 0.2f);
}

if (time > 0.995)
{
intensity *= (1f - time) * 200f;
}
}

return intensity;
}

public static bool IsFinale()
{
var time = DateTime.UtcNow;

return time.Year == 2024 && time.Month == 12 && ((time.Day == 8 && time.Hour == 23) || (time.Day == 9 && time.Hour == 0));
}

public static float GetDarkness()
{
return IsFinale() ? 1.0f : 0.8f;
}

public static Color[] SwapFinaleColors(Color[] colors)
{
return IsFinale() ? FinaleColors : colors;
}
}
}
17 changes: 11 additions & 6 deletions TSOClient/tso.common/Rendering/TimeOfDayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ private static Color PowColor(Color col, float pow)

public static Color ColorFromTime(double time)
{
Color col1 = m_TimeColors[(int)Math.Floor(time * (m_TimeColors.Length - 1))]; //first colour
Color col2 = m_TimeColors[(int)Math.Floor(time * (m_TimeColors.Length - 1)) + 1]; //second colour
if (DarknessMultiplier != 1.0)
Color[] colors = FinaleUtils.SwapFinaleColors(m_TimeColors);

Color col1 = colors[(int)Math.Floor(time * (colors.Length - 1))]; //first colour
Color col2 = colors[(int)Math.Floor(time * (colors.Length - 1)) + 1]; //second colour

float darkness = FinaleUtils.GetDarkness();

if (darkness != 1.0)
{
col1 = Color.Lerp(Color.White, col1, DarknessMultiplier);
col2 = Color.Lerp(Color.White, col2, DarknessMultiplier);
col1 = Color.Lerp(Color.White, col1, darkness);
col2 = Color.Lerp(Color.White, col2, darkness);
}
double Progress = (time * (m_TimeColors.Length - 1)) % 1; //interpolation progress (mod 1)
double Progress = (time * (colors.Length - 1)) % 1; //interpolation progress (mod 1)

return PowColor(Color.Lerp(col1, col2, (float)Progress), 2.2f); //linearly interpolate between the two colours for this specific time.
}
Expand Down
Binary file modified TSOClient/tso.content/Content/DX/Effects/2DWorldBatch.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Effects/GrassShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Effects/GrassShaderiOS.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Effects/ParticleShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Effects/RCObject.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/mobile.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/simdialogue.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/trebuchet.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/2DWorldBatch.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/GrassShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/GrassShaderiOS.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/ParticleShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/RCObject.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/RCObjectiOS.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/mobile.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/simdialogue.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/trebuchet.xnb
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions TSOClient/tso.content/ContentSrc/Effects/LightingCommon.fx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ float4 lightColorFloor(float4 intensities) {
float avg = (intensities.r + intensities.g + intensities.b) / 3;
//floor shadow is how much less than average the alpha component is

float fshad = intensities.a / avg;
float fshad = intensities.a / max(0.0001, avg);

return lerp(OutsideDark, float4(intensities.rgb * LightingAdjust, 1), (fshad - MinAvg.x) * MinAvg.y);
}

float4 lightColorIAvg(float4 intensities, float i, float avg) {

float fshad = intensities.a / avg;
float fshad = intensities.a / max(0.0001, avg);
fshad = lerp(fshad, 1, i);

return lerp(OutsideDark, float4(intensities.rgb * LightingAdjust, 1), (fshad - MinAvg.x) * MinAvg.y);
Expand All @@ -53,7 +53,7 @@ float4 lightColorI(float4 intensities, float i) {
float avg = (intensities.r + intensities.g + intensities.b) / 3;
//floor shadow is how much less than average the alpha component is

float fshad = intensities.a / avg;
float fshad = intensities.a / max(0.0001, avg);
fshad = lerp(fshad, 1, i);

return lerp(OutsideDark, float4(intensities.rgb * LightingAdjust, 1), (fshad - MinAvg.x) * MinAvg.y);
Expand Down
Binary file modified TSOClient/tso.content/ContentSrc/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions TSOClient/tso.world/Components/AbstractSkyDome.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FSO.Common;
using FSO.Common.Model;
using FSO.Common.Rendering;
using FSO.Common.Utils;
using FSO.Files;
using FSO.LotView.Model;
Expand All @@ -14,6 +15,7 @@ namespace FSO.LotView.Components
public class AbstractSkyDome : IDisposable
{
private static string DefaultSkyCol = "Textures/skycol.png";
private static string FinalSkyCol = "Textures/skycolfinal.png";

private VertexBuffer Verts;
private IndexBuffer Indices;
Expand All @@ -24,6 +26,8 @@ public class AbstractSkyDome : IDisposable
private VertexPositionTexture[] VertexData;
private int[] IndexData;

private bool IsFinal;

public AbstractSkyDome(GraphicsDevice GD, float time)
{
float? customSky = DynamicTuning.Global?.GetTuning("city", 0, 2);
Expand All @@ -33,10 +37,27 @@ public AbstractSkyDome(GraphicsDevice GD, float time)
TryLoadSkyColor(GD, DefaultSkyCol);
}

LoadFinalIfNeeded(GD);

InitArrays();
BuildSkyDome(GD, time);
}

public void LoadFinalIfNeeded(GraphicsDevice GD)
{
bool needsFinal = FinaleUtils.IsFinale();

if (!IsFinal && needsFinal)
{
using (var file = File.OpenRead(Path.Combine(FSOEnvironment.ContentDir, FinalSkyCol)))
{
GradTex = ImageLoader.FromStream(GD, file);
};

IsFinal = true;
}
}

private bool TryLoadSkyColor(GraphicsDevice GD, string path)
{
try
Expand Down Expand Up @@ -111,6 +132,8 @@ private void InitArrays()

public void BuildSkyDome(GraphicsDevice GD, float time)
{
LoadFinalIfNeeded(GD);

//generate sky dome geometry
var subdivs = 65;
VertexPositionTexture[] verts = VertexData;
Expand Down Expand Up @@ -224,7 +247,7 @@ public void Draw(GraphicsDevice gd, Color outsideColor, Matrix view, Matrix proj
}

gd.BlendState = BlendState.NonPremultiplied;
var night = Night(time);
var night = Night((float)FinaleUtils.BiasSunTime(time));
//draw the sun or moon
var pos = sunVector;
var z = -pos.X;
Expand All @@ -241,7 +264,7 @@ public void Draw(GraphicsDevice gd, Color outsideColor, Matrix view, Matrix proj
effect.VertexColorEnabled = false;
effect.TextureEnabled = true;
effect.Texture = (night) ? TextureGenerator.GetMoon(gd) : TextureGenerator.GetSun(gd);
effect.DiffuseColor = new Vector3(color.X, color.Y, color.Z) * ((night) ? 2f : 0.6f);
effect.DiffuseColor = FinaleUtils.BiasSunIntensity(new Vector3(color.X, color.Y, color.Z) * ((night) ? 2f : 0.6f), time);
gd.BlendState = (night) ? BlendState.NonPremultiplied : BlendState.Additive;

foreach (var pass in effect.CurrentTechnique.Passes)
Expand Down
3 changes: 3 additions & 0 deletions TSOClient/tso.world/LMap/LMapBatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FSO.Common;
using FSO.Common.Rendering;
using FSO.Common.Utils;
using FSO.LotView.Components;
using FSO.LotView.Effects;
Expand Down Expand Up @@ -375,6 +376,8 @@ public LightData BuildOutdoorsLight(double tod)
DayOffset = 0.25f;
DayDuration = 0.60f;

tod = FinaleUtils.BiasSunTime(tod);

bool night = false;
double modTime;
var offStart = 1 - (DayOffset + DayDuration);
Expand Down
10 changes: 8 additions & 2 deletions TSOClient/tso.world/Model/WeatherController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FSO.LotView.Components;
using FSO.Common.Rendering;
using FSO.LotView.Components;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -88,7 +89,7 @@ public void Update()

ParticleType ptype;

if (IsManual)
if (IsManual && !FinaleUtils.IsFinale())
{
if (WeatherData == LastWeatherData && enabled == LastEnabled) return;
LastWeatherData = WeatherData;
Expand Down Expand Up @@ -167,6 +168,11 @@ public void SetWeather(short data) {

private int GetAutoWeatherIntensity(DateTime time)
{
if (FinaleUtils.IsFinale())
{
return 0;
}

var distance = time - new DateTime(2019, 1, 26);
var halfDay = (int)distance.TotalHours;

Expand Down

0 comments on commit 34f6ea8

Please sign in to comment.