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

2112 lines
68 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
namespace Artngame.SKYMASTER
{
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class FullVolumeCloudsSkyMaster : PostEffectsBaseSkyMaster
{
public bool reflCamBlendBackground;
public float adjustReflPos = 8f;
public float adjustReflPos2;
public float adjustReflPos3;
public bool adjustVR;
public float shiftLeftEye;
public float cameraFarDistanceAdjust = 30000f;
public bool adjustNightLigting = true;
public float backShadeNight = 0.5f;
public float turbidityNight = 2f;
public float extinctionNight = 0.01f;
public float shift_dawn;
public float shift_dusk;
public Vector3 groundColorNight = new Vector3(0.5f, 0.5f, 0.5f);
public float scatterNight = 0.12f;
public float reflectFogHeight = 1f;
public bool isForReflections;
public bool windByWindZone;
public bool windByWeather;
public float windSunny = 0.01f;
public float windCloudy = 0.06f;
public float windStorm = 0.85f;
public float downscaleReflectNoiseSteps = 1f;
public bool adjustNightTimeSun = true;
public float varianceAltitude1;
public bool useWeather;
public SkyMasterManager.Volume_Weather_types prevWeather;
private bool weatherTransition = true;
private float weatherTransTimeStart;
public float weatherTransitionDuration = 45f;
public float sunnyDensity;
public float cloudyDensity = 2.5f;
public float stormyDensity = 4.5f;
public float weatherTransitionSpeed = 1.2f;
public bool heavyStorm;
private float localLightFalloffP;
private float localLightIntensityP;
private float sinSizeP;
private float backShadeP;
private float underSideP;
public bool unity2018 = true;
[Tooltip("Apply distance-based fog?")]
public bool distanceFog = true;
[Tooltip("Distance fog is based on radial distance from camera when checked")]
public bool useRadialDistance;
[Tooltip("Apply height-based fog?")]
public bool heightFog = true;
[Tooltip("Fog top Y coordinate")]
public float height = 1f;
[Range(1E-05f, 10f)]
public float heightDensity = 1E-05f;
[Tooltip("Push fog away from the camera by this amount")]
public float startDistance;
public float _mobileFactor = 1f;
public float _alphaFactor = 0.96f;
public float _HorizonZAdjust = 1f;
public bool updateReflectionCamera;
public bool updateReflectionCameraLocalLights;
public bool updateShadows = true;
public Material cloudsShadowMat;
public bool adaptLocalToLightning;
public bool useFluidTexture;
public Material fluidFlow;
public bool WebGL;
public bool blendBackground;
public Camera backgroundCam;
public Material backgroundMat;
public bool fastest;
public Light localLight;
public float localLightFalloff = 2f;
public float localLightIntensity = 1f;
public float currentLocalLightIntensity;
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);
public float _NearZCutoff = -2f;
public float _HorizonYAdjust;
public float _FadeThreshold;
public Texture3D texture3Dnoise1;
public Texture3D texture3Dnoise2;
public float _SampleCount0 = 42f;
public float _SampleCount1 = 3f;
public int _SampleCountL = 4;
public float _NoiseFreq1 = 3.1f;
public float _NoiseFreq2 = 35.1f;
public float _NoiseAmp1 = 5f;
public float _NoiseAmp2 = 1f;
public float _NoiseBias = -0.2f;
public float windMultiply = 1f;
public Vector3 _Scroll1 = new Vector3(0.01f, 0.08f, 0.06f);
public Vector3 _Scroll2 = new Vector3(0.01f, 0.05f, 0.03f);
public float _Altitude0 = 1500f;
public float _Altitude1 = 3500f;
public float _FarDist = 30000f;
public float _FarDistNight = 300000000f;
public float _FarDistDay = 400000f;
public float _Scatter = 0.008f;
public float _HGCoeff = 0.5f;
public float _Extinct = 0.01f;
public float _Exposure = 1E-05f;
public float _ExposureUnder = 3f;
public Vector3 _GroundColor = new Vector3(0.8f, 0.8f, 0.8f);
public float _SunSize = 0.04f;
public Vector3 _SkyTint = new Vector3(0.5f, 0.5f, 0.5f);
public float _AtmosphereThickness = 1f;
public float _BackShade = 1f;
public float _UndersideCurveFactor;
public Gradient DistGradient = new Gradient();
public Vector2 GradientBounds = Vector2.zero;
public float luminance = 0.05f;
public float lumFac = 0.2f;
public float ScatterFac = 500f;
public float TurbFac = 35f;
public float HorizFac = 62.4f;
public float turbidity = 30f;
public float reileigh = 170f;
public float mieCoefficient = 9.5f;
public float mieDirectionalG = 0.9f;
public float bias = 0.3f;
public float contrast = 6.5f;
public Transform Sun;
public bool FogSky;
public Vector3 TintColor = new Vector3(68f, 155f, 345f);
public float ClearSkyFac = 1f;
public Shader fogShader;
private Material fogMaterial;
public SkyMasterManager SkyManager;
private Texture2D colourPalette;
private bool Made_texture;
public bool useTOD;
public bool tintUnder;
public Vector3 colorMultiplier = Vector3.one;
public Vector3 UnderColorMultiplier = Vector3.one;
public bool adjustNightTimeDensity = true;
public bool followPlayer;
public Transform Galaxy;
public Transform ShadowLayer;
public GameObject shadowDome;
public GameObject backCamPrefab;
public GameObject shadowDomePrefab;
public GameObject LightningBoxPrefab;
public bool setupDepth;
public bool setupShadows;
public bool setupLightning;
public FullVolumeCloudsSkyMaster reflectClouds;
public GameObject LightningPrefab;
public bool EnableLightning;
public bool useLocalLightLightn;
private float last_lightning_time;
public float lightning_every = 15f;
public float max_lightning_time = 2f;
public float lightning_rate_offset = 5f;
private Transform LightningOne;
private Transform LightningTwo;
public Transform LightningBox;
private Light LightA;
private Light LightB;
private bool init_values = true;
public int gradientResolution = 256;
private Color[] colourArray;
private CameraClearFlags previousFlag;
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 Camera cam;
private int toggleCounter;
public int splitPerFrames = 1;
public bool cameraMotionCompensate = true;
private List<XRNodeState> nodeStatesCache = new List<XRNodeState>();
private Vector3 prevCenterPos;
public bool m_single_pass_stereo;
private RenderTexture tmpBuffer;
private RenderTexture tmpBufferL;
private RenderTexture tmpBufferR;
private RenderTexture tmpCloudBufferL;
private RenderTexture tmpCloudBufferR;
public float updateRate = 0.3f;
public int resolution = 256;
public int downScaleFactor = 1;
public int reflectDownScale = 4;
public float reduceReflectfarDist = 1f;
public bool downScale;
private RenderTexture _cloudBuffer;
private RenderTexture _cloudBufferP;
private RenderTexture _cloudBufferP1;
public bool _needsReset = true;
private Vector3 prevCameraRotL;
private Vector3 prevCameraRotR;
private Vector3 prevCameraRot;
private Vector3 prevCameraRotP;
private RenderTexture new1;
private int countCameraSteady;
public bool enableReproject;
public bool autoReproject;
private void Start1()
{
localLightFalloffP = localLightFalloff;
localLightIntensityP = localLightIntensity;
sinSizeP = _SunSize;
backShadeP = _BackShade;
underSideP = _UndersideCurveFactor;
}
public void initVariablesScatter()
{
heightDensity = 0.003f;
height = 40f;
startDistance = 0f;
windMultiply = 0.05f;
useTOD = true;
unity2018 = true;
useWeather = true;
updateShadows = true;
shadowsUpdate();
updateReflectionCamera = true;
_HorizonYAdjust = -700f;
_NoiseFreq1 = 3.9f;
_NoiseFreq2 = 29f;
_NoiseAmp1 = 4.82f;
_NoiseAmp2 = 4.04f;
if (!useWeather)
{
_NoiseBias = -3.63f;
}
_Altitude0 = 2300f;
_Altitude1 = 4500f;
_Scatter = 0.015f;
_Extinct = 0.0095f;
_ExposureUnder = 1f;
_HGCoeff = 0.19f;
_GroundColor = Vector3.one * 1.8f;
_SunSize = 2f;
_BackShade = 0.12f;
_UndersideCurveFactor = 0.5f;
luminance = 0.9f;
lumFac = 0.9f;
ScatterFac = 800f;
TurbFac = 35f;
HorizFac = 62.4f;
turbidity = 80f;
reileigh = 171f;
mieCoefficient = 2f;
mieDirectionalG = 0.74f;
bias = 3.6f;
contrast = 7.59f;
TintColor = new Vector3(74f, 78f, 345f);
}
public void initVariablesA()
{
_Altitude0 = 2300f;
_Altitude1 = 4200f;
_SampleCount0 = 1f;
_SampleCount1 = 140f;
_SampleCountL = 9;
_NoiseFreq1 = 5.1f;
_NoiseFreq2 = 49f;
_NoiseAmp1 = 5.32f;
_NoiseAmp2 = 2.34f;
if (!useWeather)
{
_NoiseBias = -3.8f;
}
splitPerFrames = 1;
downScale = true;
downScaleFactor = 2;
_Scatter = 0.02f;
_Extinct = 0.01f;
_HGCoeff = -0.05f;
_BackShade = 0.4f;
_UndersideCurveFactor = 0.2f;
_FarDist = 442000f;
distanceFog = false;
_SunSize = 20f;
_Scroll1 = new Vector3(-0.25f, -0.14f, -0.25f);
_Scroll2 = new Vector3(0.01f, 0.05f, 0.03f);
_InteractTexturePos = new Vector4(0.06f, 0.05f, -1222f, -1222f);
_InteractTextureAtr = new Vector4(0.34f, 0.991f, 0f, 1f);
_InteractTextureOffset = new Vector4(1100f, 1100f, 0f, 0f);
_HorizonYAdjust = 2000f;
}
public void createDepthSetup()
{
if (!setupDepth)
{
return;
}
int num = LayerMask.NameToLayer("Background");
if (num > -1)
{
SkyManager.SunObj.layer = num;
SkyManager.MoonObj.layer = num;
SkyManager.CloudDomeL1.layer = num;
SkyManager.CloudDomeL2.layer = num;
SkyManager.StarDome.layer = num;
SkyManager.Star_particles_OBJ.layer = num;
Transform[] componentsInChildren = base.transform.GetComponentsInChildren<Transform>(includeInactive: true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (componentsInChildren[i].name.Contains("STAR_GALAXY_DOME"))
{
componentsInChildren[i].gameObject.layer = num;
Galaxy = componentsInChildren[i];
break;
}
}
if (Galaxy == null)
{
componentsInChildren = SkyManager.transform.GetComponentsInChildren<Transform>(includeInactive: true);
for (int j = 0; j < componentsInChildren.Length; j++)
{
if (componentsInChildren[j].name.Contains("STAR_GALAXY_DOME"))
{
componentsInChildren[j].gameObject.layer = num;
Galaxy = componentsInChildren[j];
break;
}
}
}
ParticleSystem[] componentsInChildren2 = SkyManager.Star_particles_OBJ.transform.GetComponentsInChildren<ParticleSystem>(includeInactive: true);
for (int k = 0; k < componentsInChildren2.Length; k++)
{
componentsInChildren2[k].gameObject.layer = num;
}
if (backgroundCam == null)
{
GameObject gameObject = UnityEngine.Object.Instantiate(backCamPrefab);
backgroundCam = gameObject.GetComponent<Camera>();
}
backgroundCam.cullingMask = 1 << num;
Camera.main.cullingMask &= ~(1 << num);
backgroundCam.farClipPlane = Camera.main.farClipPlane;
backgroundCam.tag = "Untagged";
if (followPlayer)
{
Vector3 position = Camera.main.transform.position;
SkyManager.SunObj.layer = num;
SkyManager.MoonObj.layer = num;
SkyManager.CloudDomeL1.layer = num;
SkyManager.CloudDomeL2.layer = num;
SkyManager.StarDome.layer = num;
SkyManager.Star_particles_OBJ.layer = num;
Galaxy.position = new Vector3(Galaxy.position.x, Galaxy.position.z);
shadowDome.transform.position = new Vector3(position.x, shadowDome.transform.position.y, position.z);
}
}
else
{
Debug.Log("Please add the Background layer to proceed with the setup");
}
setupDepth = false;
}
public void createShadowDome()
{
if (setupShadows)
{
if (shadowDome == null)
{
GameObject gameObject = UnityEngine.Object.Instantiate(shadowDomePrefab);
shadowDome = gameObject;
}
setupShadows = false;
}
}
public void createLightningBox()
{
if (setupLightning)
{
if (LightningBox == null)
{
GameObject gameObject = UnityEngine.Object.Instantiate(LightningBoxPrefab);
LightningBox = gameObject.transform;
}
setupLightning = false;
}
}
public void shadowsUpdate()
{
if (!updateShadows || isForReflections)
{
return;
}
if ((bool)cloudsShadowMat)
{
cloudsShadowMat.SetVector("_InteractTextureAtr", _InteractTextureAtr);
cloudsShadowMat.SetVector("_InteractTextureOffset", _InteractTextureOffset);
cloudsShadowMat.SetVector("_InteractTexturePos", _InteractTexturePos);
cloudsShadowMat.SetTexture("_InteractTexture", _InteractTexture);
cloudsShadowMat.SetFloat("_Altitude0", _Altitude0);
cloudsShadowMat.SetFloat("_Altitude1", _Altitude1);
cloudsShadowMat.SetFloat("_NoiseBias", _NoiseBias);
cloudsShadowMat.SetFloat("_UndersideCurveFactor", _UndersideCurveFactor);
cloudsShadowMat.SetFloat("_BackShade", _BackShade);
if (Application.isPlaying)
{
cloudsShadowMat.SetVector("_Scroll1", _Scroll1);
cloudsShadowMat.SetVector("_Scroll2", _Scroll2);
}
else
{
cloudsShadowMat.SetVector("_Scroll1", Vector4.zero);
cloudsShadowMat.SetVector("_Scroll2", Vector4.zero);
}
cloudsShadowMat.SetFloat("_NoiseAmp1", _NoiseAmp1);
cloudsShadowMat.SetFloat("_NoiseAmp2", _NoiseAmp2);
cloudsShadowMat.SetFloat("_NoiseFreq1", _NoiseFreq1);
cloudsShadowMat.SetFloat("_NoiseFreq2", _NoiseFreq2);
}
updateShadows = false;
}
public void updateReflections()
{
if (Application.isPlaying && reflectClouds != null && updateReflectionCameraLocalLights)
{
reflectClouds.localLight = localLight;
}
if (!updateReflectionCamera)
{
return;
}
if ((bool)SkyManager && (bool)SkyManager.water)
{
PlanarReflectionSM componentInChildren = SkyManager.water.GetComponentInChildren<PlanarReflectionSM>();
if (componentInChildren.m_ReflectionCameraOut != null && !isForReflections)
{
reflectClouds = componentInChildren.m_ReflectionCameraOut.GetComponent<FullVolumeCloudsSkyMaster>();
if (reflectClouds == null)
{
reflectClouds = componentInChildren.m_ReflectionCameraOut.gameObject.AddComponent<FullVolumeCloudsSkyMaster>();
}
reflectClouds.isForReflections = true;
int num = LayerMask.NameToLayer("Background");
SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.cullingMask &= ~(1 << num);
PlanarReflectionSM component = SkyManager.water.GetComponent<PlanarReflectionSM>();
component.reflectionMask = (int)component.reflectionMask & ~(1 << num);
reflectClouds.distanceFog = false;
reflectClouds.windMultiply = windMultiply;
Vector3 forward = Camera.main.transform.forward;
float num2 = Vector3.SignedAngle(forward, new Vector3(forward.x, 0f, forward.z), Camera.main.transform.right);
float num3 = 22f;
if (num2 > 0f)
{
num3 -= num2;
num2 = 0.3f * num2;
}
reflectClouds.height = 1f * (height + num2 * num3) * reflectFogHeight;
reflectClouds.heightDensity = heightDensity;
reflectClouds.startDistance = startDistance;
reflectClouds.downScaleFactor = reflectDownScale;
reflectClouds.adjustReflPos = adjustReflPos;
reflectClouds.adjustReflPos2 = adjustReflPos2;
reflectClouds.adjustReflPos3 = adjustReflPos3;
reflectClouds.downScale = true;
reflectClouds.splitPerFrames = 0;
reflectClouds._needsReset = true;
reflectClouds._SampleCount0 = _SampleCount0;
reflectClouds._SampleCount1 = _SampleCount1 / downscaleReflectNoiseSteps;
reflectClouds._SampleCountL = (int)((float)_SampleCountL / downscaleReflectNoiseSteps);
reflectClouds.localLightFalloff = localLightFalloff;
reflectClouds.localLightIntensity = localLightIntensity;
reflectClouds.updateReflectionCameraLocalLights = updateReflectionCameraLocalLights;
reflectClouds.cloudsShadowMat = cloudsShadowMat;
reflectClouds.backgroundCam = backgroundCam;
reflectClouds.backgroundMat = backgroundMat;
reflectClouds.blendBackground = reflCamBlendBackground;
reflectClouds.WebGL = WebGL;
reflectClouds.texture3Dnoise1 = texture3Dnoise1;
reflectClouds.texture3Dnoise2 = texture3Dnoise2;
reflectClouds.Sun = Sun;
reflectClouds.fogShader = fogShader;
reflectClouds.SkyManager = SkyManager;
reflectClouds.LightningPrefab = LightningPrefab;
reflectClouds.LightningBox = LightningBox;
reflectClouds.cameraMotionCompensate = cameraMotionCompensate;
reflectClouds.lightning_every = lightning_every;
reflectClouds.max_lightning_time = max_lightning_time;
reflectClouds.lightning_rate_offset = lightning_rate_offset;
reflectClouds._FarDist = _FarDist / (reduceReflectfarDist * 1.4f);
reflectClouds._FarDistDay = _FarDistDay / (reduceReflectfarDist * 1.4f);
reflectClouds._FarDistDay = _FarDistDay / (reduceReflectfarDist * 1.4f);
reflectClouds._Scatter = _Scatter;
reflectClouds._HGCoeff = _HGCoeff;
reflectClouds._Extinct = _Extinct;
reflectClouds._SunSize = _SunSize;
reflectClouds._SkyTint = _SkyTint;
reflectClouds._ExposureUnder = _ExposureUnder;
reflectClouds._HorizonYAdjust = _HorizonYAdjust;
reflectClouds._HorizonZAdjust = _HorizonZAdjust;
reflectClouds._GroundColor = _GroundColor;
reflectClouds._mobileFactor = _mobileFactor;
reflectClouds._alphaFactor = _alphaFactor;
reflectClouds.luminance = luminance;
reflectClouds.lumFac = lumFac;
reflectClouds.ScatterFac = ScatterFac;
reflectClouds.TurbFac = TurbFac;
reflectClouds.turbidity = turbidity;
reflectClouds.HorizFac = HorizFac;
reflectClouds.reileigh = reileigh;
reflectClouds.mieCoefficient = mieCoefficient;
reflectClouds.mieDirectionalG = mieDirectionalG;
reflectClouds.bias = bias;
reflectClouds.contrast = contrast;
reflectClouds.TintColor = TintColor;
reflectClouds._InteractTextureAtr = _InteractTextureAtr;
reflectClouds._InteractTextureOffset = _InteractTextureOffset;
reflectClouds._InteractTexturePos = _InteractTexturePos;
reflectClouds._InteractTexture = _InteractTexture;
reflectClouds._Altitude0 = _Altitude0;
reflectClouds._Altitude1 = _Altitude1;
reflectClouds._NoiseBias = _NoiseBias;
reflectClouds._UndersideCurveFactor = _UndersideCurveFactor;
reflectClouds._BackShade = _BackShade;
reflectClouds._Scroll1 = _Scroll1;
reflectClouds._Scroll2 = _Scroll2;
reflectClouds._NoiseAmp1 = _NoiseAmp1;
reflectClouds._NoiseAmp2 = _NoiseAmp2;
reflectClouds._NoiseFreq1 = _NoiseFreq1;
reflectClouds._NoiseFreq2 = _NoiseFreq2;
reflectClouds.useTOD = useTOD;
reflectClouds.useWeather = useWeather;
}
}
updateReflectionCamera = false;
}
public void LightningUpdate()
{
if (!Application.isPlaying)
{
return;
}
if (EnableLightning)
{
if (LightningOne == null)
{
LightningOne = UnityEngine.Object.Instantiate(LightningPrefab).transform;
LightA = LightningOne.GetComponentInChildren<ChainLightning_SKYMASTER>().startLight;
LightningOne.gameObject.SetActive(value: false);
}
if (LightningTwo == null)
{
LightningTwo = UnityEngine.Object.Instantiate(LightningPrefab).transform;
LightB = LightningTwo.GetComponentInChildren<ChainLightning_SKYMASTER>().startLight;
LightningTwo.gameObject.SetActive(value: false);
}
if (!(LightningBox != null))
{
return;
}
if (Time.fixedTime - last_lightning_time > lightning_every - UnityEngine.Random.Range(0f - lightning_rate_offset, lightning_rate_offset))
{
Vector2 vector = LightningBox.position.x * Vector2.one + LightningBox.localScale.x / 2f * new Vector2(-1f, 1f);
Vector2 vector2 = LightningBox.position.y * Vector2.one + LightningBox.localScale.y / 2f * new Vector2(-1f, 1f);
Vector2 vector3 = LightningBox.position.z * Vector2.one + LightningBox.localScale.z / 2f * new Vector2(-1f, 1f);
LightningOne.position = new Vector3(UnityEngine.Random.Range(vector.x, vector.y), UnityEngine.Random.Range(vector2.x, vector2.y), UnityEngine.Random.Range(vector3.x, vector3.y));
if (UnityEngine.Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
{
LightningOne.gameObject.SetActive(value: true);
localLight = LightA;
}
LightningTwo.position = new Vector3(UnityEngine.Random.Range(vector.x, vector.y), UnityEngine.Random.Range(vector2.x, vector2.y), UnityEngine.Random.Range(vector3.x, vector3.y));
if (UnityEngine.Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
{
LightningTwo.gameObject.SetActive(value: true);
localLight = LightB;
}
last_lightning_time = Time.fixedTime;
}
else if (Time.fixedTime - last_lightning_time > max_lightning_time)
{
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
{
LightningOne.gameObject.SetActive(value: false);
localLight = null;
}
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
{
LightningTwo.gameObject.SetActive(value: false);
localLight = null;
}
}
}
else
{
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
{
LightningOne.gameObject.SetActive(value: false);
localLight = null;
}
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
{
LightningTwo.gameObject.SetActive(value: false);
localLight = null;
}
}
}
private void Update()
{
if (init_values)
{
Start1();
init_values = false;
}
createDepthSetup();
createShadowDome();
createLightningBox();
if (Application.isPlaying)
{
updateShadows = true;
}
shadowsUpdate();
if (Application.isPlaying)
{
updateReflectionCamera = true;
}
updateReflections();
if (Application.isPlaying)
{
LightningUpdate();
}
if (SkyManager != null)
{
if (useTOD)
{
bool flag = true;
if (heavyStorm && (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm))
{
_GroundColor = Vector3.Lerp(_GroundColor, new Vector3(0f, 0f, 0f), Time.deltaTime * weatherTransitionSpeed * 0.12f);
flag = false;
}
if (SkyManager.UseGradients && flag)
{
_SkyTint = Vector3.Lerp(b: new Vector3(SkyManager.gradSkyColor.r * colorMultiplier.x, SkyManager.gradSkyColor.g * colorMultiplier.y, SkyManager.gradSkyColor.b * colorMultiplier.z), a: _SkyTint, t: Time.deltaTime * weatherTransitionSpeed * 0.12f);
if (tintUnder)
{
_GroundColor = Vector3.Lerp(b: new Vector3(SkyManager.gradSkyColor.r * UnderColorMultiplier.x, SkyManager.gradSkyColor.g * UnderColorMultiplier.y, SkyManager.gradSkyColor.b * UnderColorMultiplier.z), a: _GroundColor, t: Time.deltaTime * weatherTransitionSpeed * 0.12f);
}
}
}
if (useWeather && !isForReflections)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Sunny && windByWeather)
{
windMultiply = Mathf.Lerp(windMultiply, windSunny, Time.deltaTime * 0.005f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy && windByWeather)
{
windMultiply = Mathf.Lerp(windMultiply, windCloudy, Time.deltaTime * 0.005f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm && windByWeather)
{
windMultiply = Mathf.Lerp(windMultiply, windStorm, Time.deltaTime * 0.005f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm && windByWeather)
{
windMultiply = Mathf.Lerp(windMultiply, windStorm, Time.deltaTime * 0.005f);
}
if (SkyManager.currentWeatherName != prevWeather)
{
prevWeather = SkyManager.currentWeatherName;
weatherTransition = true;
weatherTransTimeStart = Time.fixedTime;
}
if (weatherTransition)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Sunny)
{
_NoiseBias = Mathf.Lerp(_NoiseBias, sunnyDensity - 7.5f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy)
{
_NoiseBias = Mathf.Lerp(_NoiseBias, cloudyDensity - 6.5f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm)
{
_NoiseBias = Mathf.Lerp(_NoiseBias, stormyDensity - 6.5f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
{
_NoiseBias = Mathf.Lerp(_NoiseBias, stormyDensity - 6.5f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
EnableLightning = true;
}
else
{
EnableLightning = false;
}
if (heavyStorm && (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm))
{
localLightFalloff = Mathf.Lerp(localLightFalloff, 2.6f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
localLightIntensity = Mathf.Lerp(localLightIntensity, 6f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
_SunSize = Mathf.Lerp(_SunSize, -1.5f, Time.deltaTime * weatherTransitionSpeed * 0.16f);
_BackShade = Mathf.Lerp(_BackShade, 0.73f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
_UndersideCurveFactor = Mathf.Lerp(_UndersideCurveFactor, 0.1f, Time.deltaTime * weatherTransitionSpeed * 0.02f);
}
else
{
localLightFalloff = Mathf.Lerp(localLightFalloff, localLightFalloffP, Time.deltaTime * weatherTransitionSpeed * 0.02f);
localLightIntensity = Mathf.Lerp(localLightIntensity, localLightIntensityP, Time.deltaTime * weatherTransitionSpeed * 0.02f);
_SunSize = Mathf.Lerp(_SunSize, sinSizeP, Time.deltaTime * weatherTransitionSpeed * 0.16f);
_BackShade = Mathf.Lerp(_BackShade, backShadeP, Time.deltaTime * weatherTransitionSpeed * 0.02f);
_UndersideCurveFactor = Mathf.Lerp(_UndersideCurveFactor, underSideP, Time.deltaTime * weatherTransitionSpeed * 0.02f);
}
if (Time.fixedTime - weatherTransTimeStart > weatherTransitionDuration)
{
weatherTransition = false;
}
}
if (SkyManager.windZone != null)
{
if (windByWindZone)
{
windMultiply = Mathf.Lerp(windMultiply, SkyManager.windZone.windMain + 0f, Time.deltaTime * 0.02f);
}
_Scroll1.x = (0f - windMultiply) * SkyManager.windZone.transform.forward.x;
_Scroll1.z = (0f - windMultiply) * SkyManager.windZone.transform.forward.z;
_Scroll2.x = _Scroll1.x;
_Scroll2.z = _Scroll1.z;
}
}
if (adjustNightTimeDensity)
{
if ((!SkyManager.AutoSunPosition && SkyManager.Current_Time >= 9f + SkyManager.Shift_dawn + shift_dawn && SkyManager.Current_Time <= SkyManager.NightTimeMax + SkyManager.Shift_dawn + shift_dusk) || (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 0f))
{
_FarDist = _FarDistDay;
}
else
{
_FarDist = _FarDistNight;
}
}
if (adjustNightTimeSun)
{
if ((!SkyManager.AutoSunPosition && ((SkyManager.Current_Time >= 9f + SkyManager.Shift_dawn) & (SkyManager.Current_Time <= SkyManager.NightTimeMax + SkyManager.Shift_dawn))) || (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 0f))
{
if (Sun != SkyManager.SunObj.transform)
{
Sun = SkyManager.SunObj.transform;
}
}
else if (Sun != SkyManager.MoonObj.transform)
{
Sun = SkyManager.MoonObj.transform;
}
}
}
if (colourArray == null)
{
colourArray = new Color[gradientResolution];
}
}
private void Awake()
{
Start1();
_needsReset = true;
colourArray = new Color[gradientResolution];
for (int i = 0; i < colourArray.Length; i++)
{
colourArray[i] = DistGradient.Evaluate((float)i / (float)colourArray.Length);
}
if (!Made_texture)
{
colourPalette = new Texture2D(gradientResolution, 10, TextureFormat.ARGB32, mipChain: false);
colourPalette.filterMode = FilterMode.Point;
colourPalette.wrapMode = TextureWrapMode.Clamp;
Made_texture = true;
}
for (int j = 0; j < gradientResolution; j++)
{
for (int k = 0; k < 10; k++)
{
colourPalette.SetPixel(j, k, colourArray[j]);
}
}
colourPalette.Apply();
cam = GetComponent<Camera>();
}
public override bool CheckResources()
{
CheckSupport(needDepth: true);
fogMaterial = CheckShaderAndCreateMaterial(fogShader, fogMaterial);
if (!isSupported)
{
ReportAutoDisable();
}
return isSupported;
}
private void OnPreRender()
{
if (!fastest)
{
cam = GetComponent<Camera>();
previousFlag = cam.clearFlags;
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
cam.clearFlags = CameraClearFlags.Color;
}
cam.depthTextureMode = DepthTextureMode.DepthNormals;
Camera camera = cam;
if (isForReflections)
{
_ = Camera.main != null;
}
if (fogMaterial != null && !isForReflections)
{
if (camera.stereoEnabled && toggleCounter != 2 && toggleCounter != 3)
{
left_world_from_view = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
right_world_from_view = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
left_screen_from_view = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
right_screen_from_view = cam.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;
fogMaterial.SetMatrix("_LeftWorldFromView", left_world_from_view);
fogMaterial.SetMatrix("_RightWorldFromView", right_world_from_view);
fogMaterial.SetMatrix("_LeftViewFromScreen", left_view_from_screen);
fogMaterial.SetMatrix("_RightViewFromScreen", right_view_from_screen);
_ = isForReflections;
}
else
{
left_world_from_view = cam.cameraToWorldMatrix;
left_screen_from_view = cam.projectionMatrix;
left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, renderIntoTexture: true).inverse;
left_view_from_screen[1, 1] *= -1f;
fogMaterial.SetMatrix("_LeftWorldFromView", left_world_from_view);
fogMaterial.SetMatrix("_LeftViewFromScreen", left_view_from_screen);
}
}
}
private void OnPostRender()
{
if (!fastest)
{
cam = GetComponent<Camera>();
cam.clearFlags = previousFlag;
}
}
private bool TryGetCenterEyeNodeStateRotation(out Quaternion rotation)
{
InputTracking.GetNodeStates(nodeStatesCache);
for (int i = 0; i < nodeStatesCache.Count; i++)
{
XRNodeState xRNodeState = nodeStatesCache[i];
if (xRNodeState.nodeType == XRNode.CenterEye && xRNodeState.TryGetRotation(out rotation))
{
return true;
}
}
rotation = Quaternion.identity;
return false;
}
private bool TryGetLeftEyeNodeStatePosition(out Vector3 position)
{
InputTracking.GetNodeStates(nodeStatesCache);
for (int i = 0; i < nodeStatesCache.Count; i++)
{
XRNodeState xRNodeState = nodeStatesCache[i];
if (xRNodeState.nodeType == XRNode.LeftEye && xRNodeState.TryGetPosition(out position))
{
return true;
}
}
position = Vector3.zero;
return false;
}
private void OnValidate()
{
}
[ImageEffectOpaque]
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (!CheckResources() || (!distanceFog && !heightFog))
{
Graphics.Blit(source, destination);
return;
}
Transform transform = cam.transform;
if (isForReflections)
{
left_world_from_view = cam.cameraToWorldMatrix;
left_screen_from_view = cam.projectionMatrix;
Matrix4x4 inverse = GL.GetGPUProjectionMatrix(left_screen_from_view, renderIntoTexture: true).inverse;
inverse[1, 1] *= -1f;
inverse[3, 3] += 3f;
fogMaterial.SetMatrix("_LeftWorldFromView", left_world_from_view);
fogMaterial.SetMatrix("_LeftViewFromScreen", inverse);
fogMaterial.SetMatrix("_RightWorldFromView", left_world_from_view);
fogMaterial.SetMatrix("_RightViewFromScreen", inverse);
}
if (adjustVR)
{
prevCenterPos = cam.transform.position;
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
transform.position += new Vector3(shiftLeftEye, 0f, 0f);
}
}
float nearClipPlane = cam.nearClipPlane;
float farClipPlane = cam.farClipPlane;
float fieldOfView = cam.fieldOfView;
float aspect = cam.aspect;
Matrix4x4 identity = Matrix4x4.identity;
float num = fieldOfView * 0.5f;
Vector3 vector = transform.right * nearClipPlane * Mathf.Tan(num * (MathF.PI / 180f)) * aspect;
Vector3 vector2 = transform.up * nearClipPlane * Mathf.Tan(num * (MathF.PI / 180f));
Vector3 vector3 = transform.forward * nearClipPlane - vector + vector2;
float num2 = vector3.magnitude * farClipPlane / nearClipPlane;
vector3.Normalize();
vector3 *= num2;
Vector3 vector4 = transform.forward * nearClipPlane + vector + vector2;
vector4.Normalize();
vector4 *= num2;
Vector3 vector5 = transform.forward * nearClipPlane + vector - vector2;
vector5.Normalize();
vector5 *= num2;
Vector3 vector6 = transform.forward * nearClipPlane - vector - vector2;
vector6.Normalize();
vector6 *= num2;
identity.SetRow(0, vector3);
identity.SetRow(1, vector4);
identity.SetRow(2, vector5);
identity.SetRow(3, vector6);
Vector3 position = transform.position;
float num3 = position.y - height;
float z = ((num3 <= 0f) ? 1f : 0f);
fogMaterial.SetMatrix("_FrustumCornersWS", identity);
fogMaterial.SetVector("_CameraWS", position);
fogMaterial.SetVector("_HeightParams", new Vector4(height, num3, z, heightDensity * 0.5f));
fogMaterial.SetVector("_DistanceParams", new Vector4(0f - Mathf.Max(startDistance, 0f), 0f, 0f, 0f));
if (!useFluidTexture)
{
fogMaterial.SetTexture("_InteractTexture", _InteractTexture);
}
else
{
fogMaterial.SetTexture("_InteractTexture", fluidFlow.GetTexture("_MainTex"));
}
fogMaterial.SetVector("_InteractTexturePos", _InteractTexturePos);
fogMaterial.SetVector("_InteractTextureAtr", _InteractTextureAtr);
fogMaterial.SetVector("_InteractTextureOffset", _InteractTextureOffset);
fogMaterial.SetFloat("_NearZCutoff", _NearZCutoff);
fogMaterial.SetFloat("_HorizonYAdjust", _HorizonYAdjust);
fogMaterial.SetFloat("_HorizonZAdjust", _HorizonZAdjust);
fogMaterial.SetFloat("_FadeThreshold", _FadeThreshold);
fogMaterial.SetFloat("_mobileFactor", _mobileFactor);
fogMaterial.SetFloat("_alphaFactor", _alphaFactor);
fogMaterial.SetFloat("_SampleCount0", _SampleCount0);
fogMaterial.SetFloat("_SampleCount1", _SampleCount1);
fogMaterial.SetInt("_SampleCountL", _SampleCountL);
fogMaterial.SetFloat("_NoiseFreq1", _NoiseFreq1);
fogMaterial.SetFloat("_NoiseFreq2", _NoiseFreq2);
fogMaterial.SetFloat("_NoiseAmp1", _NoiseAmp1);
fogMaterial.SetFloat("_NoiseAmp2", _NoiseAmp2);
fogMaterial.SetFloat("_NoiseBias", _NoiseBias);
if (Application.isPlaying)
{
fogMaterial.SetVector("_Scroll1", _Scroll1);
fogMaterial.SetVector("_Scroll2", _Scroll2);
}
else
{
fogMaterial.SetVector("_Scroll1", Vector4.zero);
fogMaterial.SetVector("_Scroll2", Vector4.zero);
}
fogMaterial.SetFloat("_Altitude0", _Altitude0);
fogMaterial.SetFloat("_Altitude1", _Altitude1);
fogMaterial.SetFloat("_FarDist", _FarDist);
fogMaterial.SetFloat("_HGCoeff", _HGCoeff);
fogMaterial.SetFloat("_Exposure", _ExposureUnder);
if (!adjustNightLigting)
{
fogMaterial.SetFloat("_Scatter", _Scatter);
fogMaterial.SetVector("_GroundColor", _GroundColor);
fogMaterial.SetFloat("_BackShade", _BackShade);
fogMaterial.SetFloat("turbidity", turbidity);
fogMaterial.SetFloat("_Extinct", _Extinct);
}
else if ((!SkyManager.AutoSunPosition && ((SkyManager.Current_Time >= 9f + SkyManager.Shift_dawn) & (SkyManager.Current_Time <= SkyManager.NightTimeMax + SkyManager.Shift_dawn))) || (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 0f))
{
float a = fogMaterial.GetFloat("_Scatter");
Vector3 a2 = fogMaterial.GetVector("_GroundColor");
float a3 = fogMaterial.GetFloat("_BackShade");
float a4 = fogMaterial.GetFloat("turbidity");
float a5 = fogMaterial.GetFloat("_Extinct");
if (Time.fixedTime < 1f)
{
fogMaterial.SetFloat("_Scatter", _Scatter);
fogMaterial.SetVector("_GroundColor", _GroundColor);
fogMaterial.SetFloat("_BackShade", _BackShade);
fogMaterial.SetFloat("turbidity", turbidity);
fogMaterial.SetFloat("_Extinct", _Extinct);
}
else
{
fogMaterial.SetFloat("_Scatter", Mathf.Lerp(a, _Scatter, Time.deltaTime * 0.2f));
fogMaterial.SetVector("_GroundColor", Vector3.Lerp(a2, _GroundColor, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("_BackShade", Mathf.Lerp(a3, _BackShade, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("turbidity", Mathf.Lerp(a4, turbidity, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("_Extinct", Mathf.Lerp(a5, _Extinct, Time.deltaTime * 0.2f));
}
}
else
{
float a6 = fogMaterial.GetFloat("_Scatter");
Vector3 a7 = fogMaterial.GetVector("_GroundColor");
float a8 = fogMaterial.GetFloat("_BackShade");
float a9 = fogMaterial.GetFloat("turbidity");
float a10 = fogMaterial.GetFloat("_Extinct");
if (Time.fixedTime < 1f)
{
fogMaterial.SetFloat("_Scatter", scatterNight);
fogMaterial.SetVector("_GroundColor", groundColorNight);
fogMaterial.SetFloat("_BackShade", _BackShade);
fogMaterial.SetFloat("turbidity", turbidity);
fogMaterial.SetFloat("_Extinct", _Extinct);
}
else
{
fogMaterial.SetFloat("_Scatter", Mathf.Lerp(a6, scatterNight, Time.deltaTime * 0.2f));
fogMaterial.SetVector("_GroundColor", Vector3.Lerp(a7, groundColorNight, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("_BackShade", Mathf.Lerp(a8, backShadeNight, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("turbidity", Mathf.Lerp(a9, turbidityNight, Time.deltaTime * 0.2f));
fogMaterial.SetFloat("_Extinct", Mathf.Lerp(a10, extinctionNight, Time.deltaTime * 0.2f));
}
}
fogMaterial.SetFloat("_SunSize", _SunSize);
fogMaterial.SetVector("_SkyTint", _SkyTint);
fogMaterial.SetFloat("_AtmosphereThickness", _AtmosphereThickness);
fogMaterial.SetFloat("_UndersideCurveFactor", _UndersideCurveFactor);
if (localLight != null)
{
Vector3 position2 = localLight.transform.position;
currentLocalLightIntensity = Mathf.Pow(10f, 3f + (localLightFalloff - 3f) * 3f);
fogMaterial.SetVector("_LocalLightPos", new Vector4(position2.x, position2.y, position2.z, localLight.intensity * localLightIntensity * currentLocalLightIntensity));
fogMaterial.SetVector("_LocalLightColor", new Vector4(localLight.color.r, localLight.color.g, localLight.color.b, localLightFalloff));
}
else if (currentLocalLightIntensity > 0f)
{
currentLocalLightIntensity = 0f;
fogMaterial.SetVector("_LocalLightColor", Vector4.zero);
}
fogMaterial.SetFloat("luminance", luminance);
fogMaterial.SetFloat("lumFac", lumFac);
fogMaterial.SetFloat("Multiplier1", ScatterFac);
fogMaterial.SetFloat("Multiplier2", TurbFac);
fogMaterial.SetFloat("Multiplier3", HorizFac);
fogMaterial.SetFloat("reileigh", reileigh);
fogMaterial.SetFloat("mieCoefficient", mieCoefficient);
fogMaterial.SetFloat("mieDirectionalG", mieDirectionalG);
fogMaterial.SetFloat("bias", bias);
fogMaterial.SetFloat("contrast", contrast);
fogMaterial.SetFloat("varianceAltitude1", varianceAltitude1);
if (isForReflections)
{
if (adjustNightTimeSun && Application.isPlaying && Time.fixedTime > 5f)
{
Vector3 a11 = fogMaterial.GetVector("v3LightDir");
fogMaterial.SetVector("v3LightDir", Vector3.Lerp(a11, new Vector3(0f - Sun.forward.x, Sun.forward.y, 0f - Sun.forward.z), Time.deltaTime * 0.2f));
}
else
{
fogMaterial.SetVector("v3LightDir", new Vector3(0f - Sun.forward.x, Sun.forward.y, 0f - Sun.forward.z));
}
}
else if (adjustNightTimeSun && Application.isPlaying && Time.fixedTime > 5f)
{
Vector3 a12 = fogMaterial.GetVector("v3LightDir");
fogMaterial.SetVector("v3LightDir", Vector3.Lerp(a12, -Sun.forward, Time.deltaTime * 0.2f));
}
else
{
fogMaterial.SetVector("v3LightDir", -Sun.forward);
}
fogMaterial.SetVector("_TintColor", new Vector4(TintColor.x, TintColor.y, TintColor.z, 1f));
float value = 0f;
if (FogSky)
{
value = 1f;
}
fogMaterial.SetFloat("FogSky", value);
fogMaterial.SetFloat("ClearSkyFac", ClearSkyFac);
fogMaterial.SetFloat("_cameraFarDistanceAdjust", cameraFarDistanceAdjust);
FogMode fogMode = RenderSettings.fogMode;
float num4 = 0.01f;
float fogStartDistance = RenderSettings.fogStartDistance;
float fogEndDistance = RenderSettings.fogEndDistance;
bool flag = fogMode == FogMode.Linear;
float num5 = (flag ? (fogEndDistance - fogStartDistance) : 0f);
float num6 = ((Mathf.Abs(num5) > 0.0001f) ? (1f / num5) : 0f);
Vector4 value2 = default(Vector4);
value2.x = num4 * 1.2011224f;
value2.y = num4 * 1.442695f;
value2.z = (flag ? (0f - num6) : 0f);
value2.w = (flag ? (fogEndDistance * num6) : 0f);
fogMaterial.SetVector("_SceneFogParams", value2);
fogMaterial.SetVector("_SceneFogMode", new Vector4((float)fogMode, useRadialDistance ? 1 : 0, 0f, 0f));
int num7 = 0;
num7 = ((!distanceFog || !heightFog) ? (distanceFog ? 1 : 2) : 0);
if (isForReflections)
{
fogMaterial.SetFloat("_invertX", 1f);
}
else
{
fogMaterial.SetFloat("_invertX", 0f);
}
if (isForReflections)
{
fogMaterial.SetFloat("_invertRay", -1f);
}
else
{
fogMaterial.SetFloat("_invertRay", 1f);
}
if (isForReflections)
{
fogMaterial.SetVector("_WorldSpaceCameraPosC", position);
}
else
{
fogMaterial.SetVector("_WorldSpaceCameraPosC", position);
}
if (!downScale)
{
CustomGraphicsBlit(source, destination, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, WebGL);
}
else if (!fastest)
{
if (tmpBuffer == null || tmpBufferL == null || tmpBufferR == null)
{
RenderTextureFormat colorFormat = (cam.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default);
RenderTextureDescriptor eyeTextureDesc;
if (XRSettings.enabled)
{
eyeTextureDesc = XRSettings.eyeTextureDesc;
eyeTextureDesc = new RenderTextureDescriptor(source.width + 125, source.height + 125, colorFormat, 0);
}
else
{
eyeTextureDesc = new RenderTextureDescriptor(source.width + 125, source.height + 125, colorFormat, 0);
}
tmpBuffer = RenderTexture.GetTemporary(eyeTextureDesc);
tmpBufferL = RenderTexture.GetTemporary(eyeTextureDesc);
tmpBufferR = RenderTexture.GetTemporary(eyeTextureDesc);
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
RenderTexture.active = tmpBufferL;
}
else
{
RenderTexture.active = tmpBufferR;
}
}
else
{
RenderTexture.active = tmpBuffer;
}
GL.ClearWithSkybox(clearDepth: false, cam);
if (blendBackground)
{
if (isForReflections)
{
backgroundCam.transform.rotation = cam.transform.rotation;
backgroundCam.transform.position = cam.transform.position;
if (Camera.main.stereoEnabled)
{
Matrix4x4 projectionMatrix = cam.projectionMatrix;
float angle = adjustReflPos;
float angle2 = adjustReflPos2;
float num8 = adjustReflPos3;
float num9 = cam.transform.eulerAngles.x;
if (num9 > 180f)
{
num9 = 0f - (360f - num9);
}
num8 = (0f - num9) / 6f;
if (backgroundCam.nearClipPlane == 1f)
{
angle = 0f - adjustReflPos;
angle2 = 0f - adjustReflPos2;
num8 = 0f - num8;
}
Matrix4x4 matrix4x = Matrix4x4.Rotate(Quaternion.AngleAxis(angle, Vector3.up));
Matrix4x4 matrix4x2 = Matrix4x4.Rotate(Quaternion.AngleAxis(num8, Vector3.forward));
backgroundCam.projectionMatrix = projectionMatrix * matrix4x * matrix4x2;
Matrix4x4 matrix4x3 = Matrix4x4.Rotate(Quaternion.AngleAxis(angle2, Vector3.up));
Matrix4x4 matrix4x4 = cam.cameraToWorldMatrix * matrix4x3 * matrix4x2;
backgroundCam.worldToCameraMatrix = matrix4x4.inverse;
}
}
else if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
backgroundCam.worldToCameraMatrix = left_world_from_view;
backgroundCam.projectionMatrix = left_screen_from_view;
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component.WaterTileBeingRenderedA(base.transform, cam, 0);
}
}
}
else
{
backgroundCam.worldToCameraMatrix = right_world_from_view;
backgroundCam.projectionMatrix = right_screen_from_view;
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component2 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component2.WaterTileBeingRenderedA(base.transform, cam, 1);
}
}
}
}
else
{
backgroundCam.transform.rotation = cam.transform.rotation;
backgroundCam.transform.position = cam.transform.position;
backgroundCam.worldToCameraMatrix = Camera.main.worldToCameraMatrix;
backgroundCam.projectionMatrix = Camera.main.projectionMatrix;
}
if (unity2018 && Screen.width > 0 && (backgroundCam.targetTexture == null || backgroundCam.targetTexture.width != Screen.width || backgroundCam.targetTexture.height != Screen.height))
{
backgroundCam.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
}
if (isForReflections)
{
backgroundCam.transform.eulerAngles = new Vector3(backgroundCam.transform.eulerAngles.x, backgroundCam.transform.eulerAngles.y, 180f);
SkyManager.setMoonShader(backgroundCam.transform, 0.5f);
backgroundCam.Render();
tmpBuffer.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, tmpBuffer);
SkyManager.setMoonShader(Camera.main.transform, 1f);
}
else
{
backgroundCam.Render();
Graphics.Blit(backgroundCam.targetTexture, tmpBuffer, backgroundMat);
}
}
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
CustomGraphicsBlitOpt(source, destination, tmpBufferL, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, 0);
CustomGraphicsBlitOpt(source, destination, tmpBufferL, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, 0);
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBufferR, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, 1);
CustomGraphicsBlitOpt(source, destination, tmpBufferR, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, 1);
}
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBuffer, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, -1);
CustomGraphicsBlitOpt(source, destination, tmpBuffer, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, -1);
}
}
else if (((!cam.stereoEnabled && toggleCounter != 0) || (cam.stereoEnabled && (toggleCounter == 2 || toggleCounter == 3))) && Application.isPlaying && splitPerFrames > 0)
{
if (enableReproject)
{
int num10 = 1;
if (WebGL)
{
num10 = -1;
}
Camera main = cam;
if (Camera.main != null)
{
main = Camera.main;
}
Matrix4x4 value3 = cam.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(2f, num10, -1f)) * main.projectionMatrix.inverse * Matrix4x4.Scale(new Vector3(-1f, 1f, 1f));
float value4 = (float)toggleCounter / (float)splitPerFrames;
float num11 = cam.transform.eulerAngles.y - prevCameraRotP.y;
float num12 = 0f - (cam.transform.eulerAngles.x - prevCameraRotP.x);
if (num11 > 122f || num11 < -122f)
{
num11 = 0f;
}
if (num12 > 122f || num12 < -122f)
{
num12 = 0f;
}
value3[0, 3] = 1f * num11;
value3[1, 3] = 1f * num12;
value3[2, 3] = 1f;
fogMaterial.SetMatrix("_WorldClip", value3);
fogMaterial.SetTexture("_CloudTexP", _cloudBuffer);
fogMaterial.SetTexture("_CloudTex", _cloudBufferP);
fogMaterial.SetFloat("frameFraction", value4);
Graphics.Blit(_cloudBufferP, _cloudBufferP1, fogMaterial, 5);
}
if (cam.stereoEnabled)
{
if (toggleCounter == 2)
{
toggleCounter = 3;
}
else if (toggleCounter == 3)
{
toggleCounter = 0;
}
}
else
{
toggleCounter--;
}
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
CustomGraphicsBlitOpt(source, destination, tmpBufferL, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: true, WebGL, 0);
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBufferR, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: true, WebGL, 1);
}
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBuffer, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: true, WebGL, -1);
}
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component3 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component3.WaterTileBeingRenderedA(base.transform, cam, 0);
backgroundCam.nearClipPlane = 1f;
}
}
}
else if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component4 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component4.WaterTileBeingRenderedA(base.transform, cam, 1);
backgroundCam.nearClipPlane = 2f;
}
}
backgroundCam.transform.position = Camera.main.transform.position;
backgroundCam.worldToCameraMatrix = Camera.main.worldToCameraMatrix;
backgroundCam.projectionMatrix = Camera.main.projectionMatrix;
backgroundCam.transform.rotation = Camera.main.transform.parent.rotation;
}
}
else
{
if (cam.stereoEnabled)
{
toggleCounter++;
}
else
{
toggleCounter = splitPerFrames;
}
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
RenderTexture.active = tmpBufferL;
}
else
{
RenderTexture.active = tmpBufferR;
}
}
else
{
RenderTexture.active = tmpBuffer;
}
GL.ClearWithSkybox(clearDepth: false, cam);
if (blendBackground)
{
if (isForReflections)
{
backgroundCam.transform.rotation = cam.transform.rotation;
backgroundCam.transform.position = cam.transform.position;
Matrix4x4 projectionMatrix2 = cam.projectionMatrix;
float angle3 = adjustReflPos;
float angle4 = adjustReflPos2;
float num13 = adjustReflPos3;
float num14 = cam.transform.eulerAngles.x;
if (num14 > 180f)
{
num14 = 0f - (360f - num14);
}
num13 = (0f - num14) / 6f;
if (backgroundCam.nearClipPlane == 1f)
{
angle3 = 0f - adjustReflPos;
angle4 = 0f - adjustReflPos2;
num13 = 0f - num13;
}
Matrix4x4 matrix4x5 = Matrix4x4.Rotate(Quaternion.AngleAxis(angle3, Vector3.up));
Matrix4x4 matrix4x6 = Matrix4x4.Rotate(Quaternion.AngleAxis(num13, Vector3.forward));
backgroundCam.projectionMatrix = projectionMatrix2 * matrix4x5 * matrix4x6;
Matrix4x4 matrix4x7 = Matrix4x4.Rotate(Quaternion.AngleAxis(angle4, Vector3.up));
Matrix4x4 matrix4x8 = cam.cameraToWorldMatrix * matrix4x7 * matrix4x6;
backgroundCam.worldToCameraMatrix = matrix4x8.inverse;
}
else if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component5 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component5.WaterTileBeingRenderedA(base.transform, cam, 0);
backgroundCam.nearClipPlane = 1f;
}
}
if (isForReflections)
{
}
}
else
{
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component6 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component6.WaterTileBeingRenderedA(base.transform, cam, 1);
backgroundCam.nearClipPlane = 2f;
}
}
_ = isForReflections;
}
backgroundCam.transform.position = Camera.main.transform.position;
backgroundCam.worldToCameraMatrix = Camera.main.worldToCameraMatrix;
backgroundCam.projectionMatrix = Camera.main.projectionMatrix;
backgroundCam.transform.rotation = Camera.main.transform.parent.rotation;
}
else
{
backgroundCam.transform.rotation = cam.transform.rotation;
backgroundCam.transform.position = cam.transform.position;
backgroundCam.worldToCameraMatrix = Camera.main.worldToCameraMatrix;
backgroundCam.projectionMatrix = Camera.main.projectionMatrix;
}
if (unity2018 && (backgroundCam.targetTexture == null || backgroundCam.targetTexture.width != Screen.width || backgroundCam.targetTexture.height != Screen.height))
{
backgroundCam.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
}
RenderTexture temporary = RenderTexture.GetTemporary(backgroundCam.targetTexture.width, backgroundCam.targetTexture.height, 0, backgroundCam.targetTexture.format);
if (isForReflections)
{
backgroundCam.transform.eulerAngles = new Vector3(backgroundCam.transform.eulerAngles.x, backgroundCam.transform.eulerAngles.y, 180f);
SkyManager.setMoonShader(backgroundCam.transform, 0.5f);
backgroundCam.Render();
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
tmpBufferL.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, temporary, fogMaterial, 6);
Graphics.Blit(temporary, tmpBufferL);
}
else
{
tmpBufferR.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, temporary, fogMaterial, 6);
Graphics.Blit(temporary, tmpBufferR);
}
}
else
{
tmpBuffer.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, temporary, fogMaterial, 6);
Graphics.Blit(temporary, tmpBuffer);
}
SkyManager.setMoonShader(Camera.main.transform, 1f);
}
else
{
backgroundCam.Render();
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
tmpBufferL.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, temporary, backgroundMat);
Graphics.Blit(temporary, tmpBufferL);
}
else
{
RenderTexture.active = tmpBufferR;
Graphics.Blit(backgroundCam.targetTexture, temporary, backgroundMat);
Graphics.Blit(temporary, tmpBufferR);
}
}
else
{
tmpBuffer.DiscardContents();
Graphics.Blit(backgroundCam.targetTexture, temporary, backgroundMat);
Graphics.Blit(temporary, tmpBuffer);
}
}
RenderTexture.ReleaseTemporary(temporary);
}
else if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component7 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component7.WaterTileBeingRenderedA(base.transform, cam, 0);
}
}
}
else if (SkyManager != null && SkyManager.water != null)
{
PlanarReflectionSM component8 = SkyManager.water.GetComponent<PlanarReflectionSM>();
if (Camera.current != null && Camera.main != null && Camera.current == Camera.main)
{
component8.WaterTileBeingRenderedA(base.transform, cam, 1);
}
}
}
if (cam.stereoEnabled)
{
if (cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left)
{
CustomGraphicsBlitOpt(source, destination, tmpBufferL, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, 0);
destination.DiscardContents();
tmpBufferL.DiscardContents();
CustomGraphicsBlitOpt(source, destination, tmpBufferL, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, 0);
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBufferR, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, 1);
destination.DiscardContents();
tmpBufferR.DiscardContents();
CustomGraphicsBlitOpt(source, destination, tmpBufferR, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, 1);
}
}
else
{
CustomGraphicsBlitOpt(source, destination, tmpBuffer, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, -1);
destination.DiscardContents();
tmpBuffer.DiscardContents();
CustomGraphicsBlitOpt(source, destination, tmpBuffer, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, -1);
}
}
}
else
{
CustomGraphicsBlitOpt(source, destination, null, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: true, splitPerFrame: false, WebGL, -1);
CustomGraphicsBlitOpt(source, destination, null, fogMaterial, num7, DistGradient, GradientBounds, colourPalette, texture3Dnoise1, texture3Dnoise2, cam, toggle: false, splitPerFrame: false, WebGL, -1);
}
if (adjustVR)
{
cam.transform.position = prevCenterPos;
}
}
private static void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr, Gradient DistGradient, Vector2 GradientBounds, Texture2D colourPalette, Texture3D tex3D1, Texture3D tex3D2, Camera cam, bool WebGL)
{
RenderTexture.active = dest;
fxMaterial.SetTexture("_MainTex", source);
fxMaterial.SetTexture("_NoiseTex1", tex3D1);
fxMaterial.SetTexture("_NoiseTex2", tex3D2);
int num = 1;
if (WebGL)
{
num = -1;
}
Camera camera = cam;
if (Camera.main != null)
{
camera = Camera.main;
}
fxMaterial.SetMatrix("_WorldClip", cam.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(1f, num, -1f)) * camera.projectionMatrix.inverse * Matrix4x4.Scale(new Vector3(-1f, 1f, 1f)));
fxMaterial.SetTexture("_ColorRamp", colourPalette);
if (GradientBounds != Vector2.zero)
{
fxMaterial.SetFloat("_Close", GradientBounds.x);
fxMaterial.SetFloat("_Far", GradientBounds.y);
}
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 RenderTexture CreateBuffer()
{
RenderTextureDescriptor desc;
if (XRSettings.enabled)
{
desc = XRSettings.eyeTextureDesc;
desc.width = 1280 / downScaleFactor;
desc.height = 720 / downScaleFactor;
}
else
{
desc = new RenderTextureDescriptor(1280 / downScaleFactor, 720 / downScaleFactor, RenderTextureFormat.ARGB32, 0);
}
return new RenderTexture(desc)
{
filterMode = FilterMode.Bilinear,
wrapMode = TextureWrapMode.Repeat
};
}
private void ResetResources()
{
if ((bool)_cloudBuffer)
{
UnityEngine.Object.DestroyImmediate(_cloudBuffer);
}
_cloudBuffer = CreateBuffer();
if ((bool)_cloudBufferP)
{
UnityEngine.Object.DestroyImmediate(_cloudBufferP);
}
_cloudBufferP = CreateBuffer();
if ((bool)_cloudBufferP1)
{
UnityEngine.Object.DestroyImmediate(_cloudBufferP1);
}
_cloudBufferP1 = CreateBuffer();
if ((bool)tmpCloudBufferL)
{
UnityEngine.Object.DestroyImmediate(tmpCloudBufferL);
}
tmpCloudBufferL = CreateBuffer();
if ((bool)tmpCloudBufferR)
{
UnityEngine.Object.DestroyImmediate(tmpCloudBufferR);
}
tmpCloudBufferR = CreateBuffer();
if ((bool)new1)
{
UnityEngine.Object.DestroyImmediate(new1);
}
new1 = CreateBuffer();
_needsReset = false;
}
private void LateUpdate()
{
if (_needsReset)
{
ResetResources();
}
}
private void Reset()
{
_needsReset = true;
}
private void CustomGraphicsBlitOpt(RenderTexture source, RenderTexture dest, RenderTexture skysource, Material fxMaterial, int passNr, Gradient DistGradient, Vector2 GradientBounds, Texture2D colourPalette, Texture3D tex3D1, Texture3D tex3D2, Camera cam, bool toggle, bool splitPerFrame, bool WebGL, int eye)
{
if (!fastest)
{
fxMaterial.SetInt("_fastest", 0);
}
else
{
fxMaterial.SetInt("_fastest", 1);
}
if (toggle)
{
if (enableReproject || countCameraSteady > 1)
{
Graphics.Blit(new1, _cloudBufferP);
}
if (!fastest)
{
fxMaterial.SetTexture("_SkyTex", skysource);
}
fxMaterial.SetTexture("_CloudTex", _cloudBuffer);
if (new1 == null)
{
new1 = CreateBuffer();
}
RenderTexture.active = new1;
fxMaterial.SetTexture("_MainTex", null);
fxMaterial.SetTexture("_NoiseTex1", tex3D1);
fxMaterial.SetTexture("_NoiseTex2", tex3D2);
int num = 1;
if (WebGL)
{
num = -1;
}
Camera camera = cam;
if (Camera.main != null)
{
camera = Camera.main;
}
Matrix4x4 value = cam.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(1f, num, -1f)) * camera.projectionMatrix.inverse * Matrix4x4.Scale(new Vector3(-1f, 1f, 1f));
fxMaterial.SetMatrix("_WorldClip", value);
fxMaterial.SetTexture("_ColorRamp", colourPalette);
if (GradientBounds != Vector2.zero)
{
fxMaterial.SetFloat("_Close", GradientBounds.x);
fxMaterial.SetFloat("_Far", GradientBounds.y);
}
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();
Graphics.Blit(new1, _cloudBuffer);
if (eye == 0)
{
Graphics.Blit(new1, tmpCloudBufferL);
}
if (eye == 1)
{
Graphics.Blit(new1, tmpCloudBufferR);
}
prevCameraRotP = cam.transform.eulerAngles;
return;
}
fxMaterial.SetTexture("_MainTex", source);
if (!fastest)
{
fxMaterial.SetTexture("_SkyTex", skysource);
}
if (splitPerFrames > 0 && enableReproject && Application.isPlaying)
{
if (splitPerFrame)
{
fxMaterial.SetTexture("_CloudTex", _cloudBufferP1);
}
else if (autoReproject)
{
if (autoReproject && enableReproject && countCameraSteady > 2)
{
fxMaterial.SetTexture("_CloudTex", _cloudBufferP1);
}
else
{
fxMaterial.SetTexture("_CloudTex", _cloudBuffer);
}
}
else
{
fxMaterial.SetTexture("_CloudTex", _cloudBufferP1);
}
}
else
{
fxMaterial.SetTexture("_CloudTex", _cloudBuffer);
if (eye == 0)
{
fxMaterial.SetTexture("_CloudTex", tmpCloudBufferL);
}
if (eye == 1)
{
fxMaterial.SetTexture("_CloudTex", tmpCloudBufferR);
}
}
RenderTexture.active = dest;
int num2 = 1;
if (WebGL)
{
num2 = -1;
}
Camera camera2 = cam;
if (Camera.main != null)
{
camera2 = Camera.main;
}
Matrix4x4 value2 = cam.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(2f, num2, -1f)) * camera2.projectionMatrix.inverse * Matrix4x4.Scale(new Vector3(-1f, 1f, 1f));
if (splitPerFrame)
{
float num3 = cam.transform.eulerAngles.y - prevCameraRot.y;
float num4 = 0f - (cam.transform.eulerAngles.x - prevCameraRot.x);
if (eye == 0)
{
num3 = cam.transform.eulerAngles.y - prevCameraRotL.y;
num4 = 0f - (cam.transform.eulerAngles.x - prevCameraRotL.x);
}
if (eye == 1)
{
num3 = cam.transform.eulerAngles.y - prevCameraRotR.y;
num4 = 0f - (cam.transform.eulerAngles.x - prevCameraRotR.x);
}
if (autoReproject)
{
if (Mathf.Abs(num3) == 0f && Mathf.Abs(num4) == 0f)
{
if (countCameraSteady > 8)
{
enableReproject = true;
}
else
{
countCameraSteady++;
}
}
else if (toggleCounter == 1 && countCameraSteady > 0)
{
enableReproject = false;
countCameraSteady = 0;
}
}
if (num3 > 122f || num3 < -122f)
{
num3 = 0f;
}
if (num4 > 122f || num4 < -122f)
{
num4 = 0f;
}
value2[0, 3] = 0.009f * num3;
value2[1, 3] = 0.012f * num4;
value2[2, 3] = 1f;
}
else
{
prevCameraRot = cam.transform.eulerAngles;
if (eye == 0)
{
prevCameraRotL = cam.transform.eulerAngles;
}
if (eye == 1)
{
prevCameraRotR = cam.transform.eulerAngles;
}
}
fxMaterial.SetMatrix("_WorldClip", value2);
GL.PushMatrix();
GL.LoadOrtho();
if (splitPerFrame && cameraMotionCompensate)
{
fxMaterial.SetPass(4);
}
else
{
fxMaterial.SetPass(3);
}
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();
}
}
}