/// <summary>
 /// Perform updates to the sky sphere based on profile settings
 /// </summary>
 /// <param name="camera">Current camera</param>
 /// <param name="material">Sky sphere material</param>
 /// <param name="skySphere">Sky sphere game object</param>
 /// <param name="sun">The sun</param>
 public void UpdateSkySphere(Camera camera, Material material, GameObject skySphere, WeatherMakerCelestialObjectScript sun)
 {
     if (material == null || WeatherMakerLightManagerScript.Instance == null || sun == null)
     {
         return;
     }
     if (!SystemInfo.supportsComputeShaders)
     {
         if (SkyMode == WeatherMakeSkyMode.ProceduralPhysicallyBased)
         {
             SkyMode = WeatherMakeSkyMode.ProceduralUnityStyle;
         }
         else if (SkyMode == WeatherMakeSkyMode.ProceduralTexturedPhysicallyBased)
         {
             SkyMode = WeatherMakeSkyMode.ProceduralTexturedUnityStyle;
         }
     }
     SetSkySphereScalesAndPositions(camera, skySphere);
     SetShaderLightParameters(material);
     RaycastForEclipse(camera, material);
     SetShaderSkyParameters(camera, material, sun);
     shaderProps = (shaderProps ?? new WeatherMakerShaderPropertiesScript(material));
     shaderProps.Update(material);
     //WeatherMakerLightManagerScript.Instance.UpdateShaderVariables(camera, shaderProps, null);
 }
 /// <summary>
 /// Perform updates to the sky plane based on profile settings
 /// </summary>
 /// <param name="camera">Current camera</param>
 /// <param name="material">Sky sphere material</param>
 /// <param name="skyPlane">Sky plane game object</param>
 /// <param name="sun">The sun</param>
 public void UpdateSkyPlane(Camera camera, Material material, GameObject skyPlane, WeatherMakerCelestialObjectScript sun)
 {
     if (material == null || WeatherMakerLightManagerScript.Instance == null || sun == null)
     {
         return;
     }
     SetSkyPlaneScalesAndPositions(camera, skyPlane);
     SetShaderLightParameters(material);
     SetShaderSkyParameters(camera, material, sun);
     shaderProps = (shaderProps ?? new WeatherMakerShaderPropertiesScript(material));
     shaderProps.Update(material);
     //WeatherMakerLightManagerScript.Instance.UpdateShaderVariables(camera, shaderProps, null);
 }
示例#3
0
        public void SetShaderCloudParameters(Material cloudMaterial, ComputeShader cloudProbe, Camera camera, Texture weatherMap)
        {
            if (WeatherMakerScript.Instance == null ||
                WeatherMakerScript.Instance.PerformanceProfile == null ||
                WeatherMakerDayNightCycleManagerScript.Instance == null ||
                WeatherMakerLightManagerScript.Instance == null)
            {
                return;
            }

            WeatherMakerCelestialObjectScript sun = (camera == null || !camera.orthographic ? WeatherMakerLightManagerScript.Instance.SunPerspective : WeatherMakerLightManagerScript.Instance.SunOrthographic);

            if (sun == null)
            {
                return;
            }

            if (!isAnimating)
            {
                CloudLayerVolumetric1.CloudDirLightGradientColorColor  = sun.GetGradientColor(CloudLayerVolumetric1.CloudDirLightGradientColor);
                CloudLayerVolumetric1.CloudGradientStratusVector       = WeatherMakerCloudVolumetricProfileScript.CloudHeightGradientToVector4(CloudLayerVolumetric1.CloudGradientStratus);
                CloudLayerVolumetric1.CloudGradientStratoCumulusVector = WeatherMakerCloudVolumetricProfileScript.CloudHeightGradientToVector4(CloudLayerVolumetric1.CloudGradientStratoCumulus);
                CloudLayerVolumetric1.CloudGradientCumulusVector       = WeatherMakerCloudVolumetricProfileScript.CloudHeightGradientToVector4(CloudLayerVolumetric1.CloudGradientCumulus);
            }

            shaderProps.Update(null);
            SetShaderVolumetricCloudShaderProperties(shaderProps, weatherMap, sun);
            if (cloudProbe != null)
            {
                shaderProps.Update(cloudProbe);
                SetShaderVolumetricCloudShaderProperties(shaderProps, weatherMap, sun);
            }

            Shader.SetGlobalInt(WMS._WeatherMakerCloudVolumetricShadowSampleCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudShadowSampleCount);

            if (CloudsEnabled)
            {
                float cover = Mathf.Min(1.0f, CloudCoverTotal * (1.5f - CloudLightAbsorptionTotal));
                float sunIntensityMultiplier = Mathf.Clamp(1.0f - (cover * CloudLightStrength), 0.2f, 1.0f);
                float sunIntensityMultiplierWithoutLightStrength = Mathf.Clamp(1.0f - (cover * cover * 0.85f), 0.2f, 1.0f);
                float cloudShadowReducer = sunIntensityMultiplierWithoutLightStrength;
                float dirLightMultiplier = sunIntensityMultiplier * Mathf.Lerp(1.0f, DirectionalLightIntensityMultiplier, cover);
                Shader.SetGlobalFloat(WMS._WeatherMakerCloudGlobalShadow2, cloudShadowReducer);
                CloudGlobalShadow = cloudShadowReducer = Mathf.Min(cloudShadowReducer, Shader.GetGlobalFloat(WMS._WeatherMakerCloudGlobalShadow));
                CloudDirectionalLightDirectBlock = dirLightMultiplier;

                // if we have shadows turned on, use screen space shadows
                if (QualitySettings.shadows != ShadowQuality.Disable && WeatherMakerLightManagerScript.ScreenSpaceShadowMode != UnityEngine.Rendering.BuiltinShaderMode.Disabled &&
                    WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudShadowDownsampleScale != WeatherMakerDownsampleScale.Disabled &&
                    WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudShadowSampleCount > 0)
                {
                    // do not reduce light intensity or shadows, screen space shadows are being used
                    WeatherMakerLightManagerScript.Instance.DirectionalLightIntensityMultipliers.Remove("WeatherMakerFullScreenCloudsScript");
                    Shader.SetGlobalFloat(WMS._WeatherMakerDirLightMultiplier, 1.0f);
                    Shader.SetGlobalFloat(WMS._WeatherMakerCloudGlobalShadow, 1.0f);
                }
                else
                {
                    // save dir light multiplier so flat clouds can adjust to the dimmed light
                    Shader.SetGlobalFloat(WMS._WeatherMakerDirLightMultiplier, 1.0f / Mathf.Max(0.0001f, dirLightMultiplier));
                    Shader.SetGlobalFloat(WMS._WeatherMakerCloudGlobalShadow, cloudShadowReducer);

                    // brighten up on orthographic, looks better
                    if (WeatherMakerScript.Instance.MainCamera != null && WeatherMakerScript.Instance.MainCamera.orthographic)
                    {
                        sunIntensityMultiplier = Mathf.Min(1.0f, sunIntensityMultiplier * 2.0f);
                    }

                    // we rely on sun intensity reduction to fake shadows
                    WeatherMakerLightManagerScript.Instance.DirectionalLightIntensityMultipliers["WeatherMakerFullScreenCloudsScript"] = dirLightMultiplier;
                }
            }
            else
            {
                WeatherMakerLightManagerScript.Instance.DirectionalLightIntensityMultipliers.Remove("WeatherMakerFullScreenCloudsScript");
                WeatherMakerLightManagerScript.Instance.DirectionalLightShadowIntensityMultipliers.Remove("WeatherMakerFullScreenCloudsScript");
            }
        }