Пример #1
0
 private void LoadDefaultLayerIfNeeded(ref WeatherMakerCloudVolumetricProfileScript script)
 {
     if (script == null)
     {
         script = Resources.Load <WeatherMakerCloudVolumetricProfileScript>("WeatherMakerCloudLayerProfileVolumetric_None");
     }
 }
 private void LoadDefaultLayerIfNeeded(ref WeatherMakerCloudVolumetricProfileScript script)
 {
     if (script == null && WeatherMakerScript.Instance != null)
     {
         script = WeatherMakerScript.Instance.LoadResource <WeatherMakerCloudVolumetricProfileScript>("WeatherMakerCloudLayerProfileVolumetric_None");
     }
 }
Пример #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");
            }
        }