diff --git a/Assets/GothicVR/Editor/Scripts/Tools/FeatureFlagTool.cs b/Assets/GothicVR/Editor/Scripts/Tools/FeatureFlagTool.cs index 3b1b0cd1d..288fbf43a 100644 --- a/Assets/GothicVR/Editor/Scripts/Tools/FeatureFlagTool.cs +++ b/Assets/GothicVR/Editor/Scripts/Tools/FeatureFlagTool.cs @@ -30,6 +30,7 @@ public class FeatureFlagTool : EditorWindow new (nameof(FeatureFlags.vobItemsDynamicAttach), typeof(bool), true), // Ints + new (nameof(FeatureFlags.TimeMultiplier), typeof(float), 1), new (nameof(FeatureFlags.startHour), typeof(int), 8), // Official start time of G1 - new game new (nameof(FeatureFlags.startMinute), typeof(int), 0), // Official start time of G1 - new game diff --git a/Assets/GothicVR/Resources/Materials/GothicSky.mat b/Assets/GothicVR/Resources/Materials/GothicSky.mat index 2a3f243cf..f55ffefa6 100644 --- a/Assets/GothicVR/Resources/Materials/GothicSky.mat +++ b/Assets/GothicVR/Resources/Materials/GothicSky.mat @@ -8,23 +8,28 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: GothicSky - m_Shader: {fileID: 108, guid: 0000000000000000f000000000000000, type: 0} + m_Shader: {fileID: 4800000, guid: 93b46fd80ab75b048aedcb5df3194872, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] m_InvalidKeywords: - _MAPPING_LATITUDE_LONGITUDE_LAYOUT - _MIRRORONBACK_ON + - _SUNDISK_HIGH_QUALITY m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 + m_CustomRenderQueue: 3000 stringTagMap: {} disabledShaderPasses: [] - m_LockedProperties: + m_LockedProperties: _FogCutoff m_SavedProperties: serializedVersion: 3 m_TexEnvs: + - _BackTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _BaseMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -45,10 +50,22 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _DownTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _EmissionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _FrontTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _LeftTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -65,10 +82,38 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _RightTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Sky1: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Sky2: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Sky3: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Sky4: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _SpecGlossMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _Tex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _UpTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - unity_Lightmaps: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -83,8 +128,14 @@ Material: m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: + - _Alpha1: 1 + - _Alpha2: 1 + - _Alpha3: 1 + - _Alpha4: 1 - _AlphaClip: 0 + - _AlphaTestToggle: 0 - _AlphaToMask: 0 + - _AtmosphereThickness: 1 - _Blend: 0 - _BlendModePreserveSpecular: 1 - _BumpScale: 1 @@ -96,16 +147,20 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 0 - _DstBlendAlpha: 0 + - _Emission: 0 - _EnvironmentReflections: 1 - _Exposure: 1 + - _FogCutoff: 0.3 - _GlossMapScale: 0 + - _GlossSource: 0 - _Glossiness: 0 - _GlossyReflections: 0 - _ImageType: 1 - - _Layout: 0 + - _Layout: 1 - _Mapping: 1 - _Metallic: 0 - _MirrorOnBack: 1 + - _NormalMapToggle: 0 - _OcclusionStrength: 1 - _Parallax: 0.005 - _QueueOffset: 0 @@ -113,18 +168,30 @@ Material: - _Rotation: 0 - _Smoothness: 0.5 - _SmoothnessTextureChannel: 0 + - _SpecGlossMapToggle: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 - _SrcBlendAlpha: 1 + - _SunDisk: 2 + - _SunSize: 0.04 + - _SunSizeConvergence: 5 - _Surface: 0 - _WorkflowMode: 1 - _ZWrite: 1 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} + - _Color2: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _FogColor: {r: 1, g: 1, b: 1, a: 0} + - _FogColor2: {r: 1, g: 1, b: 1, a: 0} + - _GroundColor: {r: 0.36899996, g: 0.34899998, b: 0.34099993, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - _Tint: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} + - _Vector1: {r: 0, g: 0, b: 0, a: 0} + - _Vector2: {r: 0.9, g: 1.1, b: 0, a: 0} + - _Vector3: {r: 0, g: 0, b: 0, a: 0} + - _Vector4: {r: 0.9, g: 1.1, b: 0, a: 0} m_BuildTextureStacks: [] --- !u!114 &2550804037692824493 MonoBehaviour: diff --git a/Assets/GothicVR/Resources/worldLightingSettings.lighting b/Assets/GothicVR/Resources/worldLightingSettings.lighting new file mode 100644 index 000000000..4f4c58043 --- /dev/null +++ b/Assets/GothicVR/Resources/worldLightingSettings.lighting @@ -0,0 +1,66 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!850595691 &4890085278179872738 +LightingSettings: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: worldLightingSettings + serializedVersion: 6 + m_GIWorkflowMode: 1 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_RealtimeEnvironmentLighting: 1 + m_BounceScale: 1 + m_AlbedoBoost: 1 + m_IndirectOutputScale: 1 + m_UsingShadowmask: 1 + m_BakeBackend: 2 + m_LightmapMaxSize: 1024 + m_BakeResolution: 40 + m_Padding: 2 + m_LightmapCompression: 3 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAO: 0 + m_MixedBakeMode: 2 + m_LightmapsBakeMode: 1 + m_FilterMode: 1 + m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0} + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_RealtimeResolution: 2 + m_ForceWhiteAlbedo: 0 + m_ForceUpdates: 0 + m_FinalGather: 0 + m_FinalGatherRayCount: 256 + m_FinalGatherFiltering: 1 + m_PVRCulling: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_LightProbeSampleCountMultiplier: 4 + m_PVRBounces: 2 + m_PVRMinBounces: 2 + m_PVREnvironmentImportanceSampling: 1 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_PVRTiledBaking: 0 + m_NumRaysToShootPerTexel: -1 + m_RespectSceneVisibilityWhenBakingGI: 0 diff --git a/Assets/GothicVR/Resources/worldLightingSettings.lighting.meta b/Assets/GothicVR/Resources/worldLightingSettings.lighting.meta new file mode 100644 index 000000000..6f3d161b2 --- /dev/null +++ b/Assets/GothicVR/Resources/worldLightingSettings.lighting.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8e19a4dfc17c45c4881fc82791748c12 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 4890085278179872738 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GothicVR/Scenes/Bootstrap.unity b/Assets/GothicVR/Scenes/Bootstrap.unity index a015142b2..2ec6743c8 100644 --- a/Assets/GothicVR/Scenes/Bootstrap.unity +++ b/Assets/GothicVR/Scenes/Bootstrap.unity @@ -322,6 +322,7 @@ MonoBehaviour: createWayPointMeshes: 0 createWaypointEdgeMeshes: 0 enableDayTime: 1 + TimeMultiplier: 1 sunMovementPerformanceValue: 1 startHour: 8 startMinute: 0 @@ -1612,6 +1613,7 @@ GameObject: - component: {fileID: 1896514225} - component: {fileID: 1896514223} - component: {fileID: 1896514226} + - component: {fileID: 1896514228} m_Layer: 0 m_Name: Managers m_TagString: Untagged @@ -1770,6 +1772,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d8a5433ca9664e58a7e90654db1d382c, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1896514228 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1896514212} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 46e9095c72bc48bfb33591c93b3dc5f5, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2044949334 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/GothicVR/Scenes/Worlds/world.zen.unity b/Assets/GothicVR/Scenes/Worlds/world.zen.unity index b86d25034..9139e3d6d 100644 --- a/Assets/GothicVR/Scenes/Worlds/world.zen.unity +++ b/Assets/GothicVR/Scenes/Worlds/world.zen.unity @@ -14,19 +14,19 @@ OcclusionCullingSettings: RenderSettings: m_ObjectHideFlags: 0 serializedVersion: 9 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 + m_Fog: 1 + m_FogColor: {r: 0, g: 0, b: 0, a: 1} + m_FogMode: 1 m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_LinearFogStart: 250 + m_LinearFogEnd: 500 + m_AmbientSkyColor: {r: 0, g: 0, b: 0, a: 1} m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} m_AmbientIntensity: 1 - m_AmbientMode: 0 + m_AmbientMode: 3 m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_SkyboxMaterial: {fileID: 2100000, guid: 39ac659c922b5b1489714aacd9b952e9, type: 2} m_HaloStrength: 0.5 m_FlareStrength: 1 m_FlareFadeSpeed: 3 @@ -98,7 +98,7 @@ LightmapSettings: m_TrainingDataDestination: TrainingData m_LightProbeSampleCountMultiplier: 4 m_LightingDataAsset: {fileID: 0} - m_LightingSettings: {fileID: 0} + m_LightingSettings: {fileID: 4890085278179872738, guid: 8e19a4dfc17c45c4881fc82791748c12, type: 2} --- !u!196 &4 NavMeshSettings: serializedVersion: 2 @@ -123,3 +123,7 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: [] diff --git a/Assets/GothicVR/Scripts/Creator/WorldCreator.cs b/Assets/GothicVR/Scripts/Creator/WorldCreator.cs index b7aca4212..a858ae0aa 100644 --- a/Assets/GothicVR/Scripts/Creator/WorldCreator.cs +++ b/Assets/GothicVR/Scripts/Creator/WorldCreator.cs @@ -172,9 +172,6 @@ private static void WorldLoaded() teleportationArea.interactionManager = interactionManager; } - // TODO - For some reason the referenced skybox in scene is reset to default once game starts. - // We therefore need to reset it now again. - RenderSettings.skybox = TextureManager.I.skyMaterial; } #if UNITY_EDITOR diff --git a/Assets/GothicVR/Scripts/Data/SkyLayerData.cs b/Assets/GothicVR/Scripts/Data/SkyLayerData.cs new file mode 100644 index 000000000..efadd33b6 --- /dev/null +++ b/Assets/GothicVR/Scripts/Data/SkyLayerData.cs @@ -0,0 +1,14 @@ +using UnityEngine; + +namespace GVR.Data +{ + public class SkyLayerData + { + public Texture2D[] texBox; + public Texture2D tex; + public string texName = ""; + public float texAlpha; + public float texScale = 1; + public Vector2 texSpeed = new(0.9f, 1.1f); + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Data/SkyLayerData.cs.meta b/Assets/GothicVR/Scripts/Data/SkyLayerData.cs.meta new file mode 100644 index 000000000..a01d27867 --- /dev/null +++ b/Assets/GothicVR/Scripts/Data/SkyLayerData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b604f82c329e42438a9240b444187afb +timeCreated: 1702402018 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Data/SkyState.cs b/Assets/GothicVR/Scripts/Data/SkyState.cs new file mode 100644 index 000000000..c17a8b886 --- /dev/null +++ b/Assets/GothicVR/Scripts/Data/SkyState.cs @@ -0,0 +1,200 @@ +using UnityEngine; + +namespace GVR.Data +{ + /// + /// This class is mostly a copy of the data from the original game, but with some changes as to make transitions cleaner. + /// (E.g textures for transitional layers such as dawn and evening and night1, day1) + /// + public class SkyState + { + public float time; + public Vector3 polyColor; + public Vector3 fogColor; + public Vector3 domeColor1; + public Vector3 domeColor0; + public float fogDist; + public int sunOn = 1; + public int cloudShadowOn; + public SkyLayerData[] layer; + + public SkyState() + { + layer = new SkyLayerData[2]; + layer[0] = new SkyLayerData(); + layer[1] = new SkyLayerData(); + } + + public void PresetDawn() + { + time = 0.7f; // 4:48 am + + polyColor = new Vector3(190.0f, 160.0f, 255.0f); // ambient light + fogColor = new Vector3(80.0f, 60.0f, 105.0f); // fog + domeColor0 = new Vector3(80.0f, 60.0f, 105.0f); // dome color + domeColor1 = new Vector3(255.0f, 255.0f, 255.0f); + + layer[0].texName = "SKYNIGHT_LAYER0_A0.TGA"; + layer[1].texName = "SKYDAY_LAYER0_A0.TGA"; + + layer[0].texAlpha = 128.0f; + layer[1].texAlpha = 128.0f; + + layer[0].texSpeed.y = 0.0f; + layer[0].texSpeed.x = 0.0f; + + fogDist = 0.5f; + sunOn = 1; + } + + public void PresetDay0() + { + time = 0.75f; // 6:00 am + + polyColor = new Vector3(255.0f, 250.0f, 235.0f); + fogColor = new Vector3(120.0f, 140.0f, 180.0f); + domeColor0 = fogColor; + domeColor1 = new Vector3(255.0f, 255.0f, 255.0f); + + layer[0].texName = "SKYDAY_LAYER1_A0.TGA"; + layer[1].texName = "SKYDAY_LAYER0_A0.TGA"; + + layer[0].texAlpha = 0.0f; + layer[1].texAlpha = 255.0f; + + layer[1].texSpeed *= 0.2f; + + fogDist = 0.2f; + sunOn = 1; + } + + public void PresetDay1() + { + time = 0f; // 12:00 pm + + polyColor = new Vector3(255.0f, 250.0f, 235.0f); + fogColor = new Vector3(120.0f, 140.0f, 180.0f); + domeColor0 = fogColor; + domeColor1 = new Vector3(255.0f, 255.0f, 255.0f); + + layer[0].texName = "SKYDAY_LAYER1_A0.TGA"; + layer[1].texName = "SKYDAY_LAYER0_A0.TGA"; + + layer[0].texAlpha = 215.0f; + layer[1].texAlpha = 255.0f; + + fogDist = 0.05f; + sunOn = 1; + } + + public void PresetDay2() + { + time = 0.25f; // 6:00 pm + + polyColor = new Vector3(255.0f, 250.0f, 235.0f); + fogColor = new Vector3(120.0f, 140.0f, 180.0f); + domeColor0 = new Vector3(120.0f, 140.0f, 180.0f); + domeColor1 = new Vector3(255.0f, 255.0f, 255.0f); + + layer[0].texName = "SKYDAY_LAYER1_A0.TGA"; + layer[1].texName = "SKYDAY_LAYER0_A0.TGA"; + + layer[0].texAlpha = 0.0f; + layer[1].texAlpha = 255.0f; + + fogDist = 0.05f; + sunOn = 1; + } + + public void PresetEvening() + { + time = 0.3f; // 7:12 pm + + polyColor = new Vector3(255.0f, 185.0f, 170.0f); + fogColor = new Vector3(170.0f, 70.0f, 50.0f); + domeColor0 = new Vector3(170.0f, 70.0f, 50.0f); + domeColor1 = new Vector3(255.0f, 255.0f, 255.0f); + + layer[0].texName = "SKYNIGHT_LAYER0_A0.TGA"; + layer[1].texName = "SKYDAY_LAYER0_A0.TGA"; + + layer[0].texAlpha = 128.0f; + layer[1].texAlpha = 128.0f; + + layer[0].texSpeed.x = 0.0f; + layer[0].texSpeed.y = 0.0f; + + sunOn = 1; + fogDist = 0.2f; + } + + public void PresetNight0() + { + time = 0.35f; // 8:24 pm + + polyColor = new Vector3(105.0f, 105.0f, 195.0f); + fogColor = new Vector3(20.0f, 20.0f, 60.0f); + domeColor0 = fogColor; + domeColor1 = new Vector3(255.0f, 55.0f, 155.0f); + + layer[0].texName = "SKYNIGHT_LAYER0_A0.TGA"; + layer[1].texName = "SKYNIGHT_LAYER1_A0.TGA"; + + layer[0].texAlpha = 255.0f; + layer[1].texAlpha = 0.0f; + + layer[0].texScale *= 4.0f; + + layer[0].texSpeed.x = 0.0f; + layer[0].texSpeed.y = 0.0f; + + fogDist = 0.1f; + sunOn = 0; + cloudShadowOn = 0; + } + + public void PresetNight1() + { + time = 0.5f; // 12:00 am + + polyColor = new Vector3(40.0f, 60.0f, 210.0f); + fogColor = new Vector3(5.0f, 5.0f, 20.0f); + domeColor0 = fogColor; + domeColor1 = new Vector3(55.0f, 55.0f, 155.0f); + + layer[0].texName = "SKYNIGHT_LAYER0_A0.TGA"; + layer[1].texName = "SKYNIGHT_LAYER1_A0.TGA"; + + layer[0].texAlpha = 255.0f; + layer[1].texAlpha = 215.0f; + + layer[0].texSpeed.y = 0.0f; + layer[0].texSpeed.x = 0.0f; + + fogDist = 0.05f; + sunOn = 0; + } + + public void PresetNight2() + { + time = 0.65f; // 3:36 am + + polyColor = new Vector3(40.0f, 60.0f, 210.0f); + fogColor = new Vector3(5.0f, 5.0f, 20.0f); + domeColor0 = fogColor; + domeColor1 = new Vector3(55.0f, 55.0f, 155.0f); + + layer[0].texName = "SKYNIGHT_LAYER0_A0.TGA"; + layer[1].texName = "SKYNIGHT_LAYER1_A0.TGA"; + + layer[0].texAlpha = 255.0f; + layer[1].texAlpha = 0.0f; + + layer[0].texSpeed.y = 0.0f; + layer[0].texSpeed.x = 0.0f; + + fogDist = 0.2f; + sunOn = 0; + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Data/SkyState.cs.meta b/Assets/GothicVR/Scripts/Data/SkyState.cs.meta new file mode 100644 index 000000000..834a729b4 --- /dev/null +++ b/Assets/GothicVR/Scripts/Data/SkyState.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fe0042fcdd0e494f8a1890d6666f811f +timeCreated: 1702401958 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Debugging/FeatureFlags.cs b/Assets/GothicVR/Scripts/Debugging/FeatureFlags.cs index de150ba76..a266ebba7 100644 --- a/Assets/GothicVR/Scripts/Debugging/FeatureFlags.cs +++ b/Assets/GothicVR/Scripts/Debugging/FeatureFlags.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using GVR.Util; using UnityEngine; @@ -33,6 +33,8 @@ public enum SunMovementPerformance [Header("__________DayTime__________")] public bool enableDayTime; + [Tooltip("Modifies how fast the in-game time passes")] + [Range(0.5f, 300f)] public float TimeMultiplier; public SunMovementPerformance sunMovementPerformanceValue; [Range(0, 23)] public int startHour; [Range(0, 59)] public int startMinute; diff --git a/Assets/GothicVR/Scripts/Extensions/NumericsExtension.cs b/Assets/GothicVR/Scripts/Extensions/NumericsExtension.cs index 8b3aca4b3..73eddaf6b 100644 --- a/Assets/GothicVR/Scripts/Extensions/NumericsExtension.cs +++ b/Assets/GothicVR/Scripts/Extensions/NumericsExtension.cs @@ -30,6 +30,25 @@ public static UnityEngine.Vector3 ToUnityVector(this Vector3 vector3) return vector / 100; } + public static UnityEngine.Color ToUnityColor(this Vector3 vector3) + { + return new UnityEngine.Color() + { + r = vector3.X, + g = vector3.Y, + b = vector3.Z + }; + } + + public static UnityEngine.Color ToUnityColor(this UnityEngine.Vector3 vector3) + { + return new UnityEngine.Color() + { + r = vector3.x, + g = vector3.y, + b = vector3.z + }; + } public static UnityEngine.Vector3[] ToUnityArray(this Vector3[] array) { diff --git a/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs b/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs index 8b120f7ed..321695054 100644 --- a/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs +++ b/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs @@ -5,6 +5,7 @@ using GVR.Creator; using GVR.Debugging; using GVR.Globals; +using GVR.GothicVR.Scripts.Manager; using GVR.Util; using UnityEngine; using UnityEngine.SceneManagement; @@ -159,6 +160,7 @@ private void SetLoadingTextureForWorld(string worldName, bool newGame = false) private void HideLoadingScene() { + SkyManager.I.InitSky(); SceneManager.UnloadSceneAsync(Constants.SceneLoading); LoadingManager.I.ResetProgress(); diff --git a/Assets/GothicVR/Scripts/Manager/SkyManager.cs b/Assets/GothicVR/Scripts/Manager/SkyManager.cs new file mode 100644 index 000000000..18656a0d9 --- /dev/null +++ b/Assets/GothicVR/Scripts/Manager/SkyManager.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using GVR.Caches; +using GVR.Data; +using GVR.Extensions; +using GVR.Globals; +using GVR.Util; +using GVR.World; +using UnityEngine; +using UnityEngine.Rendering; + +namespace GVR.GothicVR.Scripts.Manager +{ + public class SkyManager : SingletonBehaviour + { + private float masterTime; + [SerializeField] private List stateList = new List(); + + protected void Start() + { + var skyState3 = new SkyState(); + skyState3.PresetDay1(); + stateList.Add(skyState3); + var skyState4 = new SkyState(); + skyState4.PresetDay2(); + stateList.Add(skyState4); + var skyState5 = new SkyState(); + skyState5.PresetEvening(); + stateList.Add(skyState5); + var skyState6 = new SkyState(); + skyState6.PresetNight0(); + stateList.Add(skyState6); + var skyState7 = new SkyState(); + skyState7.PresetNight1(); + stateList.Add(skyState7); + var skyState8 = new SkyState(); + skyState8.PresetNight2(); + stateList.Add(skyState8); + var skyState1 = new SkyState(); + skyState1.PresetDawn(); + stateList.Add(skyState1); + var skyState2 = new SkyState(); + skyState2.PresetDay0(); + stateList.Add(skyState2); + + RenderSettings.fog = true; + RenderSettings.fogMode = FogMode.Linear; + RenderSettings.ambientMode = AmbientMode.Flat; + + GvrEvents.GameTimeSecondChangeCallback.AddListener(Interpolate); + } + + public void InitSky() + { + Interpolate(new DateTime()); + } + + private void Interpolate(DateTime _) + { + masterTime = GameTime.I.GetSkyTime(); // Current time + + var (previousIndex, nextIndex) = FindNextStateIndex(); + + var lastState = stateList[previousIndex]; + var newState = stateList[nextIndex]; + + float lerpDuration = 0.05f; // Duration over which to lerp + float startTime = newState.time; // Starting time + + // Calculate how far we are between the two ticks (0.0 to 1.0) + float endTime = startTime + lerpDuration; + float lerpFraction = (masterTime - startTime) / (endTime - startTime); + + lerpFraction = Mathf.Clamp01(lerpFraction); + + if (lerpFraction > 1) + return; // finished blending + + var oldPolyColor = lastState.polyColor.ToUnityColor() / 255f; + var newPolyColor = newState.polyColor.ToUnityColor() / 255f; + + var oldDomeColor = lastState.domeColor0.ToUnityColor() / 255f; + var newDomeColor = newState.domeColor0.ToUnityColor() / 255f; + + var oldFogColor = lastState.fogColor.ToUnityColor() / 255f; + var newFogColor = newState.fogColor.ToUnityColor() / 255f; + + + RenderSettings.ambientLight = Color.Lerp(oldPolyColor, newPolyColor, lerpFraction); + RenderSettings.fogColor = Color.Lerp(oldFogColor, newFogColor, lerpFraction); + + if (lastState.layer[0].texName != "") + RenderSettings.skybox.SetTexture("_Sky1", AssetCache.TryGetTexture(lastState.layer[0].texName)); + RenderSettings.skybox.SetVector("_Vector1", lastState.layer[0].texSpeed); + RenderSettings.skybox.SetFloat("_Alpha1", lastState.layer[0].texAlpha / 255f); + + if (newState.layer[0].texName != "") + RenderSettings.skybox.SetTexture("_Sky3", AssetCache.TryGetTexture(newState.layer[0].texName)); + RenderSettings.skybox.SetVector("_Vector3", newState.layer[0].texSpeed); + RenderSettings.skybox.SetFloat("_Alpha3", newState.layer[0].texAlpha / 255f); + + if (lastState.layer[0].texName != "") + RenderSettings.skybox.SetTexture("_Sky2", AssetCache.TryGetTexture(lastState.layer[1].texName)); + RenderSettings.skybox.SetVector("_Vector2", lastState.layer[1].texSpeed); + RenderSettings.skybox.SetFloat("_Alpha2", lastState.layer[1].texAlpha / 255f); + + if (newState.layer[1].texName != "") + RenderSettings.skybox.SetTexture("_Sky4", AssetCache.TryGetTexture(newState.layer[1].texName)); + RenderSettings.skybox.SetVector("_Vector4", newState.layer[1].texSpeed); + RenderSettings.skybox.SetFloat("_Alpha4", newState.layer[1].texAlpha / 255f); + + RenderSettings.skybox.SetColor("_Color", oldDomeColor); + RenderSettings.skybox.SetColor("_Color2", newDomeColor); + + RenderSettings.skybox.SetColor("_FogColor", oldFogColor); + RenderSettings.skybox.SetColor("_FogColor2", newFogColor); + + RenderSettings.skybox.SetFloat("_Blend", lerpFraction); + DynamicGI.UpdateEnvironment(); + } + + /// + /// Find the previous and next state indices based on the current master time. + /// + private (int previousIndex, int nextIndex) FindNextStateIndex() + { + var nextIndex = stateList.FindLastIndex(x => x.time < masterTime); + + if (nextIndex == -1) + { + nextIndex = 0; + } + + var previousIndex = nextIndex - 1; + if (previousIndex < 0) + previousIndex = stateList.Count - 1; + + return (previousIndex, nextIndex); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Manager/SkyManager.cs.meta b/Assets/GothicVR/Scripts/Manager/SkyManager.cs.meta new file mode 100644 index 000000000..21f0afab6 --- /dev/null +++ b/Assets/GothicVR/Scripts/Manager/SkyManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 46e9095c72bc48bfb33591c93b3dc5f5 +timeCreated: 1701696937 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/UI/TextureManager.cs b/Assets/GothicVR/Scripts/UI/TextureManager.cs index 157faf372..41e506e11 100644 --- a/Assets/GothicVR/Scripts/UI/TextureManager.cs +++ b/Assets/GothicVR/Scripts/UI/TextureManager.cs @@ -62,7 +62,6 @@ public void LoadLoadingDefaultTextures() sliderPositionMaterial.mainTexture = AssetCache.TryGetTexture("MENU_SLIDER_POS.TGA"); fillerMaterial.mainTexture = AssetCache.TryGetTexture("MENU_BUTTONBACK.TGA"); arrowMaterial.mainTexture = AssetCache.TryGetTexture("U.TGA"); - skyMaterial.mainTexture = AssetCache.TryGetTexture("SKYDAY_LAYER1_A0.TGA"); } public void SetTexture(string texture, Material material) diff --git a/Assets/GothicVR/Scripts/World/GameTime.cs b/Assets/GothicVR/Scripts/World/GameTime.cs index d35558a19..8db66a546 100644 --- a/Assets/GothicVR/Scripts/World/GameTime.cs +++ b/Assets/GothicVR/Scripts/World/GameTime.cs @@ -10,7 +10,7 @@ namespace GVR.World public class GameTime : SingletonBehaviour { public static readonly DateTime MIN_TIME = new(1, 1, 1, 0, 0, 0); - public static readonly DateTime MAX_TIME = new(1, 1, 1, 23, 59, 59); + public static readonly DateTime MAX_TIME = new(9999, 12, 31, 23, 59, 59); private int secondsInMinute = 0; private int minutesInHour = 0; @@ -66,7 +66,7 @@ private IEnumerator TimeTick() GvrEvents.GameTimeSecondChangeCallback.Invoke(time); RaiseMinuteAndHourEvent(); - yield return new WaitForSeconds(ONE_INGAME_SECOND); + yield return new WaitForSeconds(ONE_INGAME_SECOND / FeatureFlags.I.TimeMultiplier); } } private void RaiseMinuteAndHourEvent() @@ -88,5 +88,38 @@ private void RaiseHourEvent() GvrEvents.GameTimeHourChangeCallback.Invoke(time); } } + + public bool IsDay() + { + // 6:30 - 18:30 - values taken from gothic and regoth - https://github.com/REGoth-project/REGoth/blob/master/src/engine/GameClock.cpp#L126 + TimeSpan startOfDay = new TimeSpan(6, 30, 0); + TimeSpan endOfDay = new TimeSpan(18, 30, 0); + + TimeSpan currentTime = time.TimeOfDay; + + return currentTime >= startOfDay && currentTime <= endOfDay; + } + + public float GetSkyTime() + { + TimeSpan currentTime = time.TimeOfDay; + + double totalSecondsInADay = 24 * 60 * 60; + + double secondsPassedSinceNoon; + if (currentTime < TimeSpan.FromHours(12)) + { + secondsPassedSinceNoon = currentTime.TotalSeconds + 12 * 60 * 60; + } + else + { + secondsPassedSinceNoon = currentTime.TotalSeconds - 12 * 60 * 60; + } + + // Calculate sky time as a float between 0 and 1 + float skyTime = (float)(secondsPassedSinceNoon / totalSecondsInADay); + + return skyTime; + } } } diff --git a/Assets/GothicVR/Shaders/Skybox.shader b/Assets/GothicVR/Shaders/Skybox.shader new file mode 100644 index 000000000..fa1d5c75e --- /dev/null +++ b/Assets/GothicVR/Shaders/Skybox.shader @@ -0,0 +1,144 @@ +Shader "Unlit/SkyboxWithHorizonFog" +{ + Properties + { + _Color ("Color", Color) = (1,1,1,1) + _Color2 ("Color for transition", Color) = (1,1,1,1) + + [Header(Sky Layer Settings)] + _Sky1 ("1st Sky Layer", 2D) = "black" {} + _Vector1 ("1st Layer Movement", Vector) = (0,0,0,0) + _Alpha1 ("1st Layer Alpha", Range(0, 1)) = 1 + + _Sky2 ("2nd Sky Layer", 2D) = "black" {} + _Vector2 ("2nd Layer Movement", Vector) = (0,0,0,0) + _Alpha2 ("2nd Layer Alpha", Range(0, 1)) = 1 + + [Header(Sky Layer 2 Settings)] + _Sky3 ("1st Sky Layer", 2D) = "black" {} + _Vector3 ("1st Layer Movement", Vector) = (0,0,0,0) + _Alpha3 ("1st Layer Alpha", Range(0, 1)) = 1 + + _Sky4 ("2nd Sky Layer", 2D) = "black" {} + _Vector4 ("2nd Layer Movement", Vector) = (0,0,0,0) + _Alpha4 ("2nd Layer Alpha", Range(0, 1)) = 1 + + [Header(Fog Settings)] + _FogColor ("Fog Color", Color) = (1,1,1,1) + _FogColor2 ("Fog Color for transition", Color) = (1,1,1,1) + _FogCutoff ("Fog Cutoff", Range(0.0, 1.0)) = 0.25 + + _Blend ("Blend value", Range(0,1)) = 0 + + } + SubShader + { + Tags + { + "QUEUE"="Background" "RenderType"="Background" "PreviewType"="Skybox" + } + + Pass + { + Tags + { + "QUEUE"="Background" "RenderType"="Background" "PreviewType"="Skybox" + } + Blend Off + AlphaToMask Off + Cull Off + ColorMask RGBA + ZWrite Off + ZTest LEqual + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_fog + #pragma shader_feature FUZZY + #pragma multi_compile_instancing + #include "UnityCG.cginc" + #include "UnityShaderVariables.cginc" + #define ASE_NEEDS_VERT_POSITION + #pragma shader_feature_local _ENABLEFOG_ON + #pragma shader_feature_local _ENABLEROTATION_ON + + struct appdata + { + float4 vertex : POSITION; + float3 uv : TEXCOORD0; + }; + + struct v2f + { + float3 uv : TEXCOORD0; + UNITY_FOG_COORDS(1) + float4 vertex : SV_POSITION; + float3 worldPos : TEXCOORD2; + float4 screenPosition : TEXCOORD4; + float4 screenSpaceLightPos0 : TEXCOORD5; + + UNITY_VERTEX_OUTPUT_STEREO + }; + + sampler2D _Sky1, _Sky2, _Sky3, _Sky4; + fixed4 _Color, _Color2; + fixed4 _FogColor, _FogColor2; + float _Alpha1, _Alpha2, _Alpha3, _Alpha4; + float _FogCutoff, _Blend; + float2 _Vector1, _Vector2, _Vector3, _Vector4; + + v2f vert(appdata v) + { + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + UNITY_TRANSFER_FOG(o, o.vertex); + return o; + } + + fixed4 frag(v2f i) : SV_Target + { + float horizonFactor = (i.uv.y > 0) ? smoothstep(_FogCutoff, _FogCutoff + 0.1f, i.uv.y) : 0.0f; + + // uv for the sky + float2 skyUV = i.worldPos.xz / i.worldPos.y; + + float2 skyUV1 = skyUV + _Vector1.xy * _Time.x; + float2 skyUV2 = skyUV + _Vector2.xy * _Time.x; + float2 skyUV3 = skyUV + _Vector3.xy * _Time.x; + float2 skyUV4 = skyUV + _Vector4.xy * _Time.x; + + //stars 1st layer + float3 stars1 = lerp(tex2D(_Sky1, skyUV1) * _Alpha1, tex2D(_Sky3, skyUV3) * _Alpha3, _Blend); + //stars 2nd layer + float3 stars2 = lerp(tex2D(_Sky2, skyUV2) * _Alpha2, tex2D(_Sky4, skyUV4) * _Alpha4, _Blend); + + if (i.worldPos.y < 0) + { + stars1 = lerp(_Color, _Color2, _Blend); + stars2 = lerp(_Color, _Color2, _Blend); + } + + float3 combined = stars1 + stars2; + + // Calculate the base color of the skybox + float3 col = fixed4(combined, 1); + + // Calculate the fog color based on the horizon factor + float3 fogCol = lerp(lerp(_FogColor, _FogColor2, _Blend), combined, horizonFactor); + + // Apply Unity's built-in linear fog based on the fogCoords + UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fogCol); + return float4(col, 1); + } + ENDCG + } + } + FallBack "Diffuse" +} \ No newline at end of file diff --git a/Assets/GothicVR/Shaders/Skybox.shader.meta b/Assets/GothicVR/Shaders/Skybox.shader.meta new file mode 100644 index 000000000..339cb01cf --- /dev/null +++ b/Assets/GothicVR/Shaders/Skybox.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 93b46fd80ab75b048aedcb5df3194872 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: