Files
2026-03-04 10:03:45 +08:00

1048 lines
35 KiB
C#

using System;
using UnityEngine;
namespace Artngame.SKYMASTER
{
[ExecuteInEditMode]
[RequireComponent(typeof(Camera), typeof(CloudTemporalAntiAliasing))]
public class CloudScriptTRANSP : SceneViewFilter
{
public enum RandomJitter
{
Off = 0,
Random = 1,
BlueNoise = 2
}
public CloudScript cloudsBelow;
public bool changeOnHeight = true;
public float changeAboveTranspHeight = 200f;
public Vector4 specialFX = new Vector4(0f, 0f, 1f, 0f);
public bool enableEdgeControl;
public int debugClouds;
public Vector4 edgeControl = new Vector4(1f, 1f, 1f, 1f);
public bool autoRegulateEdgeMode = true;
public float autoRegulateCutoffDistance = 1000f;
public float controlBackAlphaPower = 1f;
public float controlCloudAlphaPower = 0.001f;
private float controlBackAlphaPowerP = 1f;
private float controlCloudAlphaPowerP = 0.001f;
public Vector4 controlCloudEdgeA = new Vector4(1f, 1f, 1f, 1f);
public Vector4 controlCloudEdgeAP = new Vector4(1f, 1f, 1f, 1f);
public float depthDilation;
private float depthDilationP;
public bool useCustomTexture;
public Texture2D weatherTexture;
public Vector3 _CameraWSOffset = new Vector3(0f, 0f, 0f);
public float cameraScale = 1f;
public float extendFarPlaneAboveClouds = 1f;
public Vector4 YCutHeightDepthScale = new Vector4(0f, 1f, 0f, 1f);
public float multiplyStepsAboveClouds = 1f;
public Vector3 cloudDistanceParams = new Vector3(0f, 0f, 1f);
public int scatterOn = 1;
public int sunRaysOn;
public float sunRaysPower = 1f;
public float zeroCountSteps;
public int sunShaftSteps = 5;
public Vector4 raysResolution = new Vector4(1f, 1f, 1f, 1f);
public Vector4 rayShadowing = new Vector4(1f, 1f, 1f, 1f);
public bool enableShadowCastOnClouds;
public float shadowPower = 1f;
public Vector4 superCellControls = new Vector4(0f, 0f, 0f, 0f);
public int renderInFront;
public Texture2D _InteractTexture;
public Vector4 _InteractTexturePos = new Vector4(1f, 1f, 0f, 0f);
public Vector4 _InteractTextureAtr = new Vector4(1f, 1f, 0f, 0f);
public Vector4 _InteractTextureOffset = new Vector4(0f, 0f, 0f, 0f);
[Tooltip("Distance fog is based on radial distance from camera when checked")]
public bool useRadialDistance;
[Tooltip("Fog top Y coordinate")]
public float height = 1f;
[Range(1E-05f, 10f)]
public float heightDensity = 2f;
[Tooltip("Push fog away from the camera by this amount")]
public float startDistance;
public Light localLight;
public float localLightFalloff = 2f;
public float localLightIntensity = 1f;
public float currentLocalLightIntensity;
public float _Scatter = 0.008f;
public float _HGCoeff = 0.5f;
public float _Extinct = 0.01f;
public Vector3 _SkyTint = new Vector3(0.5f, 0.5f, 0.5f);
public float _BackShade = 1f;
public float luminance = 0.8f;
public float lumFac = 0.9f;
public float ScatterFac = 24.4f;
public float TurbFac = 324.74f;
public float HorizFac = 1f;
public float turbidity = 10f;
public float reileigh = 0.8f;
public float mieCoefficient = 0.1f;
public float mieDirectionalG = 0.7f;
public float bias = 0.6f;
public float contrast = 4.12f;
public bool FogSky;
public Vector3 TintColor = new Vector3(68f, 155f, 345f);
public float ClearSkyFac = 1f;
[Header("Vortex")]
public bool enableVORTEX;
public Vector3 vortexPosition = new Vector3(0f, 0f, 0f);
public float vortexRadius = 1000f;
public Vector4 vortexControls = new Vector4(1f, 1f, 1f, 1f);
[Header("Debugging")]
public bool debugNoLowFreqNoise;
public bool debugNoHighFreqNoise;
public bool debugNoCurlNoise;
[Header("Performance")]
[Range(1f, 1024f)]
public int steps = 256;
public bool adjustDensity = true;
public AnimationCurve stepDensityAdjustmentCurve = new AnimationCurve(new Keyframe(0f, 3.019f), new Keyframe(0.25f, 1.233f), new Keyframe(0.5f, 1f), new Keyframe(1f, 0.892f));
public bool allowFlyingInClouds;
[Range(1f, 8f)]
public int downSample = 2;
public Texture2D blueNoiseTexture;
public RandomJitter randomJitterNoise = RandomJitter.BlueNoise;
public bool temporalAntiAliasing = true;
[Header("Cloud modeling")]
public Gradient gradientLow;
public Gradient gradientMed;
public Gradient gradientHigh;
public Texture2D curlNoise;
public TextAsset lowFreqNoise;
public TextAsset highFreqNoise;
public float startHeight = 1500f;
public float thickness = 4000f;
public float planetSize = 35000f;
public Vector3 planetZeroCoordinate = new Vector3(0f, 0f, 0f);
[Range(0f, 1f)]
public float scale = 0.3f;
[Range(0f, 32f)]
public float detailScale = 13.9f;
[Range(0f, 1f)]
public float lowFreqMin = 0.366f;
[Range(0f, 1f)]
public float lowFreqMax = 0.8f;
[Range(0f, 1f)]
public float highFreqModifier = 0.21f;
[Range(0f, 10f)]
public float curlDistortScale = 7.44f;
[Range(0f, 1000f)]
public float curlDistortAmount = 407f;
[Range(0f, 1f)]
public float weatherScale = 0.1f;
[Range(0f, 2f)]
public float coverage = 1.06f;
[Range(0f, 2f)]
public float cloudSampleMultiplier = 1f;
[Header("High altitude clouds")]
public Texture2D cloudsHighTexture;
[Range(0f, 2f)]
public float coverageHigh = 2f;
[Range(0f, 2f)]
public float highCoverageScale = 1f;
[Range(0f, 1f)]
public float highCloudsScale = 0.02f;
[Header("Cloud Lighting")]
public Light sunLight;
public Color cloudBaseColor = new Color32(199, 220, byte.MaxValue, 0);
public Color cloudTopColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
[Range(0f, 1f)]
public float ambientLightFactor = 0.551f;
[Range(0f, 5f)]
public float sunLightFactor = 3.79f;
public Color highSunColor = new Color32(byte.MaxValue, 252, 210, byte.MaxValue);
public Color lowSunColor = new Color32(byte.MaxValue, 174, 0, byte.MaxValue);
[Range(0f, 1f)]
public float henyeyGreensteinGForward = 0.4f;
[Range(0f, 1f)]
public float henyeyGreensteinGBackward = 0.179f;
[Range(0f, 200f)]
public float lightStepLength = 64f;
[Range(0f, 1f)]
public float lightConeRadius = 0.4f;
public bool randomUnitSphere = true;
[Range(0f, 4f)]
public float density = 1f;
public bool aLotMoreLightSamples;
[Header("Animating")]
public float globalMultiplier = 1f;
public float windSpeed = 15.9f;
public float windDirection = -22.4f;
public float coverageWindSpeed = 25f;
public float coverageWindDirection = 5f;
public float highCloudsWindSpeed = 49.2f;
public float highCloudsWindDirection = 77.8f;
private Vector3 _windOffset;
private Vector2 _coverageWindOffset;
private Vector2 _highCloudsWindOffset;
private Vector3 _windDirectionVector;
private float _multipliedWindSpeed;
private Texture3D _cloudShapeTexture;
private Texture3D _cloudDetailTexture;
private CloudTemporalAntiAliasing _temporalAntiAliasing;
private Material _CloudMaterial;
private Material _UpscaleMaterial;
public Camera _CurrentCamera;
private Matrix4x4 left_world_from_view;
private Matrix4x4 right_world_from_view;
private Matrix4x4 left_screen_from_view;
private Matrix4x4 right_screen_from_view;
private Matrix4x4 left_view_from_screen;
private Matrix4x4 right_view_from_screen;
private GradientColorKey[] colorKey;
private GradientAlphaKey[] alphaKey;
public Material CloudMaterial
{
get
{
if (!_CloudMaterial)
{
_CloudMaterial = new Material(Shader.Find("Hidden/Clouds"));
_CloudMaterial.hideFlags = HideFlags.HideAndDontSave;
}
return _CloudMaterial;
}
}
public Material UpscaleMaterial
{
get
{
if (!_UpscaleMaterial)
{
_UpscaleMaterial = new Material(Shader.Find("Hidden/CloudBlender"));
_UpscaleMaterial.hideFlags = HideFlags.HideAndDontSave;
}
return _UpscaleMaterial;
}
}
public Camera CurrentCamera
{
get
{
if (!_CurrentCamera)
{
_CurrentCamera = GetComponent<Camera>();
}
return _CurrentCamera;
}
}
private void Reset()
{
_temporalAntiAliasing = GetComponent<CloudTemporalAntiAliasing>();
_temporalAntiAliasing.SetCamera(CurrentCamera);
}
private void Awake()
{
Reset();
if (useCustomTexture)
{
CloudMaterial.SetTexture("_WeatherTexture", weatherTexture);
}
}
private void Start()
{
controlBackAlphaPowerP = controlBackAlphaPower;
controlCloudAlphaPowerP = controlCloudAlphaPower;
depthDilationP = depthDilation;
controlCloudEdgeAP = controlCloudEdgeA;
if ((bool)_CloudMaterial)
{
UnityEngine.Object.DestroyImmediate(_CloudMaterial);
}
if ((bool)_UpscaleMaterial)
{
UnityEngine.Object.DestroyImmediate(_UpscaleMaterial);
}
_windOffset = new Vector3(0f, 0f, 0f);
_coverageWindOffset = new Vector3(0.5f / (weatherScale * 0.00025f), 0.5f / (weatherScale * 0.00025f));
_highCloudsWindOffset = new Vector3(1500f, -900f);
if (useCustomTexture)
{
CloudMaterial.SetTexture("_WeatherTexture", weatherTexture);
}
}
private void Update()
{
if (gradientLow == null)
{
createGradient(ref gradientLow);
}
if (gradientMed == null)
{
createGradient(ref gradientMed);
}
if (gradientHigh == null)
{
createGradient(ref gradientHigh);
}
if (sunLight == null && !Application.isPlaying)
{
controlWeatherTOD_SM_SRP component = base.transform.gameObject.GetComponent<controlWeatherTOD_SM_SRP>();
if (component != null && component.temporalSunMoon != null)
{
Light component2 = component.temporalSunMoon.GetComponent<Light>();
if (component2 != null)
{
sunLight = component2;
}
}
if (sunLight == null)
{
Light[] array = UnityEngine.Object.FindObjectsOfType(typeof(Light)) as Light[];
Light[] array2 = array;
foreach (Light light in array2)
{
if (light.type == LightType.Directional && light.gameObject.name.Contains("Sun") && light.enabled && light.gameObject.activeInHierarchy)
{
sunLight = light;
break;
}
}
if (sunLight == null)
{
array2 = array;
foreach (Light light2 in array2)
{
if (light2.type == LightType.Directional && light2.gameObject.activeInHierarchy)
{
sunLight = light2;
break;
}
}
if (sunLight == null)
{
Light light3 = new GameObject
{
name = "Sky Master Sun"
}.AddComponent<Light>();
sunLight = light3;
}
}
}
}
if (autoRegulateEdgeMode && Application.isPlaying)
{
if (Camera.main.transform.position.y > autoRegulateCutoffDistance)
{
controlBackAlphaPower = 1f;
controlCloudAlphaPower = 0.001f;
depthDilation = 0f;
controlCloudEdgeA = Vector4.Lerp(controlCloudEdgeA, new Vector4(1f, 1f, 1f, 1f), Time.deltaTime * 0.4f);
}
else
{
controlBackAlphaPower = controlBackAlphaPowerP;
controlCloudAlphaPower = controlCloudAlphaPowerP;
depthDilation = depthDilationP;
controlCloudEdgeA = Vector4.Lerp(controlCloudEdgeA, controlCloudEdgeAP, Time.deltaTime * 0.4f);
}
}
_multipliedWindSpeed = windSpeed * globalMultiplier;
float f = windDirection * (MathF.PI / 180f);
_windDirectionVector = new Vector3(Mathf.Cos(f), -0.25f, Mathf.Sin(f));
_windOffset += _multipliedWindSpeed * _windDirectionVector * Time.deltaTime;
float f2 = coverageWindDirection * (MathF.PI / 180f);
Vector2 vector = new Vector2(Mathf.Cos(f2), Mathf.Sin(f2));
_coverageWindOffset += coverageWindSpeed * globalMultiplier * vector * Time.deltaTime;
float f3 = highCloudsWindDirection * (MathF.PI / 180f);
Vector2 vector2 = new Vector2(Mathf.Cos(f3), Mathf.Sin(f3));
_highCloudsWindOffset += highCloudsWindSpeed * globalMultiplier * vector2 * Time.deltaTime;
}
private void OnDestroy()
{
if ((bool)_CloudMaterial)
{
UnityEngine.Object.DestroyImmediate(_CloudMaterial);
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.green;
Matrix4x4 frustumCorners = GetFrustumCorners(CurrentCamera);
Vector3 position = CurrentCamera.transform.position;
for (int i = 0; i < 4; i++)
{
frustumCorners.SetRow(i, CurrentCamera.cameraToWorldMatrix * frustumCorners.GetRow(i));
Gizmos.DrawLine(position, position + (Vector3)frustumCorners.GetRow(i));
}
Gizmos.color = Color.red;
int num = 10;
for (int j = 1; j < num; j++)
{
float t = (float)j / (float)num;
Vector3 a = Vector3.Lerp(frustumCorners.GetRow(0), frustumCorners.GetRow(1), t);
Vector3 b = Vector3.Lerp(frustumCorners.GetRow(3), frustumCorners.GetRow(2), t);
for (int k = 1; k < num; k++)
{
float t2 = (float)k / (float)num;
Vector3 normalized = Vector3.Lerp(a, b, t2).normalized;
Gizmos.DrawLine(position + normalized, position + normalized * 1.2f);
}
}
}
private Vector4 gradientToVector4(Gradient gradient)
{
if (gradient.colorKeys.Length != 4)
{
return new Vector4(0f, 0f, 0f, 0f);
}
float time = gradient.colorKeys[0].time;
float time2 = gradient.colorKeys[1].time;
float time3 = gradient.colorKeys[2].time;
float time4 = gradient.colorKeys[3].time;
return new Vector4(time, time2, time3, time4);
}
public void OnRenderImage(RenderTexture source, RenderTexture destination)
{
changeOnHeight = cloudsBelow.changeOnHeight;
changeAboveTranspHeight = cloudsBelow.changeAboveTranspHeight;
specialFX = cloudsBelow.specialFX;
enableEdgeControl = cloudsBelow.enableEdgeControl;
debugClouds = cloudsBelow.debugClouds;
edgeControl = cloudsBelow.edgeControl;
autoRegulateEdgeMode = cloudsBelow.autoRegulateEdgeMode;
autoRegulateCutoffDistance = cloudsBelow.autoRegulateCutoffDistance;
controlBackAlphaPower = cloudsBelow.controlBackAlphaPower;
controlCloudAlphaPower = cloudsBelow.controlCloudAlphaPower;
controlCloudEdgeA = cloudsBelow.controlCloudEdgeA;
controlCloudEdgeAP = cloudsBelow.controlCloudEdgeAP;
depthDilation = cloudsBelow.depthDilation;
useCustomTexture = cloudsBelow.useCustomTexture;
weatherTexture = cloudsBelow.weatherTexture;
_CameraWSOffset = cloudsBelow._CameraWSOffset;
scatterOn = cloudsBelow.scatterOn;
sunRaysOn = cloudsBelow.sunRaysOn;
extendFarPlaneAboveClouds = cloudsBelow.extendFarPlaneAboveClouds;
cameraScale = cloudsBelow.cameraScale;
YCutHeightDepthScale = cloudsBelow.YCutHeightDepthScale;
multiplyStepsAboveClouds = cloudsBelow.multiplyStepsAboveClouds;
cloudDistanceParams = cloudsBelow.cloudDistanceParams;
sunRaysPower = cloudsBelow.sunRaysPower;
raysResolution = cloudsBelow.raysResolution;
rayShadowing = cloudsBelow.rayShadowing;
enableShadowCastOnClouds = cloudsBelow.enableShadowCastOnClouds;
shadowPower = cloudsBelow.shadowPower;
superCellControls = cloudsBelow.superCellControls;
zeroCountSteps = cloudsBelow.zeroCountSteps;
sunShaftSteps = cloudsBelow.sunShaftSteps;
renderInFront = cloudsBelow.renderInFront;
_InteractTexture = cloudsBelow._InteractTexture;
_InteractTexturePos = cloudsBelow._InteractTexturePos;
_InteractTextureAtr = cloudsBelow._InteractTextureAtr;
_InteractTextureOffset = cloudsBelow._InteractTextureOffset;
useRadialDistance = cloudsBelow.useRadialDistance;
height = cloudsBelow.height;
heightDensity = cloudsBelow.heightDensity;
startDistance = cloudsBelow.startDistance;
localLight = cloudsBelow.localLight;
localLightFalloff = cloudsBelow.localLightFalloff;
localLightIntensity = cloudsBelow.localLightIntensity;
currentLocalLightIntensity = cloudsBelow.currentLocalLightIntensity;
_Scatter = cloudsBelow._Scatter;
_HGCoeff = cloudsBelow._HGCoeff;
_Extinct = cloudsBelow._Extinct;
_SkyTint = cloudsBelow._SkyTint;
_BackShade = cloudsBelow._BackShade;
luminance = cloudsBelow.luminance;
lumFac = cloudsBelow.lumFac;
ScatterFac = cloudsBelow.ScatterFac;
TurbFac = cloudsBelow.TurbFac;
HorizFac = cloudsBelow.HorizFac;
turbidity = cloudsBelow.turbidity;
reileigh = cloudsBelow.reileigh;
mieCoefficient = cloudsBelow.mieCoefficient;
mieDirectionalG = cloudsBelow.mieDirectionalG;
bias = cloudsBelow.bias;
contrast = cloudsBelow.contrast;
FogSky = cloudsBelow.FogSky;
TintColor = cloudsBelow.TintColor;
ClearSkyFac = cloudsBelow.ClearSkyFac;
enableVORTEX = cloudsBelow.enableVORTEX;
vortexPosition = cloudsBelow.vortexPosition;
vortexRadius = cloudsBelow.vortexRadius;
vortexControls = cloudsBelow.vortexControls;
debugNoLowFreqNoise = cloudsBelow.debugNoLowFreqNoise;
debugNoHighFreqNoise = cloudsBelow.debugNoHighFreqNoise;
debugNoCurlNoise = cloudsBelow.debugNoCurlNoise;
steps = cloudsBelow.steps;
adjustDensity = cloudsBelow.adjustDensity;
stepDensityAdjustmentCurve = cloudsBelow.stepDensityAdjustmentCurve;
allowFlyingInClouds = cloudsBelow.allowFlyingInClouds;
downSample = cloudsBelow.downSample;
blueNoiseTexture = cloudsBelow.blueNoiseTexture;
temporalAntiAliasing = cloudsBelow.temporalAntiAliasing;
gradientLow = cloudsBelow.gradientLow;
gradientMed = cloudsBelow.gradientMed;
gradientHigh = cloudsBelow.gradientHigh;
curlNoise = cloudsBelow.curlNoise;
lowFreqNoise = cloudsBelow.lowFreqNoise;
highFreqNoise = cloudsBelow.highFreqNoise;
startHeight = cloudsBelow.startHeight;
thickness = cloudsBelow.thickness;
planetSize = cloudsBelow.planetSize;
planetZeroCoordinate = cloudsBelow.planetZeroCoordinate;
scale = cloudsBelow.scale;
detailScale = cloudsBelow.detailScale;
lowFreqMin = cloudsBelow.lowFreqMin;
lowFreqMax = cloudsBelow.lowFreqMax;
highFreqModifier = cloudsBelow.highFreqModifier;
curlDistortScale = cloudsBelow.curlDistortScale;
curlDistortAmount = cloudsBelow.curlDistortAmount;
weatherScale = cloudsBelow.weatherScale;
coverage = cloudsBelow.coverage;
cloudSampleMultiplier = cloudsBelow.cloudSampleMultiplier;
cloudsHighTexture = cloudsBelow.cloudsHighTexture;
coverageHigh = cloudsBelow.coverageHigh;
highCoverageScale = cloudsBelow.highCoverageScale;
highCloudsScale = cloudsBelow.highCloudsScale;
sunLight = cloudsBelow.sunLight;
cloudBaseColor = cloudsBelow.cloudBaseColor;
cloudTopColor = cloudsBelow.cloudTopColor;
ambientLightFactor = cloudsBelow.ambientLightFactor;
sunLightFactor = cloudsBelow.sunLightFactor;
highSunColor = cloudsBelow.highSunColor;
lowSunColor = cloudsBelow.lowSunColor;
henyeyGreensteinGForward = cloudsBelow.henyeyGreensteinGForward;
henyeyGreensteinGBackward = cloudsBelow.henyeyGreensteinGBackward;
lightStepLength = cloudsBelow.lightStepLength;
lightConeRadius = cloudsBelow.lightConeRadius;
randomUnitSphere = cloudsBelow.randomUnitSphere;
density = cloudsBelow.density;
aLotMoreLightSamples = cloudsBelow.aLotMoreLightSamples;
globalMultiplier = cloudsBelow.globalMultiplier;
windSpeed = cloudsBelow.windSpeed;
windDirection = cloudsBelow.windDirection;
coverageWindSpeed = cloudsBelow.coverageWindSpeed;
coverageWindDirection = cloudsBelow.coverageWindDirection;
highCloudsWindSpeed = cloudsBelow.highCloudsWindSpeed;
highCloudsWindDirection = cloudsBelow.highCloudsWindDirection;
CloudMaterial.SetTexture("_WeatherTexture", cloudsBelow.CloudMaterial.GetTexture("_WeatherTexture"));
if (changeOnHeight && Camera.main != null && Camera.main.transform.position.y <= changeAboveTranspHeight)
{
Graphics.Blit(source, destination);
return;
}
if (CloudMaterial == null || curlNoise == null || blueNoiseTexture == null || lowFreqNoise == null || highFreqNoise == null)
{
Graphics.Blit(source, destination);
return;
}
if (_cloudShapeTexture == null)
{
_cloudShapeTexture = TGALoader.load3DFromTGASlices(lowFreqNoise);
}
if (_cloudDetailTexture == null)
{
_cloudDetailTexture = TGALoader.load3DFromTGASlices(highFreqNoise);
}
Vector3 position = CurrentCamera.transform.position;
float num = sunLightFactor;
float num2 = ambientLightFactor;
float x = sunLight.transform.eulerAngles.x;
Color value = highSunColor;
float num3 = henyeyGreensteinGBackward;
float num4 = 1E-05f + scale * 0.0004f;
if (x > 170f)
{
float num5 = Mathf.Max(0f, (x - 330f) / 30f);
float num6 = num5 * num5;
num *= num5;
num2 *= num5;
num3 *= num6 * num5;
num2 = Mathf.Max(0.02f, num2);
value = Color.Lerp(lowSunColor, highSunColor, num6);
}
updateMaterialKeyword(enableVORTEX, "DEBUG_NO_LOW_FREQ_NOISE");
CloudMaterial.SetVector("vortexPosRadius", new Vector4(vortexPosition.x, vortexPosition.y, vortexPosition.z, vortexRadius));
CloudMaterial.SetVector("vortexControlsA", vortexControls);
updateMaterialKeyword(debugNoHighFreqNoise, "DEBUG_NO_HIGH_FREQ_NOISE");
updateMaterialKeyword(allowFlyingInClouds, "ALLOW_IN_CLOUDS");
updateMaterialKeyword(randomUnitSphere, "RANDOM_UNIT_SPHERE");
updateMaterialKeyword(aLotMoreLightSamples, "SLOW_LIGHTING");
switch (randomJitterNoise)
{
case RandomJitter.Off:
updateMaterialKeyword(b: false, "RANDOM_JITTER_WHITE");
updateMaterialKeyword(b: false, "RANDOM_JITTER_BLUE");
break;
case RandomJitter.Random:
updateMaterialKeyword(b: true, "RANDOM_JITTER_WHITE");
updateMaterialKeyword(b: false, "RANDOM_JITTER_BLUE");
break;
case RandomJitter.BlueNoise:
updateMaterialKeyword(b: false, "RANDOM_JITTER_WHITE");
updateMaterialKeyword(b: true, "RANDOM_JITTER_BLUE");
break;
}
CloudMaterial.SetVector("_SunDir", sunLight.transform ? (-sunLight.transform.forward).normalized : Vector3.up);
CloudMaterial.SetVector("_PlanetCenter", planetZeroCoordinate - new Vector3(0f, planetSize, 0f));
CloudMaterial.SetVector("_ZeroPoint", planetZeroCoordinate);
CloudMaterial.SetColor("_SunColor", value);
CloudMaterial.SetColor("_CloudBaseColor", cloudBaseColor);
CloudMaterial.SetColor("_CloudTopColor", cloudTopColor);
CloudMaterial.SetFloat("_AmbientLightFactor", num2);
CloudMaterial.SetFloat("_SunLightFactor", num);
CloudMaterial.SetTexture("_ShapeTexture", _cloudShapeTexture);
CloudMaterial.SetTexture("_DetailTexture", _cloudDetailTexture);
CloudMaterial.SetTexture("_CurlNoise", curlNoise);
CloudMaterial.SetTexture("_BlueNoise", blueNoiseTexture);
CloudMaterial.SetVector("_Randomness", new Vector4(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value));
CloudMaterial.SetTexture("_AltoClouds", cloudsHighTexture);
CloudMaterial.SetFloat("_CoverageHigh", 1f - coverageHigh);
CloudMaterial.SetFloat("_CoverageHighScale", highCoverageScale * weatherScale * 0.001f);
CloudMaterial.SetFloat("_HighCloudsScale", highCloudsScale * 0.002f);
CloudMaterial.SetFloat("_CurlDistortAmount", 150f + curlDistortAmount);
CloudMaterial.SetFloat("_CurlDistortScale", curlDistortScale * num4);
CloudMaterial.SetFloat("_LightConeRadius", lightConeRadius);
CloudMaterial.SetFloat("_LightStepLength", lightStepLength);
CloudMaterial.SetFloat("_SphereSize", planetSize);
CloudMaterial.SetVector("_CloudHeightMinMax", new Vector2(startHeight, startHeight + thickness));
CloudMaterial.SetFloat("_Thickness", thickness);
CloudMaterial.SetFloat("_Scale", num4);
CloudMaterial.SetFloat("_DetailScale", detailScale * num4);
CloudMaterial.SetVector("_LowFreqMinMax", new Vector4(lowFreqMin, lowFreqMax));
CloudMaterial.SetFloat("_HighFreqModifier", highFreqModifier);
CloudMaterial.SetFloat("_WeatherScale", weatherScale * 0.00025f);
CloudMaterial.SetFloat("_Coverage", 1f - coverage);
CloudMaterial.SetFloat("_HenyeyGreensteinGForward", henyeyGreensteinGForward);
CloudMaterial.SetFloat("_HenyeyGreensteinGBackward", 0f - num3);
if (adjustDensity)
{
CloudMaterial.SetFloat("_SampleMultiplier", cloudSampleMultiplier * stepDensityAdjustmentCurve.Evaluate((float)steps / 256f));
}
else
{
CloudMaterial.SetFloat("_SampleMultiplier", cloudSampleMultiplier);
}
CloudMaterial.SetFloat("_Density", density);
CloudMaterial.SetFloat("_WindSpeed", _multipliedWindSpeed);
CloudMaterial.SetVector("_WindDirection", _windDirectionVector);
CloudMaterial.SetVector("_WindOffset", _windOffset);
CloudMaterial.SetVector("_CoverageWindOffset", _coverageWindOffset);
CloudMaterial.SetVector("_HighCloudsWindOffset", _highCloudsWindOffset);
if (gradientLow == null)
{
createGradient(ref gradientLow);
}
if (gradientMed == null)
{
createGradient(ref gradientMed);
}
if (gradientHigh == null)
{
createGradient(ref gradientHigh);
}
CloudMaterial.SetVector("_Gradient1", gradientToVector4(gradientLow));
CloudMaterial.SetVector("_Gradient2", gradientToVector4(gradientMed));
CloudMaterial.SetVector("_Gradient3", gradientToVector4(gradientHigh));
CloudMaterial.SetInt("_Steps", steps);
CloudMaterial.SetInt("_renderInFront", renderInFront);
CloudMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
if (CurrentCamera.stereoEnabled)
{
left_world_from_view = CurrentCamera.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
right_world_from_view = CurrentCamera.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
left_screen_from_view = CurrentCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
right_screen_from_view = CurrentCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, renderIntoTexture: true).inverse;
right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, renderIntoTexture: true).inverse;
left_view_from_screen[1, 1] *= -1f;
right_view_from_screen[1, 1] *= -1f;
CloudMaterial.SetMatrix("_LeftWorldFromView", left_world_from_view);
CloudMaterial.SetMatrix("_RightWorldFromView", right_world_from_view);
CloudMaterial.SetMatrix("_LeftViewFromScreen", left_view_from_screen);
CloudMaterial.SetMatrix("_RightViewFromScreen", right_view_from_screen);
}
else
{
left_world_from_view = CurrentCamera.cameraToWorldMatrix;
left_screen_from_view = CurrentCamera.projectionMatrix;
left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, renderIntoTexture: true).inverse;
left_view_from_screen[1, 1] *= -1f;
CloudMaterial.SetMatrix("_LeftWorldFromView", left_world_from_view);
CloudMaterial.SetMatrix("_LeftViewFromScreen", left_view_from_screen);
}
CloudMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
CloudMaterial.SetVector("_CameraWS", position);
CloudMaterial.SetVector("_CameraWSOffset", _CameraWSOffset);
CloudMaterial.SetFloat("_FarPlane", CurrentCamera.farClipPlane);
CloudMaterial.SetFloat("extendFarPlaneAboveClouds", extendFarPlaneAboveClouds);
CloudMaterial.SetFloat("cameraScale", cameraScale);
CloudMaterial.SetVector("YCutHeightDepthScale", YCutHeightDepthScale);
CloudMaterial.SetFloat("multiplyStepsAboveClouds", multiplyStepsAboveClouds);
CloudMaterial.SetTexture("_InteractTexture", _InteractTexture);
CloudMaterial.SetVector("_InteractTexturePos", _InteractTexturePos);
CloudMaterial.SetVector("_InteractTextureAtr", _InteractTextureAtr);
CloudMaterial.SetVector("_InteractTextureOffset", _InteractTextureOffset);
CloudMaterial.SetInt("scatterOn", scatterOn);
CloudMaterial.SetInt("sunRaysOn", sunRaysOn);
CloudMaterial.SetFloat("sunRaysPower", sunRaysPower);
CloudMaterial.SetVector("raysResolution", raysResolution);
CloudMaterial.SetVector("rayShadowing", rayShadowing);
CloudMaterial.SetFloat("shadowPower", shadowPower);
CloudMaterial.SetVector("superCellControlsA", superCellControls);
updateMaterialKeyword(enableShadowCastOnClouds, "DEBUG_NO_CURL");
CloudMaterial.SetFloat("zeroCountSteps", zeroCountSteps);
CloudMaterial.SetInt("sunShaftSteps", sunShaftSteps);
float num7 = CurrentCamera.transform.position.y - height;
float z = ((num7 <= 0f) ? 1f : 0f);
CloudMaterial.SetVector("_HeightParams", new Vector4(height, num7, z, heightDensity * 0.5f));
CloudMaterial.SetVector("_DistanceParams", new Vector4(0f - Mathf.Max(startDistance, 0f), cloudDistanceParams.x, cloudDistanceParams.y, cloudDistanceParams.z));
CloudMaterial.SetFloat("_Scatter", _Scatter);
CloudMaterial.SetFloat("_HGCoeff", _HGCoeff);
CloudMaterial.SetFloat("_Extinct", _Extinct);
CloudMaterial.SetVector("_SkyTint", _SkyTint);
CloudMaterial.SetFloat("_BackShade", _BackShade);
if (localLight != null)
{
Vector3 position2 = localLight.transform.position;
currentLocalLightIntensity = Mathf.Pow(10f, 3f + (localLightFalloff - 3f) * 3f);
CloudMaterial.SetVector("_LocalLightPos", new Vector4(position2.x, position2.y, position2.z, localLight.intensity * localLightIntensity * currentLocalLightIntensity));
CloudMaterial.SetVector("_LocalLightColor", new Vector4(localLight.color.r, localLight.color.g, localLight.color.b, localLightFalloff));
}
else if (currentLocalLightIntensity > 0f)
{
currentLocalLightIntensity = 0f;
CloudMaterial.SetVector("_LocalLightColor", Vector4.zero);
}
CloudMaterial.SetFloat("luminance", luminance);
CloudMaterial.SetFloat("lumFac", lumFac);
CloudMaterial.SetFloat("Multiplier1", ScatterFac);
CloudMaterial.SetFloat("Multiplier2", TurbFac);
CloudMaterial.SetFloat("Multiplier3", HorizFac);
CloudMaterial.SetFloat("turbidity", turbidity);
CloudMaterial.SetFloat("reileigh", reileigh);
CloudMaterial.SetFloat("mieCoefficient", mieCoefficient);
CloudMaterial.SetFloat("mieDirectionalG", mieDirectionalG);
CloudMaterial.SetFloat("bias", bias);
CloudMaterial.SetFloat("contrast", contrast);
CloudMaterial.SetVector("v3LightDir", -sunLight.transform.forward);
CloudMaterial.SetVector("_TintColor", new Vector4(TintColor.x, TintColor.y, TintColor.z, 1f));
float value2 = 0f;
if (FogSky)
{
value2 = 1f;
}
CloudMaterial.SetFloat("FogSky", value2);
CloudMaterial.SetFloat("ClearSkyFac", ClearSkyFac);
FogMode fogMode = RenderSettings.fogMode;
float num8 = 0.01f;
float fogStartDistance = RenderSettings.fogStartDistance;
float fogEndDistance = RenderSettings.fogEndDistance;
bool flag = fogMode == FogMode.Linear;
float num9 = (flag ? (fogEndDistance - fogStartDistance) : 0f);
float num10 = ((Mathf.Abs(num9) > 0.0001f) ? (1f / num9) : 0f);
Vector4 value3 = default(Vector4);
value3.x = num8 * 1.2011224f;
value3.y = num8 * 1.442695f;
value3.z = (flag ? (0f - num10) : 0f);
value3.w = (flag ? (fogEndDistance * num10) : 0f);
CloudMaterial.SetVector("_SceneFogParams", value3);
CloudMaterial.SetVector("_SceneFogMode", new Vector4((float)fogMode, useRadialDistance ? 1 : 0, 0f, 0f));
CloudMaterial.SetVector("specialFX", specialFX);
UpscaleMaterial.SetFloat("controlBackAlphaPower", controlBackAlphaPower);
UpscaleMaterial.SetFloat("controlCloudAlphaPower", controlCloudAlphaPower);
UpscaleMaterial.SetVector("controlCloudEdgeA", controlCloudEdgeA);
CloudMaterial.SetFloat("depthDilation", depthDilation);
UpscaleMaterial.SetFloat("depthDilation", depthDilation);
RenderTexture temporary = RenderTexture.GetTemporary((int)((float)source.width / (float)downSample), (int)((float)source.height / (float)downSample), 0, source.format, RenderTextureReadWrite.Default, source.antiAliasing);
CustomGraphicsBlit(source, temporary, CloudMaterial, 0);
if (enableEdgeControl)
{
UpscaleMaterial.SetVector("edgeControl", edgeControl);
if (debugClouds > 0)
{
UpscaleMaterial.SetInt("enableEdges", debugClouds - 1);
}
else
{
UpscaleMaterial.SetInt("enableEdges", 1);
}
RenderTexture temporary2 = RenderTexture.GetTemporary(temporary.width, temporary.height, 0, temporary.format, RenderTextureReadWrite.Default);
Graphics.Blit(temporary, temporary2, UpscaleMaterial, 1);
if (temporalAntiAliasing && Application.isPlaying)
{
RenderTexture temporary3 = RenderTexture.GetTemporary(temporary.width, temporary.height, 0, temporary.format, RenderTextureReadWrite.Default, source.antiAliasing);
_temporalAntiAliasing.TemporalAntiAliasing(temporary2, temporary3);
UpscaleMaterial.SetTexture("_Clouds", temporary3);
if (debugClouds > 0)
{
Graphics.Blit(temporary2, destination, UpscaleMaterial, 0);
}
else
{
Graphics.Blit(source, destination, UpscaleMaterial, 0);
}
RenderTexture.ReleaseTemporary(temporary3);
}
else
{
UpscaleMaterial.SetTexture("_Clouds", temporary2);
if (debugClouds > 0)
{
Graphics.Blit(temporary2, destination, UpscaleMaterial, 0);
}
else
{
Graphics.Blit(source, destination, UpscaleMaterial, 0);
}
}
RenderTexture.ReleaseTemporary(temporary);
RenderTexture.ReleaseTemporary(temporary2);
}
else
{
UpscaleMaterial.SetInt("enableEdges", 0);
if (temporalAntiAliasing && Application.isPlaying)
{
RenderTexture temporary4 = RenderTexture.GetTemporary(temporary.width, temporary.height, 0, temporary.format, RenderTextureReadWrite.Default, source.antiAliasing);
_temporalAntiAliasing.TemporalAntiAliasing(temporary, temporary4);
UpscaleMaterial.SetTexture("_Clouds", temporary4);
RenderTexture.ReleaseTemporary(temporary4);
}
else
{
UpscaleMaterial.SetTexture("_Clouds", temporary);
}
Graphics.Blit(source, destination, UpscaleMaterial, 0);
RenderTexture.ReleaseTemporary(temporary);
}
}
private void updateMaterialKeyword(bool b, string keyword)
{
if (b != CloudMaterial.IsKeywordEnabled(keyword))
{
if (b)
{
CloudMaterial.EnableKeyword(keyword);
}
else
{
CloudMaterial.DisableKeyword(keyword);
}
}
}
private Matrix4x4 GetFrustumCorners(Camera cam)
{
float fieldOfView = cam.fieldOfView;
float aspect = cam.aspect;
Matrix4x4 identity = Matrix4x4.identity;
float num = Mathf.Tan(fieldOfView * 0.5f * (MathF.PI / 180f));
Vector3 vector = Vector3.right * num * aspect;
Vector3 vector2 = Vector3.up * num;
Vector3 vector3 = -Vector3.forward - vector + vector2;
Vector3 vector4 = -Vector3.forward + vector + vector2;
Vector3 vector5 = -Vector3.forward + vector - vector2;
Vector3 vector6 = -Vector3.forward - vector - vector2;
identity.SetRow(0, vector3);
identity.SetRow(1, vector4);
identity.SetRow(2, vector5);
identity.SetRow(3, vector6);
return identity;
}
private static void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr)
{
RenderTexture.active = dest;
GL.PushMatrix();
GL.LoadOrtho();
fxMaterial.SetPass(passNr);
GL.Begin(7);
GL.MultiTexCoord2(0, 0f, 0f);
GL.Vertex3(0f, 0f, 3f);
GL.MultiTexCoord2(0, 1f, 0f);
GL.Vertex3(1f, 0f, 2f);
GL.MultiTexCoord2(0, 1f, 1f);
GL.Vertex3(1f, 1f, 1f);
GL.MultiTexCoord2(0, 0f, 1f);
GL.Vertex3(0f, 1f, 0f);
GL.End();
GL.PopMatrix();
}
private void createGradient(ref Gradient gradient)
{
gradient = new Gradient();
colorKey = new GradientColorKey[4];
colorKey[0].color = Color.black;
colorKey[0].time = 0f;
colorKey[1].color = Color.white;
colorKey[1].time = 0.1f;
colorKey[2].color = Color.white;
colorKey[2].time = 0.9f;
colorKey[3].color = Color.black;
colorKey[3].time = 1f;
alphaKey = new GradientAlphaKey[4];
alphaKey[0].alpha = 1f;
alphaKey[0].time = 0f;
alphaKey[1].alpha = 1f;
alphaKey[1].time = 0.1f;
alphaKey[2].alpha = 1f;
alphaKey[2].time = 0.9f;
alphaKey[3].alpha = 1f;
alphaKey[3].time = 1f;
gradient.SetKeys(colorKey, alphaKey);
}
}
}