/// <summary> /// Update a fog material with fog properties from this object /// </summary> /// <param name="material">Fog material</param> /// <param name="camera">Camera</param> /// <param name="global">Whether to set global shader properties</param> public virtual void UpdateMaterialProperties(Material material, Camera camera, bool global) { WeatherMakerCelestialObjectScript sun = WeatherMakerLightManagerScript.SunForCamera(camera); if (sun == null) { return; } fogLightAbsorption = (FogLightAbsorption == null ? 0.4f : sun.GetGradientColor(FogLightAbsorption).a); bool gamma = (QualitySettings.activeColorSpace == ColorSpace.Gamma); float scatterCover = (WeatherMakerFullScreenCloudsScript.Instance != null && WeatherMakerFullScreenCloudsScript.Instance.enabled && WeatherMakerFullScreenCloudsScript.Instance.CloudProfile != null ? WeatherMakerFullScreenCloudsScript.Instance.CloudProfile.CloudCoverTotal : 0.0f); scatterCover = Mathf.Pow(scatterCover, 4.0f); Color fogEmissionColor = FogEmissionColor * FogEmissionColor.a; fogEmissionColor.a = FogEmissionColor.a; float fogNoiseSampleCount = (float)(WeatherMakerScript.Instance == null ? FogNoiseSampleCount : WeatherMakerScript.Instance.PerformanceProfile.FogNoiseSampleCount); float invFogNoiseSampleCount = 1.0f / fogNoiseSampleCount; int hasNoiseInt = (HasNoise ? 1 : 0); float ditherLevel = (gamma ? DitherLevel : DitherLevel * 0.5f); Color fogDensityColor = sun.GetGradientColor(FogDensityGradient); fogDensity = FogDensity * fogDensityColor.a; if (!(this is WeatherMakerFullScreenFogProfileScript) || FogMode == WeatherMakerFogMode.None || fogDensity <= 0.0f || MaxFogFactor <= 0.001f) { fogScatterReduction = 1.0f; } else if (FogMode == WeatherMakerFogMode.Exponential) { fogScatterReduction = Mathf.Clamp(1.0f - ((fogDensity + scatterCover) * 0.5f), 0.15f, 1.0f); } else if (FogMode == WeatherMakerFogMode.Linear) { fogScatterReduction = Mathf.Clamp((1.0f - ((fogDensity + scatterCover) * 0.25f)), 0.15f, 1.0f); } else if (FogMode == WeatherMakerFogMode.ExponentialSquared) { fogScatterReduction = Mathf.Clamp((1.0f - ((fogDensity + scatterCover) * 0.75f)), 0.15f, 1.0f); } else if (FogMode == WeatherMakerFogMode.Constant) { fogScatterReduction = Mathf.Clamp(1.0f - (fogDensity + scatterCover), 0.5f, 1.0f); } if (global) { Shader.SetGlobalFloat(WMS._WeatherMakerFogDensityScatter, fogScatterReduction); Shader.SetGlobalInt(WMS._WeatherMakerFogNoiseEnabled, hasNoiseInt); } else { material.SetFloat(WMS._WeatherMakerFogDensityScatter, fogScatterReduction); material.SetInt(WMS._WeatherMakerFogNoiseEnabled, hasNoiseInt); } if (WeatherMakerScript.Instance == null || WeatherMakerScript.Instance.PerformanceProfile.EnableFogLights) { float fogShadowSampleCount = (float)(WeatherMakerScript.Instance == null ? FogShadowSampleCount : WeatherMakerScript.Instance.PerformanceProfile.FogShadowSampleCount); float brightness = Mathf.Min(sun.Light.intensity, Mathf.Pow(sun.Light.intensity, 2.0f)); if (QualitySettings.shadows != ShadowQuality.Disable && fogShadowSampleCount > 0 && sun.Light.intensity > 0.0f && sun.Light.shadows != LightShadows.None && FogShadowMaxRayLength > 0.0f && brightness > 0.0f) { float invFogShadowSampleCount = 1.0f / fogShadowSampleCount; float fogShadowBrightness = brightness * FogShadowBrightness; if (global) { Shader.SetGlobalInt(WMS._WeatherMakerFogVolumetricLightMode, 2); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowSampleCount, fogShadowSampleCount); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowInvSampleCount, invFogShadowSampleCount); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowMaxRayLength, FogShadowMaxRayLength); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowMultiplier, FogShadowMultiplier); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowPower, FogShadowPower); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowBrightness, fogShadowBrightness); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowDecay, FogShadowDecay); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightShadowDither, FogShadowDither); Shader.SetGlobalVector(WMS._WeatherMakerFogLightShadowDitherMagic, FogShadowDitherMagic); Shader.SetGlobalFloat(WMS._WeatherMakerFogCloudShadowStrength, FogCloudShadowStrength); } else { material.SetInt(WMS._WeatherMakerFogVolumetricLightMode, 2); material.SetFloat(WMS._WeatherMakerFogLightShadowSampleCount, fogShadowSampleCount); material.SetFloat(WMS._WeatherMakerFogLightShadowInvSampleCount, invFogShadowSampleCount); material.SetFloat(WMS._WeatherMakerFogLightShadowMaxRayLength, FogShadowMaxRayLength); material.SetFloat(WMS._WeatherMakerFogLightShadowMultiplier, FogShadowMultiplier); material.SetFloat(WMS._WeatherMakerFogLightShadowPower, FogShadowPower); material.SetFloat(WMS._WeatherMakerFogLightShadowBrightness, fogShadowBrightness); material.SetFloat(WMS._WeatherMakerFogLightShadowDecay, FogShadowDecay); material.SetFloat(WMS._WeatherMakerFogLightShadowDither, FogShadowDither); material.SetVector(WMS._WeatherMakerFogLightShadowDitherMagic, FogShadowDitherMagic); material.SetFloat(WMS._WeatherMakerFogCloudShadowStrength, FogCloudShadowStrength); } } else { if (global) { Shader.SetGlobalInt(WMS._WeatherMakerFogVolumetricLightMode, 1); } else { material.SetInt(WMS._WeatherMakerFogVolumetricLightMode, 1); } } } else { if (global) { Shader.SetGlobalInt(WMS._WeatherMakerFogVolumetricLightMode, 0); } else { material.SetInt(WMS._WeatherMakerFogVolumetricLightMode, 0); } } Color fogColor = sun.GetGradientColor(FogGradientColor) * FogColor; FogEndDepth = Mathf.Max(FogStartDepth, FogEndDepth); float endDepth = (FogEndDepth <= FogStartDepth ? FogStartDepth + 5000.0f : FogEndDepth); float fogLinearFogFactor = 0.1f * (1.0f / Mathf.Max(0.0001f, (endDepth - FogStartDepth))) * fogDensity * (endDepth - FogStartDepth); if (global) { Shader.SetGlobalFloat(WMS._WeatherMakerFogStartDepth, FogStartDepth); Shader.SetGlobalFloat(WMS._WeatherMakerFogEndDepth, endDepth); Shader.SetGlobalColor(WMS._WeatherMakerFogColor, fogColor); Shader.SetGlobalColor(WMS._WeatherMakerFogEmissionColor, fogEmissionColor); Shader.SetGlobalFloat(WMS._WeatherMakerFogHeightFalloffPower, FogHeightFalloffPower); Shader.SetGlobalFloat(WMS._WeatherMakerFogLightAbsorption, fogLightAbsorption); Shader.SetGlobalFloat(WMS._WeatherMakerFogLinearFogFactor, fogLinearFogFactor); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoisePercent, fogNoisePercent); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoiseScale, FogNoiseScale); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoiseAdder, FogNoiseAdder); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoiseMultiplier, FogNoiseMultiplier); Shader.SetGlobalVector(WMS._WeatherMakerFogNoiseVelocity, fogNoiseVelocityAccum); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoiseSampleCount, fogNoiseSampleCount); Shader.SetGlobalFloat(WMS._WeatherMakerFogNoiseSampleCountInverse, invFogNoiseSampleCount); Shader.SetGlobalVector(WMS._WeatherMakerFogNoisePositionOffset, fogNoisePositionOffset); Shader.SetGlobalFloat(WMS._WeatherMakerFogFactorMax, MaxFogFactor); Shader.SetGlobalInt(WMS._WeatherMakerFogMode, (int)FogMode); Shader.SetGlobalFloat(WMS._WeatherMakerFogDitherLevel, ditherLevel); Shader.SetGlobalFloat(WMS._WeatherMakerFogDensity, fogDensity); Shader.SetGlobalFloat(WMS._WeatherMakerFogFactorMultiplier, FogFactorMultiplier); } else { material.SetFloat(WMS._WeatherMakerFogStartDepth, FogStartDepth); material.SetFloat(WMS._WeatherMakerFogEndDepth, endDepth); material.SetColor(WMS._WeatherMakerFogColor, fogColor); material.SetColor(WMS._WeatherMakerFogEmissionColor, fogEmissionColor); material.SetFloat(WMS._WeatherMakerFogHeightFalloffPower, FogHeightFalloffPower); material.SetFloat(WMS._WeatherMakerFogLightAbsorption, fogLightAbsorption); material.SetFloat(WMS._WeatherMakerFogLinearFogFactor, fogLinearFogFactor); material.SetFloat(WMS._WeatherMakerFogNoisePercent, fogNoisePercent); material.SetFloat(WMS._WeatherMakerFogNoiseScale, FogNoiseScale); material.SetFloat(WMS._WeatherMakerFogNoiseAdder, FogNoiseAdder); material.SetFloat(WMS._WeatherMakerFogNoiseMultiplier, FogNoiseMultiplier); material.SetVector(WMS._WeatherMakerFogNoiseVelocity, fogNoiseVelocityAccum); material.SetFloat(WMS._WeatherMakerFogNoiseSampleCount, fogNoiseSampleCount); material.SetFloat(WMS._WeatherMakerFogNoiseSampleCountInverse, invFogNoiseSampleCount); material.SetVector(WMS._WeatherMakerFogNoisePositionOffset, fogNoisePositionOffset); material.SetFloat(WMS._WeatherMakerFogFactorMax, MaxFogFactor); material.SetInt(WMS._WeatherMakerFogMode, (int)FogMode); material.SetFloat(WMS._WeatherMakerFogDitherLevel, ditherLevel); material.SetFloat(WMS._WeatherMakerFogDensity, fogDensity); material.SetFloat(WMS._WeatherMakerFogFactorMultiplier, FogFactorMultiplier); } }
internal static void SetGlobalSkyParameters(Gradient skyGradient, Gradient skyGroundGradient, float skyAtmosphereMie, float skyMieMultiplier, float skyRayleighMultiplier, float skyAtmosphereThickness, float skyAtmosphereTurbidity, float skyExposure, Color skyTintColor, float skyOuterRadius, float skyInnerRadius, float skyCameraHeight, Vector4 waveLength, WeatherMakerCelestialObjectScript sun) { if (sun == null) { return; } // global sky parameters float mieG = -skyAtmosphereMie; float mieG2 = mieG * mieG; float mieConstant = 0.001f * skyMieMultiplier; float rayleighConstant = 0.0025f * skyRayleighMultiplier; rayleighConstant = Mathf.LerpUnclamped(0.0f, rayleighConstant, Mathf.Pow(skyAtmosphereThickness, 2.5f)); float redColor = waveLength.x; float greenColor = waveLength.y; float blueColor = waveLength.z; float lightRange = waveLength.w; float lightWaveLengthRedTint = Mathf.Lerp(redColor - lightRange, redColor + lightRange, 1.0f - skyTintColor.r); float lightWaveLengthGreenTint = Mathf.Lerp(greenColor - lightRange, greenColor + lightRange, 1.0f - skyTintColor.g); float lightWaveLengthBlueTint = Mathf.Lerp(blueColor - lightRange, blueColor + lightRange, 1.0f - skyTintColor.b); float lightWaveLengthRed4 = lightWaveLengthRedTint * lightWaveLengthRedTint * lightWaveLengthRedTint * lightWaveLengthRedTint; float lightWaveLengthGreen4 = lightWaveLengthGreenTint * lightWaveLengthGreenTint * lightWaveLengthGreenTint * lightWaveLengthGreenTint; float lightWaveLengthBlue4 = lightWaveLengthBlueTint * lightWaveLengthBlueTint * lightWaveLengthBlueTint * lightWaveLengthBlueTint; float lightInverseWaveLengthRed4 = 1.0f / lightWaveLengthRed4; float lightInverseWaveLengthGreen4 = 1.0f / lightWaveLengthGreen4; float lightInverseWaveLengthBlue4 = 1.0f / lightWaveLengthBlue4; const float sunBrightnessFactor = 40.0f; float sunRed = rayleighConstant * sunBrightnessFactor * lightInverseWaveLengthRed4; float sunGreen = rayleighConstant * sunBrightnessFactor * lightInverseWaveLengthGreen4; float sunBlue = rayleighConstant * sunBrightnessFactor * lightInverseWaveLengthBlue4; float sunIntensity = mieConstant * sunBrightnessFactor; float pi4Red = rayleighConstant * 4.0f * skyAtmosphereTurbidity * Mathf.PI * lightInverseWaveLengthRed4; float pi4Green = rayleighConstant * 4.0f * skyAtmosphereTurbidity * Mathf.PI * lightInverseWaveLengthGreen4; float pi4Blue = rayleighConstant * 4.0f * skyAtmosphereTurbidity * Mathf.PI * lightInverseWaveLengthBlue4; float pi4Intensity = mieConstant * 4.0f * skyAtmosphereTurbidity * Mathf.PI; float scaleFactor = 1.0f / (skyOuterRadius - 1.0f); const float scaleDepth = 0.25f; float scaleOverScaleDepth = scaleFactor / scaleDepth; if (sun != null) { Vector4 col = sun.GetGradientColor(skyGradient) * skyTintColor; col *= skyExposure; Shader.SetGlobalVector(WMS._WeatherMakerSkyTintColor, col); float mieDot = sun.GetSunMieDot(); Shader.SetGlobalVector(WMS._WeatherMakerSkyMieG, new Vector4(mieG, mieG2, -mieG, mieDot)); col = sun.GetGradientColor(skyGroundGradient); Shader.SetGlobalVector(WMS._WeatherMakerSkyGroundColor, col); } Shader.SetGlobalVector(WMS._WeatherMakerSkyAtmosphereParams, new Vector4(skyAtmosphereThickness, skyAtmosphereTurbidity, skyExposure, 0.0f)); Shader.SetGlobalVector(WMS._WeatherMakerSkyRadius, new Vector4(skyOuterRadius, skyOuterRadius * skyOuterRadius, skyInnerRadius, skyInnerRadius * skyInnerRadius)); Shader.SetGlobalVector(WMS._WeatherMakerSkyMie, new Vector4(1.5f * ((1.0f - mieG2) / (2.0f + mieG2)), 1.0f + mieG2, 2.0f + mieG, 0.0f)); Shader.SetGlobalVector(WMS._WeatherMakerSkyLightScattering, new Vector4(sunRed, sunGreen, sunBlue, sunIntensity)); Shader.SetGlobalVector(WMS._WeatherMakerSkyLightPIScattering, new Vector4(pi4Red, pi4Green, pi4Blue, pi4Intensity)); Shader.SetGlobalVector(WMS._WeatherMakerSkyScale, new Vector4(scaleFactor, scaleDepth, scaleOverScaleDepth, Mathf.Max(0.0f, skyCameraHeight) * 0.000001f)); // reduce wave length for preetham sky formulas waveLength *= 1E-6f; Shader.SetGlobalVector(WMS._WeatherMakerSkyTotalRayleigh, GetTotalRayleigh(waveLength, skyRayleighMultiplier * skyAtmosphereThickness, sun)); Shader.SetGlobalVector(WMS._WeatherMakerSkyTotalMie, GetTotalMie(waveLength, skyAtmosphereTurbidity, skyMieMultiplier, sun)); }
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"); } }
private void SetShaderVolumetricCloudShaderProperties(WeatherMakerShaderPropertiesScript props, Texture weatherMap, WeatherMakerCelestialObjectScript sun) { props.SetVector(WMS._WeatherMakerCloudCameraPosition, CloudCameraPosition); props.SetTexture(WMS._WeatherMakerWeatherMapTexture, weatherMap); props.SetVector(WMS._WeatherMakerWeatherMapScale, new Vector4(WeatherMapScale.x, WeatherMapScale.y, WeatherMapScale.z, 1.0f / WeatherMapScale.z)); props.SetFloat(WMS._CloudCoverVolumetric, CloudLayerVolumetric1.CloudCover.LastValue); props.SetFloat(WMS._CloudCoverSecondaryVolumetric, CloudLayerVolumetric1.CloudCoverSecondary.LastValue); props.SetFloat(WMS._CloudTypeVolumetric, CloudLayerVolumetric1.CloudType.LastValue); props.SetFloat(WMS._CloudTypeSecondaryVolumetric, CloudLayerVolumetric1.CloudTypeSecondary.LastValue); props.SetFloat(WMS._CloudDensityVolumetric, CloudLayerVolumetric1.CloudDensity.LastValue); props.SetFloat(WMS._CloudHeightNoisePowerVolumetric, CloudLayerVolumetric1.CloudHeightNoisePowerVolumetric.LastValue); props.SetInt(WMS._CloudDirLightRaySampleCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightRaySampleCount); props.SetFloat(WMS._CloudPlanetRadiusVolumetric, CloudPlanetRadius); props.SetFloat(WMS._CloudNoiseScalarVolumetric, CloudLayerVolumetric1.CloudNoiseScalar.LastValue * WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudNoiseMultiplier); props.SetTexture(WMS._CloudNoiseShapeVolumetric, CloudLayerVolumetric1.CloudNoiseShape); props.SetTexture(WMS._CloudNoiseDetailVolumetric, CloudLayerVolumetric1.CloudNoiseDetail); props.SetTexture(WMS._CloudNoiseCurlVolumetric, CloudLayerVolumetric1.CloudNoiseCurl); props.SetVector(WMS._CloudShapeAnimationVelocity, CloudLayerVolumetric1.CloudShapeAnimationVelocity); props.SetVector(WMS._CloudDetailAnimationVelocity, CloudLayerVolumetric1.CloudDetailAnimationVelocity); props.SetVector(WMS._CloudNoiseScaleVolumetric, CloudLayerVolumetric1.CloudNoiseScale); props.SetFloat(WMS._CloudNoiseDetailPowerVolumetric, CloudLayerVolumetric1.CloudNoiseDetailPower.LastValue); props.SetFloat(WMS._CloudShapeNoiseMinVolumetric, CloudLayerVolumetric1.CloudShapeNoiseMin.LastValue); props.SetFloat(WMS._CloudShapeNoiseMaxVolumetric, CloudLayerVolumetric1.CloudShapeNoiseMax.LastValue); props.SetFloat(WMS._CloudBottomFadeVolumetric, CloudLayerVolumetric1.CloudBottomFade.LastValue); props.SetFloat(WMS._WeatherMakerDirectionalLightScatterMultiplier, DirectionalLightScatterMultiplier); // lower cloud level sphere // assign global shader so shadow map can see them props.SetFloat(WMS._CloudStartVolumetric, CloudHeight.LastValue); props.SetFloat(WMS._CloudStartSquaredVolumetric, CloudHeight.LastValue * CloudHeight.LastValue); props.SetFloat(WMS._CloudPlanetStartVolumetric, CloudHeight.LastValue + CloudPlanetRadius); props.SetFloat(WMS._CloudPlanetStartSquaredVolumetric, Mathf.Pow(CloudHeight.LastValue + CloudPlanetRadius, 2.0f)); // height of top minus bottom cloud layer float height = CloudHeightTop.LastValue - CloudHeight.LastValue; props.SetFloat(WMS._CloudHeightVolumetric, height); props.SetFloat(WMS._CloudHeightInverseVolumetric, 1.0f / height); height *= height; props.SetFloat(WMS._CloudHeightSquaredVolumetric, height); props.SetFloat(WMS._CloudHeightSquaredInverseVolumetric, 1.0f / height); // upper cloud level sphere props.SetFloat(WMS._CloudEndVolumetric, CloudHeightTop.LastValue); height = CloudHeightTop.LastValue * CloudHeightTop.LastValue; props.SetFloat(WMS._CloudEndSquaredVolumetric, height); props.SetFloat(WMS._CloudEndSquaredInverseVolumetric, 1.0f / height); props.SetFloat(WMS._CloudPlanetEndVolumetric, CloudHeightTop.LastValue + CloudPlanetRadius); props.SetFloat(WMS._CloudPlanetEndSquaredVolumetric, Mathf.Pow(CloudHeightTop.LastValue + CloudPlanetRadius, 2.0f)); props.SetFloat(WMS._CloudPlanetRadiusNegativeVolumetric, -CloudPlanetRadius); props.SetFloat(WMS._CloudPlanetRadiusSquaredVolumetric, CloudPlanetRadius * CloudPlanetRadius); props.SetVector(WMS._CloudHenyeyGreensteinPhaseVolumetric, CloudLayerVolumetric1.CloudHenyeyGreensteinPhase); props.SetFloat(WMS._CloudRayOffsetVolumetric, CloudLayerVolumetric1.CloudRayOffset + additionalCloudRayOffset); props.SetFloat(WMS._CloudMinRayYVolumetric, CloudLayerVolumetric1.CloudMinRayY); props.SetVector(WMS._CloudGradientStratus, CloudLayerVolumetric1.CloudGradientStratusVector); props.SetVector(WMS._CloudGradientStratoCumulus, CloudLayerVolumetric1.CloudGradientStratoCumulusVector); props.SetVector(WMS._CloudGradientCumulus, CloudLayerVolumetric1.CloudGradientCumulusVector); // flat clouds float cloudCover1 = 0.0f; float cloudCover2 = 0.0f; float cloudCover3 = 0.0f; float cloudCover4 = 0.0f; if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds || (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.One) == WeatherMakerVolumetricCloudsFlatLayerMask.One) { cloudCover1 = CloudLayer1.CloudCover; } if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds || (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Two) == WeatherMakerVolumetricCloudsFlatLayerMask.Two) { cloudCover2 = CloudLayer2.CloudCover; } if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds || (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Three) == WeatherMakerVolumetricCloudsFlatLayerMask.Three) { cloudCover3 = CloudLayer3.CloudCover; } if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds || (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Four) == WeatherMakerVolumetricCloudsFlatLayerMask.Four) { cloudCover4 = CloudLayer4.CloudCover; } props.SetTexture(WMS._CloudNoise1, CloudLayer1.CloudNoise ?? Texture2D.blackTexture); props.SetTexture(WMS._CloudNoise2, CloudLayer2.CloudNoise ?? Texture2D.blackTexture); props.SetTexture(WMS._CloudNoise3, CloudLayer3.CloudNoise ?? Texture2D.blackTexture); props.SetTexture(WMS._CloudNoise4, CloudLayer4.CloudNoise ?? Texture2D.blackTexture); props.SetVectorArray(WMS._CloudNoiseScale, CloudLayer1.CloudNoiseScale * scaleReducer, CloudLayer2.CloudNoiseScale * scaleReducer, CloudLayer3.CloudNoiseScale * scaleReducer, CloudLayer4.CloudNoiseScale * scaleReducer); props.SetVectorArray(WMS._CloudNoiseMultiplier, CloudLayer1.CloudNoiseMultiplier, CloudLayer2.CloudNoiseMultiplier, CloudLayer3.CloudNoiseMultiplier, CloudLayer4.CloudNoiseMultiplier); props.SetVectorArray(WMS._CloudNoiseVelocity, cloudNoiseVelocityAccum1, cloudNoiseVelocityAccum2, cloudNoiseVelocityAccum3, cloudNoiseVelocityAccum4); props.SetFloatArrayRotation(WMS._CloudNoiseRotation, CloudLayer1.CloudNoiseRotation.LastValue, CloudLayer2.CloudNoiseRotation.LastValue, CloudLayer3.CloudNoiseRotation.LastValue, CloudLayer4.CloudNoiseRotation.LastValue); props.SetFloatArray(WMS._CloudHeight, CloudLayer1.CloudHeight, CloudLayer2.CloudHeight, CloudLayer3.CloudHeight, CloudLayer4.CloudHeight); props.SetFloatArray(WMS._CloudCover, cloudCover1, cloudCover2, cloudCover3, cloudCover4); props.SetFloatArray(WMS._CloudDensity, CloudLayer1.CloudDensity, CloudLayer2.CloudDensity, CloudLayer3.CloudDensity, CloudLayer4.CloudDensity); props.SetFloatArray(WMS._CloudSharpness, CloudLayer1.CloudSharpness, CloudLayer2.CloudSharpness, CloudLayer3.CloudSharpness, CloudLayer4.CloudSharpness); props.SetFloatArray(WMS._CloudRayOffset, CloudLayer1.CloudRayOffset, CloudLayer2.CloudRayOffset, CloudLayer3.CloudRayOffset, CloudLayer4.CloudRayOffset); props.SetVector(WMS._CloudNoiseSampleCountVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudSampleCount.ToVector2()); props.SetInt(WMS._CloudRaymarchSkipThreshold, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipThreshold); props.SetFloat(WMS._CloudRaymarchMaybeInCloudStepMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchMaybeInCloudStepMultiplier); props.SetFloat(WMS._CloudRaymarchInCloudStepMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchInCloudStepMultiplier); props.SetFloat(WMS._CloudRaymarchSkipMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipMultiplier); props.SetInt(WMS._CloudRaymarchSkipMultiplierMaxCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipMultiplierMaxCount); props.SetVector(WMS._CloudNoiseLodVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudLod.ToVector2()); props.SetColor(WMS._CloudColorVolumetric, CloudLayerVolumetric1.CloudColor); props.SetColor(WMS._CloudDirColorVolumetric, CloudLayerVolumetric1.CloudDirLightGradientColorColor); props.SetColor(WMS._CloudEmissionColorVolumetric, CloudLayerVolumetric1.CloudEmissionColor); props.SetFloat(WMS._CloudDirLightMultiplierVolumetric, CloudLayerVolumetric1.CloudDirLightMultiplier); props.SetFloat(WMS._CloudLightDitherLevel, CloudLayerVolumetric1.CloudLightDitherLevel); props.SetFloat(WMS._CloudPointSpotLightMultiplierVolumetric, CloudLayerVolumetric1.CloudPointSpotLightMultiplier); props.SetFloat(WMS._CloudAmbientGroundIntensityVolumetric, CloudLayerVolumetric1.CloudAmbientGroundIntensity); props.SetFloat(WMS._CloudAmbientSkyIntensityVolumetric, CloudLayerVolumetric1.CloudAmbientSkyIntensity); float backgroundSkyStyle = (WeatherMakerSkySphereScript.Instance == null || WeatherMakerSkySphereScript.Instance.SkySphereProfile == null || WeatherMakerSkySphereScript.Instance.SkySphereProfile.SkyMode == WeatherMakeSkyMode.ProceduralUnityStyle || WeatherMakerSkySphereScript.Instance.SkySphereProfile.SkyMode == WeatherMakeSkyMode.ProceduralTexturedUnityStyle ? 0.0f : 1.0f); props.SetVector(WMS._CloudBackgroundSkyIntensityVolumetric, new Vector4(CloudLayerVolumetric1.CloudSkyIntensity, backgroundSkyStyle, 0.0f, 0.0f)); props.SetFloat(WMS._CloudAmbientSkyHeightMultiplierVolumetric, CloudLayerVolumetric1.CloudAmbientSkyHeightMultiplier); props.SetFloat(WMS._CloudAmbientGroundHeightMultiplierVolumetric, CloudLayerVolumetric1.CloudAmbientGroundHeightMultiplier); props.SetFloat(WMS._CloudLightAbsorptionVolumetric, CloudLayerVolumetric1.CloudLightAbsorption); props.SetFloat(WMS._CloudDirLightIndirectMultiplierVolumetric, CloudLayerVolumetric1.CloudDirLightIndirectMultiplier); props.SetFloat(WMS._CloudPowderMultiplierVolumetric, CloudLayerVolumetric1.CloudPowderMultiplier.LastValue); props.SetFloat(WMS._CloudOpticalDistanceMultiplierVolumetric, CloudLayerVolumetric1.CloudOpticalDistanceMultiplier); props.SetFloat(WMS._CloudHorizonFadeMultiplierVolumetric, CloudLayerVolumetric1.CloudHorizonFadeMultiplier); props.SetFloat(WMS._CloudDirLightSampleCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightSampleCount); props.SetFloat(WMS._CloudLightStepMultiplierVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightStepMultiplier); props.SetFloat(WMS._CloudMaxRayLengthMultiplierVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudMaxRayLengthMultiplier); props.SetFloat(WMS._CloudRayDitherVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRayDither); props.SetFloat(WMS._CloudRaymarchMultiplierVolumetric, Mathf.Max(CloudLayerVolumetric1.CloudMinRayMarchMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchMultiplier)); props.SetVector(WMS._CloudRayMarchParameters, CloudLayerVolumetric1.CloudRayMarchParamers); // sample details for dir light ray march if max lod is small props.SetFloat(WMS._CloudDirLightLod, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightLod); props.SetInt(WMS._CloudRaymarchSampleDetailsForDirLight, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightSampleDetails ? 1 : 0); // flat props.SetColorArray(WMS._CloudColor, CloudLayer1.CloudColor * sun.GetGradientColor(CloudLayer1.CloudGradientColor), CloudLayer2.CloudColor * sun.GetGradientColor(CloudLayer2.CloudGradientColor), CloudLayer3.CloudColor * sun.GetGradientColor(CloudLayer3.CloudGradientColor), CloudLayer4.CloudColor * sun.GetGradientColor(CloudLayer4.CloudGradientColor)); props.SetColorArray(WMS._CloudEmissionColor, CloudLayer1.CloudEmissionColor, CloudLayer2.CloudEmissionColor, CloudLayer3.CloudEmissionColor, CloudLayer4.CloudEmissionColor); props.SetFloatArray(WMS._CloudAmbientMultiplier, CloudLayer1.CloudAmbientMultiplier, CloudLayer2.CloudAmbientMultiplier, CloudLayer3.CloudAmbientMultiplier, CloudLayer4.CloudAmbientMultiplier); props.SetFloatArray(WMS._CloudScatterMultiplier, CloudLayer1.CloudScatterMultiplier, CloudLayer2.CloudScatterMultiplier, CloudLayer3.CloudScatterMultiplier, CloudLayer4.CloudScatterMultiplier); /* * if (CloudLayer1.CloudNoiseMask != null || CloudLayer2.CloudNoiseMask != null || CloudLayer3.CloudNoiseMask != null || CloudLayer4.CloudNoiseMask != null) * { * cloudMaterial.SetTexture(WMS._CloudNoiseMask1, CloudLayer1.CloudNoiseMask ?? Texture2D.whiteTexture); * cloudMaterial.SetTexture(WMS._CloudNoiseMask2, CloudLayer2.CloudNoiseMask ?? Texture2D.whiteTexture); * cloudMaterial.SetTexture(WMS._CloudNoiseMask3, CloudLayer3.CloudNoiseMask ?? Texture2D.whiteTexture); * cloudMaterial.SetTexture(WMS._CloudNoiseMask4, CloudLayer4.CloudNoiseMask ?? Texture2D.whiteTexture); * WeatherMakerShaderIds.SetVectorArray(cloudMaterial, "_CloudNoiseMaskOffset", * CloudLayer1.CloudNoiseMaskOffset, * CloudLayer2.CloudNoiseMaskOffset, * CloudLayer3.CloudNoiseMaskOffset, * CloudLayer4.CloudNoiseMaskOffset); * WeatherMakerShaderIds.SetVectorArray(cloudMaterial, "_CloudNoiseMaskVelocity", cloudNoiseMaskVelocityAccum1, cloudNoiseMaskVelocityAccum2, cloudNoiseMaskVelocityAccum3, cloudNoiseMaskVelocityAccum4); * WeatherMakerShaderIds.SetFloatArray(cloudMaterial, "_CloudNoiseMaskScale", * (CloudLayer1.CloudNoiseMask == null ? 0.0f : CloudLayer1.CloudNoiseMaskScale * scaleReducer), * (CloudLayer2.CloudNoiseMask == null ? 0.0f : CloudLayer2.CloudNoiseMaskScale * scaleReducer), * (CloudLayer3.CloudNoiseMask == null ? 0.0f : CloudLayer3.CloudNoiseMaskScale * scaleReducer), * (CloudLayer4.CloudNoiseMask == null ? 0.0f : CloudLayer4.CloudNoiseMaskScale * scaleReducer)); * WeatherMakerShaderIds.SetFloatArrayRotation(cloudMaterial, "_CloudNoiseMaskRotation", * CloudLayer1.CloudNoiseMaskRotation.LastValue, * CloudLayer2.CloudNoiseMaskRotation.LastValue, * CloudLayer3.CloudNoiseMaskRotation.LastValue, * CloudLayer4.CloudNoiseMaskRotation.LastValue); * } */ props.SetFloatArray(WMS._CloudLightAbsorption, CloudLayer1.CloudLightAbsorption, CloudLayer2.CloudLightAbsorption, CloudLayer3.CloudLightAbsorption, CloudLayer4.CloudLightAbsorption); }
private void UpdateUnityFog(Camera camera) { if (!UseUnityFog) { return; } WeatherMakerCelestialObjectScript sun = WeatherMakerLightManagerScript.SunForCamera(camera); if (sun == null) { return; } RenderSettings.fog = (FogProfile.fogDensity > 0.0001f && FogProfile.FogMode != WeatherMakerFogMode.None); Color fogColor = (FogProfile.FogColor * (sun == null || !sun.LightIsOn ? Color.black : sun.GetGradientColor(FogProfile.FogGradientColor))); if (WeatherMakerLightManagerScript.Instance != null) { bool cameraIsPerspective = (camera == null || !camera.orthographic); foreach (WeatherMakerLightManagerScript.LightState light in WeatherMakerLightManagerScript.Instance.Lights) { if (light.Light.type == LightType.Directional && light.Light != sun.Light) { WeatherMakerCelestialObjectScript obj = light.Light.GetComponent <WeatherMakerCelestialObjectScript>(); if (obj != null && obj.OrbitTypeIsPerspective == cameraIsPerspective) { fogColor += (FogProfile.FogColor * (light.Light.color * light.Light.intensity)); } break; } } } RenderSettings.fogColor = fogColor; RenderSettings.fogDensity = FogProfile.fogDensity; switch (FogProfile.FogMode) { case WeatherMakerFogMode.Constant: case WeatherMakerFogMode.Linear: RenderSettings.fogMode = FogMode.Linear; break; case WeatherMakerFogMode.None: RenderSettings.fogDensity = 0.0f; break; case WeatherMakerFogMode.Exponential: RenderSettings.fogMode = FogMode.Exponential; break; case WeatherMakerFogMode.ExponentialSquared: RenderSettings.fogMode = FogMode.ExponentialSquared; break; } }
private void Update() { if (Profile == null) { return; } nextChange -= Time.deltaTime; if (nextChange <= 0.0f) { if (Profile.RefreshInterval.Minimum > 0.0f && Profile.RefreshInterval.Maximum > 0.0f) { nextChange = Profile.RefreshInterval.Random(); } else { nextChange = float.MaxValue; } var em = meteorParticles.emission; float value1 = Profile.EmissionRange.Random(); float value2 = Profile.EmissionRange.Random(); em.rateOverTime = new ParticleSystem.MinMaxCurve(Mathf.Min(value1, value2), Mathf.Max(value1, value2)); var mn = meteorParticles.main; float l1 = Profile.LifetimeRangeMin.Random(); float l2 = Profile.LifetimeRangeMax.Random(); var lifeTime = mn.startLifetime; lifeTime.constantMin = Mathf.Min(l1, l2); lifeTime.constantMax = Mathf.Max(l1, l2); mn.startLifetime = lifeTime; l1 = Profile.SpeedRangeMin.Random(); l2 = Profile.SpeedRangeMax.Random(); speed = new Vector2(Mathf.Min(l1, l2), Mathf.Max(l1, l2)); // pick a random offset in the sky offset = new Vector3(UnityEngine.Random.Range(Profile.OffsetMin.x, Profile.OffsetMax.x), UnityEngine.Random.Range(Profile.OffsetMin.y, Profile.OffsetMax.y), UnityEngine.Random.Range(Profile.OffsetMin.z, Profile.OffsetMax.z)); radius = Profile.RadiusRange.Random(); arc = Profile.ArcRange.Random(); } // update color based on sun position if (WeatherMakerLightManagerScript.Instance != null) { WeatherMakerCelestialObjectScript sun = (WeatherMakerLightManagerScript.Instance.SunPerspective ?? WeatherMakerLightManagerScript.Instance.SunOrthographic); if (sun != null) { float a = sun.GetGradientColor(Profile.Visibility).r; var m = meteorParticles.main; var colorRange = m.startColor; Color minColor = colorRange.colorMin; Color maxcolor = colorRange.colorMax; minColor.a = maxcolor.a = a; colorRange.colorMin = minColor; colorRange.colorMax = maxcolor; m.startColor = colorRange; } } }