Fog Colors, Lighting Colors & Interior Sky Texture

* Added customizable fog colors, ambient light and directional light colors
* Added interior sky texture
This commit is contained in:
JappaWakka 2022-04-15 16:28:17 +02:00
parent 8dd62e545d
commit 5e3713c6c6
6 changed files with 121 additions and 85 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

View File

@ -14095,6 +14095,15 @@
<Content Include="Content\SkyDomeResource\Clouds_Weather.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\SkyDomeResource\FogColors.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\SkyDomeResource\Inside.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\SkyDomeResource\LightingColors.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\SkyDomeResource\Sky_Day.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -3,28 +3,84 @@
''' </summary>
Public Class Lighting
#Region "Enums"
#End Region
#Region "Fields and Constants"
#End Region
#Region "Properties"
#End Region
#Region "Delegates"
#End Region
#Region "Constructors"
#End Region
Shared LightingColorTexture As Texture2D = TextureManager.GetTexture("SkyDomeResource\LightingColors")
Shared FogColorTexture As Texture2D = TextureManager.GetTexture("SkyDomeResource\FogColors")
#Region "Methods"
Public Shared Function GetEnvironmentColor(TextureType As Integer) As Vector3 '0 = Directional light, 1 = Ambient light, 2 = Fog color
Dim ColorTexture As Texture2D
Dim EnvironmentColor As Vector3 = Nothing
Dim x As Integer = 0
Dim y As Integer = 0
Select Case TextureType
Case 0
x = Screen.Level.DayTime - 1
If x >= 0 AndAlso x <= 3 Then
ColorTexture = LightingColorTexture
Dim ColorData(0) As Color
ColorTexture.GetData(0, New Rectangle(x, 0, 1, 1), ColorData, 0, 1)
Dim DarkOrBrightData(0) As Color
ColorTexture.GetData(0, New Rectangle(x, 1, 1, 1), DarkOrBrightData, 0, 1)
EnvironmentColor = ColorData(0).ToVector3
If DarkOrBrightData(0) = Color.Black Then
EnvironmentColor = New Vector3(0.0F) - EnvironmentColor
End If
Else
EnvironmentColor = New Vector3(0.0F)
End If
Case 1
x = Screen.Level.DayTime - 1
If x >= 0 AndAlso x <= 3 Then
ColorTexture = LightingColorTexture
Dim ColorData(0) As Color
ColorTexture.GetData(0, New Rectangle(x, 2, 1, 1), ColorData, 0, 1)
Dim DarkOrBrightData(0) As Color
ColorTexture.GetData(0, New Rectangle(x, 3, 1, 1), DarkOrBrightData, 0, 1)
EnvironmentColor = ColorData(0).ToVector3
If DarkOrBrightData(0) = Color.Black Then
EnvironmentColor = New Vector3(0.0F) - EnvironmentColor
End If
Else
EnvironmentColor = New Vector3(0.0F)
End If
Case 2
ColorTexture = FogColorTexture
Select Case Screen.Level.EnvironmentType
Case 0
x = GetLightingType()
If x > 2 Then
x = 0
y += 1
End If
Case 1
x = 1
y = 1
Case 2
x = 2
y = 1
Case 3
x = 0
y = 2
Case 4
x = 1
y = 2
Case 5
x = 2
y = 2
End Select
Dim ColorData(0) As Color
ColorTexture.GetData(0, New Rectangle(x, y, 1, 1), ColorData, 0, 1)
EnvironmentColor = ColorData(0).ToVector3
End Select
Return EnvironmentColor
End Function
''' <summary>
''' Updates the lighting values of a BasicEffect instance.
''' </summary>
@ -38,39 +94,39 @@ Public Class Lighting
refEffect.SpecularPower = 2000.0F
' LightType results:
' 0 = Night
' 1 = Morning
' 2 = Day
' 0 = Day
' 1 = Night
' 2 = Morning
' 3 = Evening
' Anything higher than 3 = No Lighting
Select Case GetLightingType()
Case 0 ' Night
refEffect.AmbientLightColor = New Vector3(0.8F)
Case 0 ' Day
refEffect.AmbientLightColor = GetEnvironmentColor(1)
refEffect.DirectionalLight0.DiffuseColor = New Vector3(-0.2F)
refEffect.DirectionalLight0.DiffuseColor = GetEnvironmentColor(0)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(-1.0F, 0.0F, 1.0F))
refEffect.DirectionalLight0.SpecularColor = New Vector3(0.0F)
refEffect.DirectionalLight0.Enabled = True
Case 1 ' Morning
refEffect.AmbientLightColor = New Vector3(0.8F)
Case 1 ' Night
refEffect.AmbientLightColor = GetEnvironmentColor(1)
refEffect.DirectionalLight0.DiffuseColor = New Vector3(-0.45F)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(1.0F, -1.0F, -1.0F))
refEffect.DirectionalLight0.DiffuseColor = GetEnvironmentColor(0)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(1.0F, 1.0F, -1.0F))
refEffect.DirectionalLight0.SpecularColor = New Vector3(0.0F)
refEffect.DirectionalLight0.Enabled = True
Case 2 ' Day
refEffect.AmbientLightColor = New Vector3(1.0F)
Case 2 ' Morning
refEffect.AmbientLightColor = GetEnvironmentColor(1)
refEffect.DirectionalLight0.DiffuseColor = New Vector3(-0.3F)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(1.0F, 1.0F, 1.0F))
refEffect.DirectionalLight0.DiffuseColor = GetEnvironmentColor(0)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(-1.0F, 0.0F, 1.0F))
refEffect.DirectionalLight0.SpecularColor = New Vector3(0.0F)
refEffect.DirectionalLight0.Enabled = True
Case 3 ' Evening
refEffect.AmbientLightColor = New Vector3(0.8F)
refEffect.AmbientLightColor = GetEnvironmentColor(1)
refEffect.DirectionalLight0.DiffuseColor = New Vector3(-0.45F)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(-1.0F, 0.0F, 1.0F))
refEffect.DirectionalLight0.DiffuseColor = GetEnvironmentColor(0)
refEffect.DirectionalLight0.Direction = Vector3.Normalize(New Vector3(1.0F, 1.0F, -1.0F))
refEffect.DirectionalLight0.SpecularColor = New Vector3(0.0F)
refEffect.DirectionalLight0.Enabled = True
Case Else 'Disable lighting on the effect
@ -88,9 +144,9 @@ Public Class Lighting
' Level's lighttype values:
' 0 = Get lighting from the current time of day.
' 1 = Disable lighting
' 2 = Always Night
' 3 = Always Morning
' 4 = Always Day
' 2 = Always Day
' 3 = Always Night
' 4 = Always Morning
' 5 = Always Evening
If Screen.Level.LightingType = 1 Then ' If the level lighting type is 1, disable lighting (set index to 99).
@ -99,11 +155,11 @@ Public Class Lighting
If Screen.Level.EnvironmentType = World.EnvironmentTypes.Outside Then
Select Case Screen.Level.DayTime
Case 1
LightType = 2
Case 2
LightType = 0
Case 3
Case 2
LightType = 1
Case 3
LightType = 2
Case 4
LightType = 3
End Select
@ -111,23 +167,9 @@ Public Class Lighting
If Screen.Level.LightingType > 1 And Screen.Level.LightingType < 6 Then ' If the level's lighting type is 2, 3, 4 or 5, set to the respective LightType (set time of day).
LightType = Screen.Level.LightingType - 2
End If
Return LightType
End Function
Public Shared Function GetLightingColor(ByVal LightType As Integer) As Vector3
Select Case LightType
Case 0
Return New Vector3(0.4F, 0.4F, 0.6F)
Case 1
Return Color.Orange.ToVector3()
Case 2
Return New Vector3(-0.3F)
Case 3
Return New Vector3(-0.45F)
End Select
End Function
#End Region
End Class

