/// <summary> /// Final Initilization and startup. /// </summary> private void Init() { if (profile == null) { return; } if (serverMode) { started = true; return; } InitImageEffects(); // Setup Camera if (PlayerCamera != null) { if (setCameraClearFlags) { PlayerCamera.clearFlags = CameraClearFlags.Skybox; } // Workaround for deferred forve HDR... if (PlayerCamera.actualRenderingPath == RenderingPath.DeferredShading) { SetCameraHDR(PlayerCamera, true); } else { SetCameraHDR(PlayerCamera, HDR); } Components.GlobalReflectionProbe.myProbe.farClipPlane = PlayerCamera.farClipPlane; } started = true; //Render moon once always on start if (MoonShader != null) { MoonShader.SetFloat("_Phase", customMoonPhase); MoonShader.SetColor("_Color", skySettings.moonColor); MoonShader.SetFloat("_Brightness", skySettings.moonBrightness * (1 - GameTime.solarTime)); } }
private void SetMaterialsVariables() { //Simple skyMat.SetColor("_SkyColor", skySettings.simpleSkyColor.Evaluate(GameTime.solarTime)); skyMat.SetColor("_HorizonColor", skySettings.simpleHorizonColor.Evaluate(GameTime.solarTime)); skyMat.SetColor("_SunColor", skySettings.simpleSunColor.Evaluate(GameTime.solarTime)); skyMat.SetFloat("_SunDiskSizeSimple", skySettings.simpleSunDiskSize.Evaluate(GameTime.solarTime)); skyMat.SetFloat("_StarsIntensity", skySettings.starsIntensity.Evaluate(GameTime.solarTime)); //Clouds skyMat.SetVector("_CloudAnimation", cirrusAnim); //cirrus if (cloudsSettings.cirrusCloudsTexture != null) { skyMat.SetTexture("_CloudMap", cloudsSettings.cirrusCloudsTexture); } skyMat.SetColor("_CloudColor", cloudsSettings.cirrusCloudsColor.Evaluate(GameTime.solarTime)); skyMat.SetFloat("_CloudAltitude", cloudsSettings.cirrusCloudsAltitude); skyMat.SetFloat("_CloudAlpha", cloudsConfig.cirrusAlpha); skyMat.SetFloat("_CloudCoverage", cloudsConfig.cirrusCoverage); skyMat.SetFloat("_CloudColorPower", cloudsConfig.cirrusColorPow); //Globals Shader.SetGlobalVector("_SunDir", -Components.Sun.transform.forward); Shader.SetGlobalColor("_EnviroLighting", lightSettings.LightColor.Evaluate(GameTime.solarTime)); // Moon Shader.SetGlobalVector("_SunPosition", Components.Sun.transform.localPosition + (-Components.Sun.transform.forward * 10000f)); Shader.SetGlobalVector("_MoonPosition", Components.Moon.transform.localPosition); //Color Mods Shader.SetGlobalColor("_weatherSkyMod", Color.Lerp(currentWeatherSkyMod, interiorZoneSettings.currentInteriorSkyboxMod, interiorZoneSettings.currentInteriorSkyboxMod.a)); Shader.SetGlobalColor("_weatherFogMod", Color.Lerp(currentWeatherFogMod, interiorZoneSettings.currentInteriorFogColorMod, interiorZoneSettings.currentInteriorFogColorMod.a)); //Fog Shader.SetGlobalVector("_EnviroSkyFog", new Vector4(Fog.skyFogHeight, Fog.skyFogIntensity, Fog.skyFogStart, fogSettings.heightFogIntensity)); Shader.SetGlobalFloat("_distanceFogIntensity", fogSettings.distanceFogIntensity); if (Application.isPlaying) { Shader.SetGlobalFloat("_maximumFogDensity", 1 - fogSettings.maximumFogDensity); } else { Shader.SetGlobalFloat("_maximumFogDensity", 1f); } if (fogSettings.useSimpleFog) { Shader.EnableKeyword("ENVIRO_SIMPLE_FOG"); Shader.SetGlobalVector("_EnviroParams", new Vector4(Mathf.Clamp(1f - GameTime.solarTime, 0.5f, 1f), fogSettings.distanceFog ? 1f : 0f, 0f, HDR ? 1f : 0f)); } else { Shader.SetGlobalColor("_scatteringColor", skySettings.scatteringColor.Evaluate(GameTime.solarTime)); Shader.SetGlobalFloat("_scatteringStrenght", Fog.scatteringStrenght); Shader.SetGlobalFloat("_scatteringPower", skySettings.scatteringCurve.Evaluate(GameTime.solarTime)); Shader.SetGlobalFloat("_SunBlocking", Fog.sunBlocking); Shader.SetGlobalVector("_EnviroParams", new Vector4(Mathf.Clamp(1f - GameTime.solarTime, 0.5f, 1f), fogSettings.distanceFog ? 1f : 0f, fogSettings.heightFog ? 1f : 0f, HDR ? 1f : 0f)); Shader.SetGlobalVector("_Bm", BetaMie(skySettings.turbidity, skySettings.waveLength) * (skySettings.mie * (Fog.scatteringStrenght * GameTime.solarTime))); Shader.SetGlobalVector("_BmScene", BetaMie(skySettings.turbidity, skySettings.waveLength) * (fogSettings.mie * (Fog.scatteringStrenght * GameTime.solarTime))); Shader.SetGlobalVector("_Br", BetaRay(skySettings.waveLength) * skySettings.rayleigh); Shader.SetGlobalVector("_mieG", GetMieG(skySettings.g)); Shader.SetGlobalVector("_mieGScene", GetMieGScene(skySettings.g)); Shader.SetGlobalVector("_SunParameters", new Vector4(skySettings.sunIntensity, skySettings.sunDiskScale, skySettings.sunDiskIntensity, 0f)); Shader.SetGlobalFloat("_Exposure", skySettings.skyExposure); Shader.SetGlobalFloat("_SkyLuminance", skySettings.skyLuminence.Evaluate(GameTime.solarTime)); Shader.SetGlobalFloat("_SkyColorPower", skySettings.skyColorPower.Evaluate(GameTime.solarTime)); Shader.SetGlobalFloat("_heightFogIntensity", fogSettings.heightFogIntensity); Shader.SetGlobalFloat("_lightning", thunder); Shader.DisableKeyword("ENVIRO_SIMPLE_FOG"); } Shader.DisableKeyword("ENVIROVOLUMELIGHT"); if (MoonShader != null) { MoonShader.SetFloat("_Phase", customMoonPhase); MoonShader.SetColor("_Color", skySettings.moonColor); MoonShader.SetFloat("_Brightness", skySettings.moonBrightness * (1 - GameTime.solarTime)); MoonShader.SetFloat("_moonFogIntensity", Fog.moonIntensity); } }
/// <summary> /// Pee-Initilize the system. /// </summary> private void PreInit() { // Check time if (GameTime.solarTime < GameTime.dayNightSwitch) { isNight = true; } else { isNight = false; } //return when in server mode! if (serverMode) { return; } CheckSatellites(); // Setup Fog Mode RenderSettings.fogMode = fogSettings.Fogmode; // Setup Skybox Material SetupSkybox(); // Set ambient mode RenderSettings.ambientMode = lightSettings.ambientMode; // Set Fog //RenderSettings.fogDensity = 0f; //RenderSettings.fogStartDistance = 0f; //RenderSettings.fogEndDistance = 1000f; // Setup ReflectionProbe if (Components.GlobalReflectionProbe == null) { GameObject temp; foreach (Transform child in transform) { if (child.name == "GlobalReflections") { temp = child.gameObject; Components.GlobalReflectionProbe = temp.GetComponent <EnviroReflectionProbe>(); if (Components.GlobalReflectionProbe == null) { Components.GlobalReflectionProbe = temp.AddComponent <EnviroReflectionProbe>(); } } } } if (!Components.Sun) { Debug.LogError("Please set sun object in inspector!"); } if (!Components.satellites) { Debug.LogError("Please set satellite object in inspector!"); } if (Components.Moon) { MoonTransform = Components.Moon.transform; MoonRenderer = Components.Moon.GetComponent <Renderer>(); if (MoonRenderer == null) { MoonRenderer = Components.Moon.AddComponent <MeshRenderer>(); } MoonRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MoonRenderer.receiveShadows = false; if (MoonRenderer.sharedMaterial != null) { DestroyImmediate(MoonRenderer.sharedMaterial); } if (skySettings.moonPhaseMode == EnviroSkySettings.MoonPhases.Realistic) { MoonShader = new Material(Shader.Find("Enviro/Lite/MoonShader")); } else { MoonShader = new Material(Shader.Find("Enviro/Lite/MoonShaderPhased")); } MoonShader.SetTexture("_MainTex", skySettings.moonTexture); MoonRenderer.sharedMaterial = MoonShader; // Set start moon phase customMoonPhase = skySettings.startMoonPhase; } else { Debug.LogError("Please set moon object in inspector!"); } if (lightSettings.directionalLightMode == EnviroLightSettings.LightingMode.Single) { SetupMainLight(); } else { SetupMainLight(); SetupAdditionalLight(); } if (Components.particleClouds) { ParticleSystem[] systems = Components.particleClouds.GetComponentsInChildren <ParticleSystem>(); if (systems.Length > 0) { particleClouds.layer1System = systems[0]; } if (systems.Length > 1) { particleClouds.layer2System = systems[1]; } if (particleClouds.layer1System != null) { particleClouds.layer1Material = particleClouds.layer1System.GetComponent <ParticleSystemRenderer>().sharedMaterial; } if (particleClouds.layer2System != null) { particleClouds.layer2Material = particleClouds.layer2System.GetComponent <ParticleSystemRenderer>().sharedMaterial; } } else { Debug.LogError("Please set particleCLouds object in inspector!"); } }
/// <summary> /// Pee-Initilize the system. /// </summary> private void PreInit() { // Check time if (GameTime.solarTime < GameTime.dayNightSwitch) { isNight = true; } else { isNight = false; } //return when in server mode! if (serverMode) { return; } CheckSatellites(); // Setup Fog Mode RenderSettings.fogMode = fogSettings.Fogmode; // Setup Skybox Material SetupSkybox(); // Set ambient mode RenderSettings.ambientMode = lightSettings.ambientMode; // Set Fog //RenderSettings.fogDensity = 0f; //RenderSettings.fogStartDistance = 0f; //RenderSettings.fogEndDistance = 1000f; // Setup ReflectionProbe Components.GlobalReflectionProbe.size = transform.localScale; Components.GlobalReflectionProbe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting; if (!Components.Sun) { Debug.LogError("Please set sun object in inspector!"); } if (!Components.satellites) { Debug.LogError("Please set satellite object in inspector!"); } if (Components.Moon) { MoonTransform = Components.Moon.transform; MoonRenderer = Components.Moon.GetComponent <Renderer>(); if (MoonRenderer == null) { MoonRenderer = Components.Moon.AddComponent <MeshRenderer>(); } MoonRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MoonRenderer.receiveShadows = false; if (MoonRenderer.sharedMaterial != null) { DestroyImmediate(MoonRenderer.sharedMaterial); } if (skySettings.moonPhaseMode == EnviroSkySettings.MoonPhases.Realistic) { MoonShader = new Material(Shader.Find("Enviro/Lite/MoonShader")); } else { MoonShader = new Material(Shader.Find("Enviro/Lite/MoonShaderPhased")); } MoonShader.SetTexture("_MainTex", skySettings.moonTexture); MoonRenderer.sharedMaterial = MoonShader; // Set start moon phase customMoonPhase = skySettings.startMoonPhase; } else { Debug.LogError("Please set moon object in inspector!"); } if (Components.DirectLight) { if (Components.DirectLight.name == "Direct Lght") { DestroyImmediate(Components.DirectLight.gameObject); Components.DirectLight = CreateDirectionalLight(); } MainLight = Components.DirectLight.GetComponent <Light>(); if (EnviroSkyMgr.instance.dontDestroy && Application.isPlaying) { DontDestroyOnLoad(Components.DirectLight); } } else { GameObject oldLight = GameObject.Find("Enviro Directional Light"); if (oldLight != null) { Components.DirectLight = oldLight.transform; } else { Components.DirectLight = CreateDirectionalLight(); } MainLight = Components.DirectLight.GetComponent <Light>(); if (EnviroSkyMgr.instance.dontDestroy && Application.isPlaying) { DontDestroyOnLoad(Components.DirectLight); } } if (Components.particleClouds) { ParticleSystem[] systems = Components.particleClouds.GetComponentsInChildren <ParticleSystem>(); if (systems.Length > 0) { particleClouds.layer1System = systems[0]; } if (systems.Length > 1) { particleClouds.layer2System = systems[1]; } if (particleClouds.layer1System != null) { particleClouds.layer1Material = particleClouds.layer1System.GetComponent <ParticleSystemRenderer>().sharedMaterial; } if (particleClouds.layer2System != null) { particleClouds.layer2Material = particleClouds.layer2System.GetComponent <ParticleSystemRenderer>().sharedMaterial; } } else { Debug.LogError("Please set particleCLouds object in inspector!"); } }