View File

@ -40,9 +40,9 @@ Public Class World
End Enum
Public Enum DayTimes As Integer
Night = 0
Morning = 1
Day = 2
Day = 0
Night = 1
Morning = 2
Evening = 3
End Enum
@ -594,50 +594,35 @@ endsub:
Private Sub ChangeEnvironment()
Select Case Me.EnvironmentType
Case EnvironmentTypes.Outside
Dim _fogColor As Color
Dim v As Single = 1.0F
Dim nightFog As Integer = 64
Dim dayFog As Integer = 168
Dim multiplier As Vector3 = New Vector3(1.0F)
Select Case CurrentMapWeather
Case World.Weathers.Clear, Weathers.Sunny
v = 1.0F
multiplier = New Vector3(1.0F)
Case World.Weathers.Rain, Weathers.Thunderstorm, World.Weathers.Fog
v = 0.7F
multiplier = New Vector3(0.7F)
Case World.Weathers.Snow
v = 0.8F
multiplier = New Vector3(0.8F)
End Select
Select Case Screen.Level.DayTime
Case 1, 3
_fogColor = New Color(CInt(v * dayFog), CInt(v * dayFog), CInt(v * dayFog))
Case 2, 4
_fogColor = New Color(CInt(v * nightFog), CInt(v * nightFog), CInt(v * nightFog))
End Select
Core.BackgroundColor = GetWeatherBackgroundColor(SkyDome.GetDaytimeColor(False))
Screen.Effect.FogColor = _fogColor.ToVector3()
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2) * multiplier
Screen.SkyDome.TextureDown = TextureManager.GetTexture("SkyDomeResource\Stars")
Case EnvironmentTypes.Inside
Core.BackgroundColor = New Color(57, 57, 57)
Screen.Effect.FogColor = Core.BackgroundColor.ToVector3()
Screen.SkyDome.TextureUp = Nothing
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2)
Screen.SkyDome.TextureUp = TextureManager.GetTexture("SkyDomeResource\Inside")
Screen.SkyDome.TextureDown = Nothing
Case EnvironmentTypes.Dark
Core.BackgroundColor = GetWeatherBackgroundColor(New Color(29, 29, 50))
Screen.Effect.FogColor = Core.BackgroundColor.ToVector3()
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2)
Screen.SkyDome.TextureUp = TextureManager.GetTexture("SkyDomeResource\Dark")
Screen.SkyDome.TextureDown = Nothing
Case EnvironmentTypes.Cave
Core.BackgroundColor = GetWeatherBackgroundColor(New Color(72, 64, 64))
Screen.Effect.FogColor = Core.BackgroundColor.ToVector3()
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2)
Screen.SkyDome.TextureUp = TextureManager.GetTexture("SkyDomeResource\Cave")
Screen.SkyDome.TextureDown = Nothing
Case EnvironmentTypes.Underwater
Core.BackgroundColor = GetWeatherBackgroundColor(New Color(40, 88, 128))
Screen.Effect.FogColor = Core.BackgroundColor.ToVector3()
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2)
Screen.SkyDome.TextureUp = TextureManager.GetTexture("SkyDomeResource\Underwater")
Screen.SkyDome.TextureDown = Nothing
Case EnvironmentTypes.Forest
Core.BackgroundColor = GetWeatherBackgroundColor(New Color(48, 80, 48))
Screen.Effect.FogColor = Core.BackgroundColor.ToVector3()
Screen.Effect.FogColor = Lighting.GetEnvironmentColor(2)
Screen.SkyDome.TextureUp = TextureManager.GetTexture("SkyDomeResource\Forest")
Screen.SkyDome.TextureDown = Nothing
End Select