Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Hadal Laboratories v0.1.1
EndCape.dll
Decompiled 4 months agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using DunGen; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("EndCape")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("A template for Lethal Company")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("EndCape")] [assembly: AssemblyTitle("EndCape")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EndCape { public static class PluginInfo { public const string PLUGIN_GUID = "EndCape"; public const string PLUGIN_NAME = "EndCape"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace EndCapeScript { public class EndCapSpawner : MonoBehaviour, IDungeonCompleteReceiver { [Serializable] public class EndCapOption { public Collider[] placementColliders; public GameObject prefab; } private static Collider[] hits = (Collider[])(object)new Collider[50]; public Tile parentTile; public EndCapOption[] options; public GameObject fallback; private Span<Collider> CheckCollider(Collider collider) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) CapsuleCollider val = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null); if (val != null) { Vector3 val2 = ((Component)this).transform.position + new Vector3(0f, val.height / 2f) + val.center; Vector3 val3 = ((Component)this).transform.position - new Vector3(0f, val.height / 2f) + val.center; int num = Physics.OverlapCapsuleNonAlloc(val2, val3, val.radius, hits, 256, (QueryTriggerInteraction)1); return hits[..num]; } SphereCollider val4 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null); if (val4 != null) { int num2 = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, val4.radius, hits, 256, (QueryTriggerInteraction)1); return hits[..num2]; } return Span<Collider>.Empty; } private bool ShouldCollidersBlockPlacement(Span<Collider> colliders) { Span<Collider> span = colliders; for (int i = 0; i < span.Length; i++) { Collider val = span[i]; if (!((Object)(object)((Component)val).GetComponentInParent<Tile>() == (Object)(object)parentTile)) { return true; } } return false; } public void OnDungeonComplete(Dungeon dungeon) { EndCapOption[] array = options; foreach (EndCapOption endCapOption in array) { bool flag = true; Collider[] placementColliders = endCapOption.placementColliders; foreach (Collider collider in placementColliders) { Span<Collider> colliders = CheckCollider(collider); if (ShouldCollidersBlockPlacement(colliders)) { flag = false; break; } } if (flag) { SpawnPrefab(endCapOption.prefab); return; } } SpawnPrefab(fallback); } private void SpawnPrefab(GameObject prefab) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(prefab, ((Component)this).transform); val.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); } } }
TolianWaterSystem.dll
Decompiled 4 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using System.Threading.Tasks; using BepInEx; using Microsoft.CodeAnalysis; using Unity.Collections; using UnityEditor; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.Video; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TolianWaterSystem")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("A template for Lethal Company")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+646ca23083ece7cd6b0810d9c33b0fdcd17eeab1")] [assembly: AssemblyProduct("TolianWaterSystem")] [assembly: AssemblyTitle("TolianWaterSystem")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public class FFT_CPU : MonoBehaviour { public enum SizeSetting { Size_32 = 0x20, Size_64 = 0x40, Size_128 = 0x80 } public class OutputFFTData { public Color[] OutputPixels; } public bool IsDetailed; public SizeSetting Size = SizeSetting.Size_64; [Range(0f, 1f)] public float WindDirection = 0.3f; [Range(0.2f, 10f)] public float WindSpeed = 5f; [Range(0.25f, 1.5f)] public float Choppines = 0.85f; [Range(1f, 100f)] public float WaterScale = 10f; [Range(0f, 2f)] public float TimeScale = 1f; public Texture2D DisplaceTexture; public RenderTexture NormalTexture; public Material WaterMaterial; private const float DomainSize = 20f; private float prevWindDirection; private float prevWindSpeed; private int prevSize; private FFT_CPU_Spectrum spectrumCpu; private OutputFFTData outputFftData; private FFT_CPU_Simulation fftCpu1; private FFT_CPU_Simulation fftCpu2; private FFT_CPU_Simulation fftCpu3; private Vector2[] butterflyRawData; private Material normalComputeMaterial; private Thread t0; private Thread t1; private Thread t2; private Thread t3; private float currentTime; private bool canUpdate = true; private bool isDoneComputeFFT_1; private bool isDoneComputeFFT_2; private bool isDoneComputeFFT_3; private AutoResetEvent[] startHandle; private void InitializeResources() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown isDoneComputeFFT_1 = false; isDoneComputeFFT_2 = false; isDoneComputeFFT_3 = false; canUpdate = true; outputFftData = new OutputFFTData(); fftCpu1 = new FFT_CPU_Simulation((int)Size, outputFftData); fftCpu2 = new FFT_CPU_Simulation((int)Size, outputFftData); fftCpu3 = new FFT_CPU_Simulation((int)Size, outputFftData); prevSize = (int)Size; prevWindDirection = WindDirection; prevWindSpeed = WindSpeed; normalComputeMaterial = new Material(WaterShadersSingleton.Instance.ComputeNormalShader); if ((Object)(object)NormalTexture != (Object)null) { NormalTexture.Release(); } NormalTexture = new RenderTexture((int)Size, (int)Size, 0, (RenderTextureFormat)2, (RenderTextureReadWrite)1); ((Texture)NormalTexture).filterMode = (FilterMode)1; ((Texture)NormalTexture).wrapMode = (TextureWrapMode)0; if ((Object)(object)DisplaceTexture != (Object)null) { Object.DestroyImmediate((Object)(object)DisplaceTexture); } DisplaceTexture = new Texture2D((int)Size, (int)Size, (TextureFormat)17, false, true); InitializeButterfly((int)Size); spectrumCpu = new FFT_CPU_Spectrum((int)Size); spectrumCpu.InitializeSpectrum(20f, WindSpeed, WindDirection, (int)Size); if (startHandle == null) { startHandle = new AutoResetEvent[4]; startHandle[0] = new AutoResetEvent(initialState: true); startHandle[1] = new AutoResetEvent(initialState: false); startHandle[2] = new AutoResetEvent(initialState: false); startHandle[3] = new AutoResetEvent(initialState: false); } } private void InitializeButterfly(int size) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.RoundToInt(Mathf.Log((float)size, 2f)); butterflyRawData = (Vector2[])(object)new Vector2[size * num]; int num2 = 1; int num3 = size >> 1; for (int i = 0; i < num; i++) { int num4 = i * size; int num5 = 0; int num6 = 2 * num2; for (int j = 0; j < num3; j++) { float num7 = 0f; for (int k = num5; k < num6; k += 2) { float num8 = MathF.PI * 2f * num7 * (float)num3 / (float)size; float num9 = Mathf.Cos(num8); float num10 = Mathf.Sin(num8); butterflyRawData[num4 + k / 2] = new Vector2(num9, 0f - num10); butterflyRawData[num4 + k / 2 + num2] = new Vector2(0f - num9, num10); num7 += 1f; } num5 += 4 * num2; num6 = num5 + 2 * num2; } num3 >>= 1; num2 <<= 1; } } private void StartThreads() { if (startHandle != null) { startHandle[0].Set(); } if (t0 == null) { t0 = new Thread(thread0); t0.Start(); } if (t1 == null) { t1 = new Thread(thread1); t1.Start(); } if (t2 == null) { t2 = new Thread(thread2); t2.Start(); } if (t3 == null) { t3 = new Thread(thread3); t3.Start(); } } private void RestartCompute() { ReleaseAll(); InitializeResources(); StartThreads(); } private void ReleaseAll() { canUpdate = false; if (t0 != null) { t0.Abort(); } t0 = null; if (t1 != null) { t1.Abort(); } t1 = null; if (t2 != null) { t2.Abort(); } t2 = null; if (t3 != null) { t3.Abort(); } t3 = null; if ((Object)(object)DisplaceTexture != (Object)null) { Object.DestroyImmediate((Object)(object)DisplaceTexture); } if ((Object)(object)NormalTexture != (Object)null) { NormalTexture.Release(); } if (IsDetailed) { Shader.DisableKeyword("KW_DETAIL_FFT"); } } private void thread0() { while (canUpdate) { startHandle[0].WaitOne(); isDoneComputeFFT_1 = false; isDoneComputeFFT_2 = false; isDoneComputeFFT_3 = false; spectrumCpu.GetUpdatedSpectrum(currentTime, (int)Size); startHandle[1].Set(); startHandle[2].Set(); startHandle[3].Set(); } } private void thread1() { while (canUpdate) { startHandle[1].WaitOne(); fftCpu1.Compute(spectrumCpu.ResultDisplaceZ, butterflyRawData, 0, (int)Size); isDoneComputeFFT_1 = true; } } private void thread2() { while (canUpdate) { startHandle[2].WaitOne(); fftCpu2.Compute(spectrumCpu.ResultHeight, butterflyRawData, 1, (int)Size); isDoneComputeFFT_2 = true; } } private void thread3() { while (canUpdate) { startHandle[3].WaitOne(); fftCpu3.Compute(spectrumCpu.ResultDisplaceX, butterflyRawData, 2, (int)Size); isDoneComputeFFT_3 = true; } } private void ReadThreadsData() { if (isDoneComputeFFT_1 && isDoneComputeFFT_2 && isDoneComputeFFT_3) { DisplaceTexture.SetPixels(outputFftData.OutputPixels); DisplaceTexture.Apply(); normalComputeMaterial.SetTexture("_DispTex", (Texture)(object)DisplaceTexture); int num = Mathf.RoundToInt(Mathf.Log((float)Size, 2f)) - 4; normalComputeMaterial.SetFloat("_SizeLog", (float)num); normalComputeMaterial.SetFloat("_Choppines", Choppines); normalComputeMaterial.SetFloat("_WindSpeed", WindSpeed); NormalTexture.DiscardContents(); RenderTexture active = RenderTexture.active; if (!Application.isPlaying) { RenderTexture.active = null; } Graphics.Blit((Texture)null, NormalTexture, normalComputeMaterial); if (!Application.isPlaying) { RenderTexture.active = active; } startHandle[0].Set(); } } private void UpdateFFT() { //IL_043e: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) if (prevSize != (int)Size) { prevSize = (int)Size; RestartCompute(); } else if (Mathf.Abs(prevWindDirection - WindDirection) > 0.001f || Mathf.Abs(prevWindSpeed - WindSpeed) > 0.01f) { prevWindDirection = WindDirection; prevWindSpeed = WindSpeed; spectrumCpu.InitializeSpectrum(20f, WindSpeed, WindDirection, (int)Size); } currentTime += Time.deltaTime * Mathf.Lerp(TimeScale, TimeScale * 0.5f, WaterScale / 100f); ReadThreadsData(); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(WaterScale * Choppines / 20f, 1f, WaterScale * Choppines / 20f); if (!IsDetailed) { if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalTexture("KW_DispTex", (Texture)(object)DisplaceTexture); } else { WaterMaterial.SetTexture("KW_DispTex", (Texture)(object)DisplaceTexture); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalTexture("KW_NormTex", (Texture)(object)NormalTexture); } else { WaterMaterial.SetTexture("KW_NormTex", (Texture)(object)NormalTexture); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_WindSpeed", WindSpeed); } else { WaterMaterial.SetFloat("KW_WindSpeed", WindSpeed); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_Choppines", Choppines); } else { WaterMaterial.SetFloat("KW_Choppines", Choppines); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_FFTScale", WaterScale); } else { WaterMaterial.SetFloat("KW_FFTScale", WaterScale); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalVector("KW_DisplaceScale", Vector4.op_Implicit(val)); } else { WaterMaterial.SetVector("KW_DisplaceScale", Vector4.op_Implicit(val)); } int num = Mathf.RoundToInt(Mathf.Log((float)Size, 2f)) - 5; if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_NormalLod", (float)num); } else { WaterMaterial.SetFloat("KW_NormalLod", (float)num); } return; } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalTexture("KW_DispTexDetail", (Texture)(object)DisplaceTexture); } else { WaterMaterial.SetTexture("KW_DispTexDetail", (Texture)(object)DisplaceTexture); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalTexture("KW_NormTexDetail", (Texture)(object)NormalTexture); } else { WaterMaterial.SetTexture("KW_NormTexDetail", (Texture)(object)NormalTexture); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_WindSpeedDetail", WindSpeed); } else { WaterMaterial.SetFloat("KW_WindSpeedDetail", WindSpeed); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_ChoppinesDetail", Choppines); } else { WaterMaterial.SetFloat("KW_ChoppinesDetail", Choppines); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_FFTScaleDetail", WaterScale); } else { WaterMaterial.SetFloat("KW_FFTScaleDetail", WaterScale); } if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalVector("KW_DisplaceScaleDetail", Vector4.op_Implicit(val)); } else { WaterMaterial.SetVector("KW_DisplaceScaleDetail", Vector4.op_Implicit(val)); } int num2 = Mathf.RoundToInt(Mathf.Log((float)Size, 2f)) - 5; if ((Object)(object)WaterMaterial == (Object)null) { Shader.SetGlobalFloat("KW_NormalLodDetail", (float)num2); } else { WaterMaterial.SetFloat("KW_NormalLodDetail", (float)num2); } Shader.EnableKeyword("KW_DETAIL_FFT"); } private void OnEnable() { RestartCompute(); } private void OnDisable() { ReleaseAll(); } private void OnDestroy() { ReleaseAll(); } private void Update() { UpdateFFT(); } } public class FFT_CPU_Simulation { private struct ButterflyHashProperties { public int x; public int y; public bool pingPong; public int index; public ButterflyHashProperties(int X, int Y, bool Pingpong, int Index) { x = X; y = Y; pingPong = Pingpong; index = Index; } } private Vector2[] input_H; private Vector2[] complex_H; private Vector2[] intermediates_H; private Vector2[] scratch_H; private Vector2[] inpButt; private bool firstThreadDone; private bool secondThreadDone; private int passes; private int size; private ButterflyHashProperties[,] hashFunction; private FFT_CPU.OutputFFTData currentBuffer; public FFT_CPU_Simulation(int Size, FFT_CPU.OutputFFTData outputFftData) { currentBuffer = outputFftData; Initialize(Size); } private void Initialize(int Size) { size = Size; passes = Mathf.RoundToInt(Mathf.Log((float)size, 2f)); intermediates_H = (Vector2[])(object)new Vector2[size]; scratch_H = (Vector2[])(object)new Vector2[size]; complex_H = (Vector2[])(object)new Vector2[size * size]; hashFunction = new ButterflyHashProperties[size, passes]; for (int i = 0; i < size; i++) { for (int j = 0; j < passes; j++) { hashFunction[i, j] = ButteflyHashFunction(i, j); } } if (currentBuffer.OutputPixels == null || currentBuffer.OutputPixels.Length != size * size) { currentBuffer.OutputPixels = (Color[])(object)new Color[size * size]; } } public void Compute(Vector2[] inpHeight, Vector2[] inpButterfly, int colorChannel, int currentSize) { if (currentSize != size) { Initialize(currentSize); } input_H = inpHeight; inpButt = inpButterfly; FFT_H(); FFT_V(colorChannel); } private void FFT_H() { bool flag = passes % 2 == 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { int num = i * size + j; intermediates_H[j].x = input_H[num].x; intermediates_H[j].y = 0f - input_H[num].y; } for (int k = 0; k < passes; k++) { for (int l = 0; l < size; l++) { ButterflyHashProperties butterflyHashProperties = hashFunction[l, k]; if (butterflyHashProperties.pingPong) { scratch_H[l].x = inpButt[butterflyHashProperties.index].x * intermediates_H[butterflyHashProperties.y].x - inpButt[butterflyHashProperties.index].y * intermediates_H[butterflyHashProperties.y].y + intermediates_H[butterflyHashProperties.x].x; scratch_H[l].y = inpButt[butterflyHashProperties.index].y * intermediates_H[butterflyHashProperties.y].x + inpButt[butterflyHashProperties.index].x * intermediates_H[butterflyHashProperties.y].y + intermediates_H[butterflyHashProperties.x].y; } else { intermediates_H[l].x = inpButt[butterflyHashProperties.index].x * scratch_H[butterflyHashProperties.y].x - inpButt[butterflyHashProperties.index].y * scratch_H[butterflyHashProperties.y].y + scratch_H[butterflyHashProperties.x].x; intermediates_H[l].y = inpButt[butterflyHashProperties.index].y * scratch_H[butterflyHashProperties.y].x + inpButt[butterflyHashProperties.index].x * scratch_H[butterflyHashProperties.y].y + scratch_H[butterflyHashProperties.x].y; } } } for (int m = 0; m < size; m++) { int num = i * size + m; if (flag) { complex_H[num].x = intermediates_H[m].x; complex_H[num].y = intermediates_H[m].y; } else { complex_H[num].x = scratch_H[m].x; complex_H[num].y = scratch_H[m].y; } } } } private void FFT_V(int colorChannel) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) bool flag = passes % 2 == 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { intermediates_H[j] = complex_H[j * size + i]; } for (int k = 0; k < passes; k++) { for (int l = 0; l < size; l++) { ButterflyHashProperties butterflyHashProperties = hashFunction[l, k]; if (butterflyHashProperties.pingPong) { scratch_H[l].x = inpButt[butterflyHashProperties.index].x * intermediates_H[butterflyHashProperties.y].x - inpButt[butterflyHashProperties.index].y * intermediates_H[butterflyHashProperties.y].y + intermediates_H[butterflyHashProperties.x].x; scratch_H[l].y = inpButt[butterflyHashProperties.index].y * intermediates_H[butterflyHashProperties.y].x + inpButt[butterflyHashProperties.index].x * intermediates_H[butterflyHashProperties.y].y + intermediates_H[butterflyHashProperties.x].y; } else { intermediates_H[l].x = inpButt[butterflyHashProperties.index].x * scratch_H[butterflyHashProperties.y].x - inpButt[butterflyHashProperties.index].y * scratch_H[butterflyHashProperties.y].y + scratch_H[butterflyHashProperties.x].x; intermediates_H[l].y = inpButt[butterflyHashProperties.index].y * scratch_H[butterflyHashProperties.y].x + inpButt[butterflyHashProperties.index].x * scratch_H[butterflyHashProperties.y].y + scratch_H[butterflyHashProperties.x].y; } } } for (int m = 0; m < size; m++) { Vector2 val = (flag ? intermediates_H[m] : scratch_H[m]); float num = (((i + m) % 2 == 1) ? (-1f) : 1f); switch (colorChannel) { case 0: currentBuffer.OutputPixels[m * size + i].r = num * val.x; break; case 1: currentBuffer.OutputPixels[m * size + i].g = num * val.x; break; case 2: currentBuffer.OutputPixels[m * size + i].b = num * val.x; break; } } } } private ButterflyHashProperties ButteflyHashFunction(int coord, int passIndex) { int num = 1 << passIndex; int num2; int num3; if (coord / num % 2 == 1) { num2 = coord - num; num3 = coord; } else { num2 = coord; num3 = coord + num; } if (passIndex == 0) { num2 = (int)(Reverse(num2) >> 32 - passes); num3 = (int)(Reverse(num3) >> 32 - passes); } bool pingpong = passIndex % 2 == 0; int index = coord + passIndex * size; return new ButterflyHashProperties(num2, num3, pingpong, index); } private uint Reverse(int x1) { uint num = (uint)x1; uint num2 = 0u; for (int i = 0; i < 32; i++) { num2 <<= 1; num2 |= num & 1u; num >>= 1; } return num2; } } public class FFT_CPU_Spectrum { private struct UpdateSpectrumHashProperties { public float k_x; public float k_y; public float w; public int index; } private UpdateSpectrumHashProperties[,] hashFunc; private float[] sinHash; private float[] cosHash; private Vector4[] initColors; public Vector2[] ResultHeight; public Vector2[] ResultDisplaceX; public Vector2[] ResultDisplaceZ; private float INVPI2 = 2f / MathF.PI; private float HPI = MathF.PI / 2f; private float PI2 = MathF.PI * 2f; private float PI4 = 0.33661976f; private int rngState; private const float Gravity = 9.81f; private int size; private UpdateSpectrumHashProperties hash; private float scaledTime; private int index; private float hX; private float hY; private float sw; private float cw; public FFT_CPU_Spectrum(int Size) { Initialize(Size); } private void Initialize(int Size) { size = Size; sinHash = new float[6284]; cosHash = new float[6284]; for (int i = 0; i < 6284; i++) { sinHash[i] = Mathf.Sin((float)i / 100f); cosHash[i] = Mathf.Cos((float)i / 100f); } initColors = (Vector4[])(object)new Vector4[size * size]; ResultHeight = (Vector2[])(object)new Vector2[size * size]; ResultDisplaceX = (Vector2[])(object)new Vector2[size * size]; ResultDisplaceZ = (Vector2[])(object)new Vector2[size * size]; } public void InitializeSpectrum(float domainSize, float windSpeed, float direction, int currentSize) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) if (size != currentSize) { Initialize(currentSize); } for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { int num = size / 2; int num2 = i - num; int num3 = j - num; if (num2 != 0 || num3 != 0) { float num4 = PI2 * (float)num2 / domainSize; float num5 = PI2 * (float)num3 / domainSize; Vector2 val = new Vector2(num4, num5); float magnitude = ((Vector2)(ref val)).magnitude; rngState = WangHash(j * size + i); float num6 = Mathf.Sqrt(Mathf.Abs(9.81f * magnitude)); float num7 = 9.81f / (2f * num6); float num8 = PiersonMoskowitzSpectrum(num6, windSpeed); float num9 = num8; float num10 = num8; float num11 = PI2 / domainSize; float theta = Mathf.Atan2(0f - num5, num4); float theta2 = Mathf.Atan2(num5, 0f - num4); num9 *= PosCosSquaredDirectionalSpreading(theta, direction); num10 *= PosCosSquaredDirectionalSpreading(theta2, direction); num9 *= num11 * num11 * num7 / magnitude; num10 *= num11 * num11 * num7 / magnitude; float num12 = RandGauss() * Mathf.Sqrt(Mathf.Abs(num9) * 2f); float num13 = RandGauss() * Mathf.Sqrt(Mathf.Abs(num10) * 2f); float num14 = RandFloat() * PI2; float num15 = RandFloat() * PI2; float num16 = num12 * Mathf.Cos(num14); float num17 = num12 * (0f - Mathf.Sin(num14)); float num18 = num13 * Mathf.Cos(num15); float num19 = num13 * (0f - Mathf.Sin(num15)); initColors[j * size + i] = new Vector4(num16, num17, num18, num19); } } } hashFunc = new UpdateSpectrumHashProperties[size, size]; for (int k = 0; k < size; k++) { for (int l = 0; l < size; l++) { hashFunc[k, l] = UpdateHashFunc(k, l, domainSize); } } } public void GetUpdatedSpectrum(float time, int currentSize) { scaledTime = time / 10f; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { hash = hashFunc[i, j]; index = (int)(hash.w * scaledTime % PI2 * 1000f); sw = sinHash[index]; cw = cosHash[index]; index = hash.index; hX = initColors[index].x * cw - initColors[index].y * (0f - sw) + initColors[index].z * cw - initColors[index].w * sw; hY = initColors[index].x * (0f - sw) + initColors[index].y * cw + initColors[index].z * sw + initColors[index].w * cw; ResultHeight[index].x = hX; ResultHeight[index].y = hY; ResultDisplaceX[index].x = (0f - hY) * hash.k_x; ResultDisplaceX[index].y = hX * hash.k_x; ResultDisplaceZ[index].x = (0f - hY) * hash.k_y; ResultDisplaceZ[index].y = hX * hash.k_y; } } } private int WangHash(int seed) { seed = seed ^ 0x3D ^ (seed >> 16); seed *= 9; seed ^= seed >> 4; seed *= 668265261; seed ^= seed >> 15; return seed; } private int Rand() { rngState ^= rngState << 13; rngState ^= rngState >> 17; rngState ^= rngState << 5; return Mathf.Abs(rngState); } private float RandFloat() { return (float)Rand() / 4.2949673E+09f; } private float RandGauss() { float num = RandFloat(); float num2 = RandFloat(); if (num < 1E-06f) { num = 1E-06f; } return Mathf.Sqrt(-2f * Mathf.Log(num)) * Mathf.Cos(PI2 * num2); } private float PiersonMoskowitzSpectrum(float w, float windSpeed) { float wm = 8.5347f / windSpeed; return AlphaBetaSpectrum(0.0081f, 1.291f, 9.81f, w, wm); } private float AlphaBetaSpectrum(float A, float B, float g, float w, float wm) { return A * g * g / Mathf.Pow(w, 5f) * Mathf.Exp((0f - B) * Mathf.Pow(wm / w, 4f)); } private float PosCosSquaredDirectionalSpreading(float theta, float direction) { if (theta > 0f - HPI && theta < HPI) { float num = Mathf.Cos(theta); return INVPI2 * (num * num) * (1f - direction) + PI4 * direction; } return PI4 * direction; } private UpdateSpectrumHashProperties UpdateHashFunc(int x, int y, float domainSize) { int num = size / 2; int num2 = x - num; int num3 = y - num; float num4 = PI2 * (float)num2 / domainSize; float num5 = PI2 * (float)num3 / domainSize; float num6 = Mathf.Sqrt(num4 * num4 + num5 * num5); float w = Mathf.Sqrt(Mathf.Abs(9.81f * num6)); num6 += 1E-05f; num4 /= num6; num5 /= num6; int num7 = x * size + y; UpdateSpectrumHashProperties result = default(UpdateSpectrumHashProperties); result.index = num7; result.k_x = num4; result.k_y = num5; result.w = w; return result; } } public class FFT_GPU : MonoBehaviour { public enum SizeSetting { Size_32 = 0x20, Size_64 = 0x40, Size_128 = 0x80, Size_256 = 0x100, Size_512 = 0x200 } public enum LodPrefix { LOD0, LOD1, LOD2 } public RenderTexture DisplaceTexture; public RenderTexture NormalTexture; private RenderTexture spectrumInitRenderTexture; private RenderTexture spectrumHeight; private RenderTexture spectrumDisplaceX; private RenderTexture spectrumDisplaceZ; private RenderTexture fftTemp1; private RenderTexture fftTemp2; private RenderTexture fftTemp3; private Material normalComputeMaterial; private ComputeShader spectrumShader; private ComputeShader shaderFFT; private Texture2D texButterfly; private float prevWindTurbulence; private float prevWindSpeed; private float prevWindRotation; private float currentHeightDataDomainScale; private int kernelSpectrumInit; private int kernelSpectrumUpdate; private Color[] butterflyColors; private bool isInitialized = false; private int ID_DispTex = Shader.PropertyToID("KW_DispTex"); private int ID_DispTex1 = Shader.PropertyToID("KW_DispTex_LOD1"); private int ID_DispTex2 = Shader.PropertyToID("KW_DispTex_LOD2"); private int ID_NormTex = Shader.PropertyToID("KW_NormTex"); private int ID_LeanTex = Shader.PropertyToID("KW_LeanTex"); private int ID_NormTex1 = Shader.PropertyToID("KW_NormTex_LOD1"); private int ID_NormTex2 = Shader.PropertyToID("KW_NormTex_LOD2"); private int ID_MipCount = Shader.PropertyToID("KW_NormMipCount"); private int ID_MipCount1 = Shader.PropertyToID("KW_NormMipCount_LOD1"); private int ID_MipCount2 = Shader.PropertyToID("KW_NormMipCount_LOD2"); private int ID_FFTDomainSize = Shader.PropertyToID("KW_FFTDomainSize"); private int ID_FFTDomainSize1 = Shader.PropertyToID("KW_FFTDomainSize_LOD1"); private int ID_FFTDomainSize2 = Shader.PropertyToID("KW_FFTDomainSize_LOD2"); private int ID_NormalLod = Shader.PropertyToID("KW_NormalLod"); public void Release() { KW_Extensions.SafeDestroy((Object)spectrumShader, (Object)shaderFFT, (Object)texButterfly, (Object)normalComputeMaterial); KW_Extensions.ReleaseRenderTextures(spectrumInitRenderTexture, spectrumHeight, spectrumDisplaceX, spectrumDisplaceZ, fftTemp1, fftTemp2, fftTemp3, DisplaceTexture, NormalTexture); prevWindTurbulence = -1f; prevWindSpeed = -1f; prevWindRotation = -1f; isInitialized = false; } private void InitializeResources(int size, int anisoLevel) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Expected O, but got Unknown //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Expected O, but got Unknown //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown Release(); spectrumShader = Object.Instantiate<ComputeShader>(WaterShadersSingleton.Instance.SpectrumGPUComputeShader); kernelSpectrumInit = spectrumShader.FindKernel("SpectrumInitalize"); kernelSpectrumUpdate = spectrumShader.FindKernel("SpectrumUpdate"); shaderFFT = Object.Instantiate<ComputeShader>(WaterShadersSingleton.Instance.FFTComputeShader); normalComputeMaterial = new Material(WaterShadersSingleton.Instance.ComputeNormalShader); texButterfly = new Texture2D(size, Mathf.RoundToInt(Mathf.Log((float)size, 2f)), (TextureFormat)20, false, true); spectrumInitRenderTexture = new RenderTexture(size, size, 0, (RenderTextureFormat)11, (RenderTextureReadWrite)1); spectrumInitRenderTexture.enableRandomWrite = true; spectrumInitRenderTexture.Create(); spectrumHeight = new RenderTexture(size, size, 0, (RenderTextureFormat)12, (RenderTextureReadWrite)1); spectrumHeight.enableRandomWrite = true; spectrumHeight.Create(); spectrumDisplaceX = new RenderTexture(size, size, 0, (RenderTextureFormat)12, (RenderTextureReadWrite)1); spectrumDisplaceX.enableRandomWrite = true; spectrumDisplaceX.Create(); spectrumDisplaceZ = new RenderTexture(size, size, 0, (RenderTextureFormat)12, (RenderTextureReadWrite)1); spectrumDisplaceZ.enableRandomWrite = true; spectrumDisplaceZ.Create(); fftTemp1 = new RenderTexture(size, size, 0, (RenderTextureFormat)12); fftTemp1.enableRandomWrite = true; fftTemp1.Create(); fftTemp2 = new RenderTexture(size, size, 0, (RenderTextureFormat)12); fftTemp2.enableRandomWrite = true; fftTemp2.Create(); fftTemp3 = new RenderTexture(size, size, 0, (RenderTextureFormat)12); fftTemp3.enableRandomWrite = true; fftTemp3.Create(); DisplaceTexture = new RenderTexture(size, size, 0, (RenderTextureFormat)11, (RenderTextureReadWrite)1); DisplaceTexture.enableRandomWrite = true; DisplaceTexture.Create(); NormalTexture = new RenderTexture(size, size, 0, (RenderTextureFormat)2, (RenderTextureReadWrite)1); ((Texture)NormalTexture).filterMode = (FilterMode)2; ((Texture)NormalTexture).wrapMode = (TextureWrapMode)0; NormalTexture.useMipMap = true; ((Texture)NormalTexture).anisoLevel = anisoLevel; InitializeButterfly(size); isInitialized = true; } private void OnDisable() { Release(); } public void ComputeFFT(LodPrefix lodPrefix, int size, int anisoLevel, float domainSize, float windTurbulence, float windSpeed, float windRotation, float timeOffset, List<Material> waterSharedMaterials, Dictionary<ComputeShader, List<int>> waterSharedComputeShaders) { if (!isInitialized || ((Texture)DisplaceTexture).width != size || ((Texture)NormalTexture).anisoLevel != anisoLevel) { InitializeResources(size, anisoLevel); } if (Mathf.Abs(prevWindTurbulence - windTurbulence) > 0.001f || Mathf.Abs(prevWindSpeed - windSpeed) > 0.01f || Mathf.Abs(prevWindRotation - windRotation) > 0.01f) { prevWindTurbulence = windTurbulence; prevWindSpeed = windSpeed; prevWindRotation = windRotation; InitializeSpectrum(size, domainSize, windSpeed, windTurbulence, windRotation); } UpdateSpectrum(size, timeOffset, windRotation); DispatchFFT(size, domainSize, windSpeed); int num = Mathf.RoundToInt(Mathf.Log((float)size, 2f)) - 4; int num2 = Mathf.RoundToInt(Mathf.Log((float)size, 2f)); foreach (Material waterSharedMaterial in waterSharedMaterials) { if (!((Object)(object)waterSharedMaterial == (Object)null)) { UpdateMaterialParameters(lodPrefix, num, domainSize, num2, waterSharedMaterial); } } foreach (KeyValuePair<ComputeShader, List<int>> waterSharedComputeShader in waterSharedComputeShaders) { if (!((Object)(object)waterSharedComputeShader.Key == (Object)null)) { UpdateComputeParameters(lodPrefix, num, domainSize, num2, waterSharedComputeShader.Key, waterSharedComputeShader.Value); } } } private void UpdateMaterialParameters(LodPrefix lodPrefix, float normalLodSize, float domainSize, float mipCount, Material material) { switch (lodPrefix) { case LodPrefix.LOD0: material.SetTexture(ID_DispTex, (Texture)(object)DisplaceTexture); material.SetTexture(ID_NormTex, (Texture)(object)NormalTexture); material.SetFloat(ID_FFTDomainSize, domainSize); material.SetFloat(ID_NormalLod, normalLodSize); material.SetFloat(ID_MipCount, mipCount); break; case LodPrefix.LOD1: material.SetTexture(ID_DispTex1, (Texture)(object)DisplaceTexture); material.SetTexture(ID_NormTex1, (Texture)(object)NormalTexture); material.SetFloat(ID_FFTDomainSize1, domainSize); material.SetFloat(ID_MipCount1, mipCount); break; case LodPrefix.LOD2: material.SetTexture(ID_DispTex2, (Texture)(object)DisplaceTexture); material.SetTexture(ID_NormTex2, (Texture)(object)NormalTexture); material.SetFloat(ID_FFTDomainSize2, domainSize); material.SetFloat(ID_MipCount2, mipCount); break; } } private void UpdateComputeParameters(LodPrefix lodPrefix, float normalLodSize, float domainSize, float mipCount, ComputeShader computeShader, List<int> kernels) { foreach (int kernel in kernels) { switch (lodPrefix) { case LodPrefix.LOD0: computeShader.SetTexture(kernel, ID_DispTex, (Texture)(object)DisplaceTexture); computeShader.SetTexture(kernel, ID_NormTex, (Texture)(object)NormalTexture); computeShader.SetFloat(ID_FFTDomainSize, domainSize); computeShader.SetFloat(ID_NormalLod, normalLodSize); computeShader.SetFloat(ID_MipCount, mipCount); break; case LodPrefix.LOD1: computeShader.SetTexture(kernel, ID_DispTex1, (Texture)(object)DisplaceTexture); computeShader.SetTexture(kernel, ID_NormTex1, (Texture)(object)NormalTexture); computeShader.SetFloat(ID_FFTDomainSize1, domainSize); computeShader.SetFloat(ID_MipCount1, mipCount); break; case LodPrefix.LOD2: computeShader.SetTexture(kernel, ID_DispTex2, (Texture)(object)DisplaceTexture); computeShader.SetTexture(kernel, ID_NormTex2, (Texture)(object)NormalTexture); computeShader.SetFloat(ID_FFTDomainSize2, domainSize); computeShader.SetFloat(ID_MipCount2, mipCount); break; } } } private void InitializeButterfly(int size) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.RoundToInt(Mathf.Log((float)size, 2f)); butterflyColors = (Color[])(object)new Color[size * num]; int num2 = 1; int num3 = size >> 1; for (int i = 0; i < num; i++) { int num4 = i * size; int num5 = 0; int num6 = 2 * num2; for (int j = 0; j < num3; j++) { float num7 = 0f; for (int k = num5; k < num6; k += 2) { float num8 = MathF.PI * 2f * num7 * (float)num3 / (float)size; float num9 = Mathf.Cos(num8); float num10 = Mathf.Sin(num8); butterflyColors[num4 + k / 2] = new Color(num9, 0f - num10, 0f, 1f); butterflyColors[num4 + k / 2 + num2] = new Color(0f - num9, num10, 0f, 1f); num7 += 1f; } num5 += 4 * num2; num6 = num5 + 2 * num2; } num3 >>= 1; num2 <<= 1; } texButterfly.SetPixels(butterflyColors); texButterfly.Apply(); } private void InitializeSpectrum(int size, float domainSize, float windSpeed, float windTurbulence, float windRotation) { Graphics.SetRenderTarget(spectrumInitRenderTexture); spectrumShader.SetInt("size", size); spectrumShader.SetFloat("domainSize", domainSize); spectrumShader.SetFloats("turbulence", new float[1] { windTurbulence }); spectrumShader.SetFloat("windSpeed", windSpeed); spectrumShader.SetFloat("windRotation", windRotation); spectrumShader.SetTexture(kernelSpectrumInit, "resultInit", (Texture)(object)spectrumInitRenderTexture); spectrumShader.Dispatch(kernelSpectrumInit, size / 8, size / 8, 1); } private void UpdateSpectrum(int size, float timeOffset, float windRotation) { Graphics.SetRenderTarget(spectrumHeight); spectrumShader.SetFloat("time", timeOffset); spectrumShader.SetTexture(kernelSpectrumUpdate, "init0", (Texture)(object)spectrumInitRenderTexture); spectrumShader.SetTexture(kernelSpectrumUpdate, "resultHeight", (Texture)(object)spectrumHeight); spectrumShader.SetTexture(kernelSpectrumUpdate, "resultDisplaceX", (Texture)(object)spectrumDisplaceX); spectrumShader.SetTexture(kernelSpectrumUpdate, "resultDisplaceZ", (Texture)(object)spectrumDisplaceZ); spectrumShader.Dispatch(kernelSpectrumUpdate, size / 8, size / 8, 1); } private void DispatchFFT(int size, float domainSize, float windSpeed) { RenderTexture active = RenderTexture.active; int num = 0; switch (size) { case 32: num = 0; break; case 64: num = 2; break; case 128: num = 4; break; case 256: num = 6; break; case 512: num = 8; break; } Graphics.SetRenderTarget(fftTemp1); shaderFFT.SetTexture(num, "inputH", (Texture)(object)spectrumHeight); shaderFFT.SetTexture(num, "inputX", (Texture)(object)spectrumDisplaceX); shaderFFT.SetTexture(num, "inputZ", (Texture)(object)spectrumDisplaceZ); shaderFFT.SetTexture(num, "inputButterfly", (Texture)(object)texButterfly); shaderFFT.SetTexture(num, "output1", (Texture)(object)fftTemp1); shaderFFT.SetTexture(num, "output2", (Texture)(object)fftTemp2); shaderFFT.SetTexture(num, "output3", (Texture)(object)fftTemp3); shaderFFT.Dispatch(num, 1, size, 1); Graphics.SetRenderTarget(DisplaceTexture); shaderFFT.SetTexture(num + 1, "inputH", (Texture)(object)fftTemp1); shaderFFT.SetTexture(num + 1, "inputX", (Texture)(object)fftTemp2); shaderFFT.SetTexture(num + 1, "inputZ", (Texture)(object)fftTemp3); shaderFFT.SetTexture(num + 1, "inputButterfly", (Texture)(object)texButterfly); shaderFFT.SetTexture(num + 1, "output", (Texture)(object)DisplaceTexture); shaderFFT.Dispatch(num + 1, size, 1, 1); normalComputeMaterial.SetFloat("KW_FFTDomainSize", domainSize); normalComputeMaterial.SetTexture("_DispTex", (Texture)(object)DisplaceTexture); int num2 = Mathf.RoundToInt(Mathf.Log((float)size, 2f)) - 4; normalComputeMaterial.SetFloat("_SizeLog", (float)num2); normalComputeMaterial.SetFloat("_WindSpeed", windSpeed); Graphics.SetRenderTarget(NormalTexture); Graphics.Blit((Texture)null, NormalTexture, normalComputeMaterial, 0); RenderTexture.active = active; } } [ExecuteInEditMode] public class KW_AddLightToWaterRendering : MonoBehaviour { private Light currentLight; private LightType lastLightType; private LightShadows lastLightShadows; private Color lastLightColor; private float lastLightRange; private float lastLightIntencity; private float lastSpotLightAngle; private Vector3 lastLightPos; private Vector3 lastLightDir; private static readonly int KW_DirLightForward_ID = Shader.PropertyToID("KW_DirLightForward"); private static readonly int KW_DirLightColor_ID = Shader.PropertyToID("KW_DirLightColor"); private KW_WaterVolumetricLighting.VolumeLight currentVolumeLight; private void OnEnable() { if ((Object)(object)currentLight == (Object)null) { currentLight = ((Component)this).GetComponent<Light>(); } if (currentVolumeLight == null) { currentVolumeLight = new KW_WaterVolumetricLighting.VolumeLight(); } currentVolumeLight.Light = currentLight; currentVolumeLight.RequiredUpdate = true; KW_WaterVolumetricLighting.ActiveLights.Add(currentVolumeLight); } private void OnDisable() { KW_WaterVolumetricLighting.ActiveLights.Remove(currentVolumeLight); if (currentVolumeLight.CopyShadowMapBuffer != null) { currentLight.RemoveCommandBuffer((LightEvent)1, currentVolumeLight.CopyShadowMapBuffer); } if (currentVolumeLight.LightCommandBuffer != null) { currentVolumeLight.Light.RemoveCommandBuffer((LightEvent)2, currentVolumeLight.LightCommandBuffer); currentVolumeLight.Light.RemoveCommandBuffer((LightEvent)1, currentVolumeLight.LightCommandBuffer); } } private bool IsRequiredLightUpdate() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) bool result = false; Transform transform = ((Component)currentLight).transform; if (lastLightType != currentLight.type || lastLightShadows != currentLight.shadows || lastLightColor != currentLight.color || Math.Abs(lastLightIntencity - currentLight.intensity) > 0.001f || Math.Abs(lastLightRange - currentLight.range) > 0.001f || Math.Abs(lastSpotLightAngle - currentLight.spotAngle) > 0.001f || lastLightPos != transform.position || lastLightDir != transform.forward) { result = true; } lastLightType = currentLight.type; lastLightShadows = currentLight.shadows; lastLightColor = currentLight.color; lastLightIntencity = currentLight.intensity; lastLightRange = currentLight.range; lastLightPos = transform.position; lastLightDir = transform.forward; return result; } private void Update() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Invalid comparison between Unknown and I4 if ((int)currentLight.type == 0) { ComputeSpotLightShadowMatrix(); } if ((int)currentLight.type == 1) { UpdateDirLight(); } if (IsRequiredLightUpdate()) { currentVolumeLight.RequiredUpdate = true; } } private void UpdateDirLight() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) Shader.SetGlobalVector(KW_DirLightForward_ID, Vector4.op_Implicit(-((Component)currentLight).transform.forward)); Shader.SetGlobalVector(KW_DirLightColor_ID, Color.op_Implicit(currentLight.color * currentLight.intensity)); } private void ComputeSpotLightShadowMatrix() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) Matrix4x4 val = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f)); Matrix4x4 val2 = ((!SystemInfo.usesReversedZBuffer) ? Matrix4x4.Perspective(currentLight.spotAngle, 1f, currentLight.shadowNearPlane, currentLight.range) : Matrix4x4.Perspective(currentLight.spotAngle, 1f, currentLight.range, currentLight.shadowNearPlane)); Matrix4x4 val3 = val * val2; ref Matrix4x4 reference = ref val3; ((Matrix4x4)(ref reference))[0, 2] = ((Matrix4x4)(ref reference))[0, 2] * -1f; reference = ref val3; ((Matrix4x4)(ref reference))[1, 2] = ((Matrix4x4)(ref reference))[1, 2] * -1f; reference = ref val3; ((Matrix4x4)(ref reference))[2, 2] = ((Matrix4x4)(ref reference))[2, 2] * -1f; reference = ref val3; ((Matrix4x4)(ref reference))[3, 2] = ((Matrix4x4)(ref reference))[3, 2] * -1f; Matrix4x4 val4 = Matrix4x4.TRS(((Component)currentLight).transform.position, ((Component)currentLight).transform.rotation, Vector3.one); Matrix4x4 inverse = ((Matrix4x4)(ref val4)).inverse; currentVolumeLight.SpotMatrix = val3 * inverse; } } [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(Collider))] public class KW_Buoyancy : MonoBehaviour { public enum ModelSourceEnum { Collider, Mesh } public ModelSourceEnum VolumeSource = ModelSourceEnum.Mesh; public Transform OvverideCenterOfMass; [Range(100f, 1000f)] public float Density = 450f; [Range(1f, 6f)] public int SlicesPerAxisX = 2; [Range(1f, 6f)] public int SlicesPerAxisY = 2; [Range(1f, 6f)] public int SlicesPerAxisZ = 2; public bool isConcave = false; [Range(2f, 32f)] public int VoxelsLimit = 16; public float AngularDrag = 0.25f; public float Drag = 0.25f; [Range(0f, 1f)] public float NormalForce = 0.2f; public bool DebugForces = false; private const float DAMPFER = 0.1f; private const float WATER_DENSITY = 1000f; private Vector3 localArchimedesForce; private List<Vector3> voxels; private Vector3[] currentForces; private bool isMeshCollider; private List<Vector3[]> debugForces; private Rigidbody rigidBody; private Collider collider; private float bounceMaxSize; private void OnEnable() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) KW_WaterDynamicScripts.AddBuoyancyScript(this); debugForces = new List<Vector3[]>(); rigidBody = ((Component)this).GetComponent<Rigidbody>(); collider = ((Component)this).GetComponent<Collider>(); Quaternion rotation = ((Component)this).transform.rotation; Vector3 position = ((Component)this).transform.position; ((Component)this).transform.rotation = Quaternion.identity; ((Component)this).transform.position = Vector3.zero; Bounds bounds = collider.bounds; bounceMaxSize = Mathf.Max(new float[3] { ((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z }); isMeshCollider = (Object)(object)((Component)this).GetComponent<MeshCollider>() != (Object)null; if (Object.op_Implicit((Object)(object)OvverideCenterOfMass)) { rigidBody.centerOfMass = ((Component)this).transform.InverseTransformPoint(((Component)OvverideCenterOfMass).transform.position); } rigidBody.angularDrag = AngularDrag; rigidBody.drag = Drag; voxels = SliceIntoVoxels(isMeshCollider && isConcave); currentForces = (Vector3[])(object)new Vector3[voxels.Count]; ((Component)this).transform.rotation = rotation; ((Component)this).transform.position = position; float num = rigidBody.mass / Density; WeldPoints(voxels, VoxelsLimit); float num2 = 1000f * Mathf.Abs(Physics.gravity.y) * num; localArchimedesForce = new Vector3(0f, num2, 0f) / (float)voxels.Count; } private void OnDisable() { KW_WaterDynamicScripts.RemoveBuoyancyScript(this); } private Bounds GetCurrentBounds() { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) Bounds result = default(Bounds); if (VolumeSource == ModelSourceEnum.Mesh) { return ((Component)this).GetComponent<Renderer>().bounds; } if (VolumeSource == ModelSourceEnum.Collider) { MeshCollider component = ((Component)this).GetComponent<MeshCollider>(); if ((Object)(object)component != (Object)null) { return component.sharedMesh.bounds; } return ((Component)this).GetComponent<Collider>().bounds; } return result; } private List<Vector3> SliceIntoVoxels(bool concave) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(SlicesPerAxisX * SlicesPerAxisY * SlicesPerAxisZ); Bounds currentBounds = GetCurrentBounds(); if (concave) { MeshCollider component = ((Component)this).GetComponent<MeshCollider>(); bool convex = component.convex; component.convex = false; for (int i = 0; i < SlicesPerAxisX; i++) { for (int j = 0; j < SlicesPerAxisY; j++) { for (int k = 0; k < SlicesPerAxisZ; k++) { float num = ((Bounds)(ref currentBounds)).min.x + ((Bounds)(ref currentBounds)).size.x / (float)SlicesPerAxisX * (0.5f + (float)i); float num2 = ((Bounds)(ref currentBounds)).min.y + ((Bounds)(ref currentBounds)).size.y / (float)SlicesPerAxisY * (0.5f + (float)j); float num3 = ((Bounds)(ref currentBounds)).min.z + ((Bounds)(ref currentBounds)).size.z / (float)SlicesPerAxisZ * (0.5f + (float)k); Vector3 val = ((Component)this).transform.InverseTransformPoint(new Vector3(num, num2, num3)); if (PointIsInsideMeshCollider((Collider)(object)component, val)) { list.Add(val); } } } } if (list.Count == 0) { list.Add(((Bounds)(ref currentBounds)).center); } component.convex = convex; } else { for (int l = 0; l < SlicesPerAxisX; l++) { for (int m = 0; m < SlicesPerAxisY; m++) { for (int n = 0; n < SlicesPerAxisZ; n++) { float num4 = ((Bounds)(ref currentBounds)).min.x + ((Bounds)(ref currentBounds)).size.x / (float)SlicesPerAxisX * (0.5f + (float)l); float num5 = ((Bounds)(ref currentBounds)).min.y + ((Bounds)(ref currentBounds)).size.y / (float)SlicesPerAxisY * (0.5f + (float)m); float num6 = ((Bounds)(ref currentBounds)).min.z + ((Bounds)(ref currentBounds)).size.z / (float)SlicesPerAxisZ * (0.5f + (float)n); Vector3 item = ((Component)this).transform.InverseTransformPoint(new Vector3(num4, num5, num6)); list.Add(item); } } } } return list; } private static bool PointIsInsideMeshCollider(Collider c, Vector3 p) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[6] { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back }; Vector3[] array2 = array; RaycastHit val2 = default(RaycastHit); foreach (Vector3 val in array2) { if (!c.Raycast(new Ray(p - val * 1000f, val), ref val2, 1000f)) { return false; } } return true; } private static void FindClosestPoints(IList<Vector3> list, out int firstIndex, out int secondIndex) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; float num2 = float.MinValue; firstIndex = 0; secondIndex = 1; for (int i = 0; i < list.Count - 1; i++) { for (int j = i + 1; j < list.Count; j++) { float num3 = Vector3.Distance(list[i], list[j]); if (num3 < num) { num = num3; firstIndex = i; secondIndex = j; } if (num3 > num2) { num2 = num3; } } } } private static void WeldPoints(IList<Vector3> list, int targetCount) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (list.Count > 2 && targetCount >= 2) { while (list.Count > targetCount) { FindClosestPoints(list, out var firstIndex, out var secondIndex); Vector3 item = (list[firstIndex] + list[secondIndex]) * 0.5f; list.RemoveAt(secondIndex); list.RemoveAt(firstIndex); list.Add(item); } } } private void FixedUpdate() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) WaterSystem currentWater = KW_WaterDynamicScripts.GetCurrentWater(); if ((Object)(object)currentWater == (Object)null) { return; } if (DebugForces) { debugForces.Clear(); } for (int i = 0; i < voxels.Count; i++) { Vector3 val = ((Component)this).transform.TransformPoint(voxels[i]); KW_WaterSurfaceData? waterSurfacePositionNormal = currentWater.GetWaterSurfacePositionNormal(val); Vector3 zero = Vector3.zero; if (waterSurfacePositionNormal.HasValue) { Vector3 position = waterSurfacePositionNormal.Value.Position; Vector3 pointVelocity = rigidBody.GetPointVelocity(val); Vector3 val2 = -pointVelocity * 0.1f * rigidBody.mass; float num = position.y - val.y; if (num > 1f) { num = 1f; } else if (num < 0f) { num = 0f; val2 *= 0.2f; } zero = val2 + Mathf.Sqrt(num) * localArchimedesForce; Vector3 normal = waterSurfacePositionNormal.Value.Normal; zero.x += normal.x * NormalForce * rigidBody.mass; zero.z += normal.z * NormalForce * rigidBody.mass; currentForces[i] = zero; } else { zero = currentForces[i]; } rigidBody.AddForceAtPosition(zero, val); if (DebugForces) { debugForces.Add((Vector3[])(object)new Vector3[2] { val, zero }); } } } private void OnDrawGizmos() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) if (!DebugForces || voxels == null || debugForces == null) { return; } float num = 0.02f * bounceMaxSize; Gizmos.color = Color.yellow; foreach (Vector3 voxel in voxels) { Gizmos.DrawCube(((Component)this).transform.TransformPoint(voxel), new Vector3(num, num, num)); } Gizmos.color = Color.cyan; foreach (Vector3[] debugForce in debugForces) { Gizmos.DrawCube(debugForce[0], new Vector3(num, num, num)); Gizmos.DrawRay(debugForce[0], debugForce[1] / rigidBody.mass * bounceMaxSize * 0.25f); } } } public class KW_CameraColorTexture : MonoBehaviour { public RenderTexture CameraColorTexture; public RenderTexture CameraColorTexture_Blured; public RenderTexture CameraColorTextureFinal; private string cb_Name = "CopyColorTexture"; private string cbFinal_Name = "CopyColorTextureFinal"; private CommandBuffer cb; private CommandBuffer cbFinal; private void OnDisable() { if ((Object)(object)CameraColorTexture != (Object)null) { CameraColorTexture.Release(); } if ((Object)(object)CameraColorTexture_Blured != (Object)null) { CameraColorTexture_Blured.Release(); } if ((Object)(object)CameraColorTextureFinal != (Object)null) { CameraColorTextureFinal.Release(); } } public void Release() { OnDisable(); } private void InitializeTextures(int width, int height, bool useHDR) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown if ((Object)(object)CameraColorTexture != (Object)null) { CameraColorTexture.Release(); } CameraColorTexture = new RenderTexture(width, height, 0, (RenderTextureFormat)(useHDR ? 9 : 7)); if ((Object)(object)CameraColorTexture_Blured != (Object)null) { CameraColorTexture_Blured.Release(); } CameraColorTexture_Blured = new RenderTexture(width, height, 0, (RenderTextureFormat)(useHDR ? 9 : 7)); } private void InitializeFinalTextures(int width, int height, bool useHDR) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)CameraColorTextureFinal != (Object)null) { CameraColorTextureFinal.Release(); } CameraColorTextureFinal = new RenderTexture(width, height, 0, (RenderTextureFormat)(useHDR ? 9 : 7)); Debug.Log((object)CameraColorTextureFinal.format); } public void RenderColorTexture(Camera currentCamera, bool useHDR, bool isScreenSpaceWaterRendering, Dictionary<CommandBuffer, CameraEvent> waterSharedBuffers) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) if (cb == null || !waterSharedBuffers.ContainsKey(cb)) { if (cb == null) { cb = new CommandBuffer { name = cb_Name }; } else { cb.Clear(); } int pixelWidth = currentCamera.pixelWidth; int pixelHeight = currentCamera.pixelHeight; InitializeTextures(pixelWidth, pixelHeight, useHDR); cb.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)1), RenderTargetIdentifier.op_Implicit((Texture)(object)CameraColorTexture)); cb.SetGlobalTexture("_CameraColorTexture", RenderTargetIdentifier.op_Implicit((Texture)(object)CameraColorTexture)); waterSharedBuffers.Add(cb, (CameraEvent)(isScreenSpaceWaterRendering ? 17 : 16)); } } public void RenderColorTextureFinal(Camera currentCamera, bool useHDR, Dictionary<CommandBuffer, CameraEvent> waterSharedBuffers) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) if (cbFinal == null || !waterSharedBuffers.ContainsKey(cbFinal)) { if (cbFinal == null) { cbFinal = new CommandBuffer { name = cbFinal_Name }; } else { cbFinal.Clear(); } int pixelWidth = currentCamera.pixelWidth; int pixelHeight = currentCamera.pixelHeight; InitializeFinalTextures(pixelWidth, pixelHeight, useHDR); cbFinal.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)1), RenderTargetIdentifier.op_Implicit((Texture)(object)CameraColorTextureFinal)); cbFinal.SetGlobalTexture("_CameraColorTextureFinal", RenderTargetIdentifier.op_Implicit((Texture)(object)CameraColorTextureFinal)); waterSharedBuffers.Add(cbFinal, (CameraEvent)19); } } } public class KW_CameraReflection_HDRP : MonoBehaviour { private class PlanarReflectionSettingData { private readonly bool _fog; private readonly int _maxLod; private readonly float _lodBias; public PlanarReflectionSettingData() { _fog = RenderSettings.fog; _maxLod = QualitySettings.maximumLODLevel; _lodBias = QualitySettings.lodBias; } public void Set() { RenderSettings.fog = false; QualitySettings.maximumLODLevel += 1; QualitySettings.lodBias = _lodBias * 0.5f; } public void Restore() { RenderSettings.fog = _fog; QualitySettings.maximumLODLevel = _maxLod; QualitySettings.lodBias = _lodBias; } } private GameObject reflCameraGO; private Camera reflectionCamera; public RenderTexture reflectionRT; public RenderTexture reflectionCubemapRT; public float m_ClipPlaneOffset = -0.05f; public float m_planeOffset = -0.05f; private float currentInterval = 0f; private int sideIdx = 0; private int[] cubeMapSides = new int[5] { 0, 1, 2, 4, 5 }; private bool requiredUpdateAllFaces = true; private int waterCullingMask = -17; private HDAdditionalCameraData hdData; private bool lastSkyFix; public void Release() { KW_Extensions.SafeDestroy((Object)reflCameraGO); KW_Extensions.ReleaseRenderTextures(reflectionRT, reflectionCubemapRT); currentInterval = 0f; requiredUpdateAllFaces = true; } private void OnDisable() { Release(); } private void InitializeReflectionTexture(int width, int height, bool useMip) { reflectionRT = KW_Extensions.ReinitializeRenderTexture(reflectionRT, width, height, 24, (RenderTextureFormat)9, null, useRandomWrite: false, useMip, (TextureWrapMode)0, (FilterMode)1); } private void InitializeCubemapTexture(int width, int height) { reflectionCubemapRT = KW_Extensions.ReinitializeRenderTexture(reflectionCubemapRT, width, height, 0, (RenderTextureFormat)2, null, useRandomWrite: false, useMipMap: false, (TextureWrapMode)0, (FilterMode)1); ((Texture)reflectionCubemapRT).dimension = (TextureDimension)4; } private void CreateCamera() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown reflCameraGO = new GameObject("WaterReflectionCamera"); reflCameraGO.transform.parent = ((Component)this).transform; reflectionCamera = reflCameraGO.AddComponent<Camera>(); reflectionCamera.cameraType = (CameraType)16; ((Behaviour)reflectionCamera).enabled = false; reflectionCamera.allowMSAA = false; reflectionCamera.useOcclusionCulling = false; hdData = reflCameraGO.AddComponent<HDAdditionalCameraData>(); } private void CopyCameraParams(Camera currentCamera, int cullingMask) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) ((Component)reflectionCamera).transform.position = ((Component)currentCamera).transform.position; ((Component)reflectionCamera).transform.rotation = ((Component)currentCamera).transform.rotation; reflectionCamera.fieldOfView = currentCamera.fieldOfView; reflectionCamera.nearClipPlane = currentCamera.nearClipPlane; reflectionCamera.farClipPlane = currentCamera.farClipPlane; reflectionCamera.rect = currentCamera.rect; reflectionCamera.aspect = currentCamera.aspect; reflectionCamera.orthographicSize = currentCamera.orthographicSize; reflectionCamera.renderingPath = currentCamera.renderingPath; reflectionCamera.allowDynamicResolution = currentCamera.allowDynamicResolution; reflectionCamera.cullingMask = cullingMask; reflectionCamera.clearFlags = currentCamera.clearFlags; reflectionCamera.backgroundColor = currentCamera.backgroundColor; if (currentCamera.usePhysicalProperties) { reflectionCamera.usePhysicalProperties = true; reflectionCamera.focalLength = currentCamera.focalLength; reflectionCamera.sensorSize = currentCamera.sensorSize; reflectionCamera.lensShift = currentCamera.lensShift; reflectionCamera.gateFit = currentCamera.gateFit; } hdData.defaultFrameSettings = (FrameSettingsRenderType)2; hdData.customRenderingSettings = true; hdData.hasPersistentHistory = true; hdData.invertFaceCulling = true; } private void RenderCamera(Camera currentCamera, Vector3 waterPosition, Matrix4x4 cameraMatrix) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) Vector3 val = waterPosition + Vector3.up * m_planeOffset; Vector3 up = Vector3.up; float num = 0f - Vector3.Dot(up, val) - m_ClipPlaneOffset; Vector4 plane = default(Vector4); ((Vector4)(ref plane))..ctor(up.x, up.y, up.z, num); Matrix4x4 reflectionMat = Matrix4x4.identity; reflectionMat *= Matrix4x4.Scale(new Vector3(1f, -1f, 1f)); CalculateReflectionMatrix(ref reflectionMat, plane); ((Component)reflectionCamera).transform.forward = Vector3.Scale(((Component)currentCamera).transform.forward, new Vector3(1f, -1f, 1f)); Vector3 position = ((Component)currentCamera).transform.position; ((Component)reflectionCamera).transform.position = ((Matrix4x4)(ref reflectionMat)).MultiplyPoint(position); reflectionCamera.worldToCameraMatrix = cameraMatrix * reflectionMat; Vector4 val2 = CameraSpacePlane(reflectionCamera, val - Vector3.up * 0.1f, up, 1f); Matrix4x4 projectionMatrix = reflectionCamera.CalculateObliqueMatrix(val2); reflectionCamera.projectionMatrix = projectionMatrix; PlanarReflectionSettingData planarReflectionSettingData = new PlanarReflectionSettingData(); planarReflectionSettingData.Set(); try { reflectionCamera.targetTexture = reflectionRT; KW_Extensions.CameraRender(reflectionCamera); } finally { planarReflectionSettingData.Restore(); } } public void RenderPlanar(Camera currentCamera, Vector3 waterPosition, float resolutionScale, bool useSkyFix, List<Material> waterShaderMaterials) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)currentCamera == (Object)null) { return; } if ((Object)(object)reflCameraGO == (Object)null) { CreateCamera(); } CopyCameraParams(currentCamera, waterCullingMask); UseSkyFix(currentCamera, useSkyFix); int width = (int)((float)currentCamera.pixelWidth * resolutionScale); int height = (int)((float)currentCamera.pixelHeight * resolutionScale); InitializeReflectionTexture(width, height, useMip: true); RenderCamera(currentCamera, waterPosition, currentCamera.worldToCameraMatrix); foreach (Material waterShaderMaterial in waterShaderMaterials) { if (!((Object)(object)waterShaderMaterial == (Object)null)) { waterShaderMaterial.SetTexture("KW_PlanarReflection", (Texture)(object)reflectionRT); } } } public void RenderCubemap(Camera currentCamera, Vector3 waterPosition, float interval, int cullingMask, int texSize, bool useSkyFix, List<Material> waterShaderMaterials) { //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)currentCamera == (Object)null) { return; } currentInterval += KW_Extensions.DeltaTime(); if (lastSkyFix != useSkyFix) { requiredUpdateAllFaces = true; } if (!requiredUpdateAllFaces && currentInterval < interval / 6f) { return; } currentInterval = 0f; if ((Object)(object)reflCameraGO == (Object)null) { CreateCamera(); } CopyCameraParams(currentCamera, cullingMask); UseSkyFix(currentCamera, useSkyFix); InitializeReflectionTexture(texSize, texSize, useMip: false); InitializeCubemapTexture(texSize, texSize); float fieldOfView = currentCamera.fieldOfView; float aspect = currentCamera.aspect; reflectionCamera.fieldOfView = 90f; reflectionCamera.aspect = 1f; m_planeOffset = 0f; m_ClipPlaneOffset = 0f; if (requiredUpdateAllFaces || interval < 0.0001f) { RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)1); RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)5); RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)0); RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)2); RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)4); } else { int num = cubeMapSides[sideIdx]; sideIdx = ((sideIdx < 4) ? (++sideIdx) : 0); RenderToCubemapFace(currentCamera, waterPosition, (CubemapFace)num); } requiredUpdateAllFaces = false; foreach (Material waterShaderMaterial in waterShaderMaterials) { if (!((Object)(object)waterShaderMaterial == (Object)null)) { waterShaderMaterial.SetTexture("KW_ReflectionCube", (Texture)(object)reflectionCubemapRT); } } } private void UseSkyFix(Camera currentCamera, bool useSkyFix) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (useSkyFix) { hdData.clearColorMode = (ClearColorMode)1; hdData.backgroundColorHDR = Color.black; hdData.SetCameraFrameSetting((FrameSettingsField)27, enabled: false); } else { HDAdditionalCameraData component = ((Component)currentCamera).GetComponent<HDAdditionalCameraData>(); if ((Object)(object)component != (Object)null) { hdData.clearColorMode = component.clearColorMode; hdData.backgroundColorHDR = component.backgroundColorHDR; } else { hdData.clearColorMode = (ClearColorMode)0; } hdData.SetCameraFrameSetting((FrameSettingsField)27, enabled: true); } lastSkyFix = useSkyFix; } private void RenderToCubemapFace(Camera currentCamera, Vector3 waterPosition, CubemapFace face) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected I4, but got Unknown Vector3 position = ((Component)currentCamera).transform.position; Matrix4x4 cameraMatrix = Matrix4x4.Inverse(Matrix4x4.TRS(position, GetRotationByCubeFace(face), new Vector3(1f, 1f, -1f))); RenderCamera(currentCamera, waterPosition, cameraMatrix); Graphics.CopyTexture((Texture)(object)reflectionRT, 0, (Texture)(object)reflectionCubemapRT, (int)face); } private Quaternion GetRotationByCubeFace(CubemapFace face) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected I4, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) return (Quaternion)((int)face switch { 1 => Quaternion.Euler(0f, -90f, 0f), 0 => Quaternion.Euler(0f, 90f, 0f), 2 => Quaternion.Euler(90f, 0f, 0f), 3 => Quaternion.Euler(-90f, 0f, 0f), 4 => Quaternion.Euler(0f, 0f, 0f), 5 => Quaternion.Euler(0f, -180f, 0f), _ => Quaternion.identity, }); } private static float sgn(float a) { if (a > 0f) { return 1f; } if (a < 0f) { return -1f; } return 0f; } private static Vector3 ReflectPosition(Vector3 pos) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Vector3 result = default(Vector3); ((Vector3)(ref result))..ctor(pos.x, 0f - pos.y, pos.z); return result; } private Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) Vector3 val = pos + normal * m_ClipPlaneOffset; Matrix4x4 worldToCameraMatrix = cam.worldToCameraMatrix; Vector3 val2 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyPoint(val); Vector3 val3 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyVector(normal); Vector3 val4 = ((Vector3)(ref val3)).normalized * sideSign; return new Vector4(val4.x, val4.y, val4.z, 0f - Vector3.Dot(val2, val4)); } private static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane) { reflectionMat.m00 = 1f - 2f * ((Vector4)(ref plane))[0] * ((Vector4)(ref plane))[0]; reflectionMat.m01 = -2f * ((Vector4)(ref plane))[0] * ((Vector4)(ref plane))[1]; reflectionMat.m02 = -2f * ((Vector4)(ref plane))[0] * ((Vector4)(ref plane))[2]; reflectionMat.m03 = -2f * ((Vector4)(ref plane))[3] * ((Vector4)(ref plane))[0]; reflectionMat.m10 = -2f * ((Vector4)(ref plane))[1] * ((Vector4)(ref plane))[0]; reflectionMat.m11 = 1f - 2f * ((Vector4)(ref plane))[1] * ((Vector4)(ref plane))[1]; reflectionMat.m12 = -2f * ((Vector4)(ref plane))[1] * ((Vector4)(ref plane))[2]; reflectionMat.m13 = -2f * ((Vector4)(ref plane))[3] * ((Vector4)(ref plane))[1]; reflectionMat.m20 = -2f * ((Vector4)(ref plane))[2] * ((Vector4)(ref plane))[0]; reflectionMat.m21 = -2f * ((Vector4)(ref plane))[2] * ((Vector4)(ref plane))[1]; reflectionMat.m22 = 1f - 2f * ((Vector4)(ref plane))[2] * ((Vector4)(ref plane))[2]; reflectionMat.m23 = -2f * ((Vector4)(ref plane))[3] * ((Vector4)(ref plane))[2]; reflectionMat.m30 = 0f; reflectionMat.m31 = 0f; reflectionMat.m32 = 0f; reflectionMat.m33 = 1f; } } public class KW_CausticDecal_CustomPass : CustomPass { private string profilerTag; private Mesh decalMesh; private Material causticDecalMaterial; protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { ((CustomPass)this).name = "Water.CausticDecalCustomPass"; } public void UpdateParams() { WaterSystem currentWater = KW_WaterDynamicScripts.GetCurrentWater(); if ((Object)(object)causticDecalMaterial == (Object)null) { causticDecalMaterial = KW_Extensions.CreateMaterial(WaterShadersSingleton.Instance.CausticDecalShader); } if (!currentWater.waterSharedMaterials.Contains(causticDecalMaterial)) { currentWater.waterSharedMaterials.Add(causticDecalMaterial); } } protected override void Execute(CustomPassContext ctx) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) Camera camera = ctx.hdCamera.camera; WaterSystem currentWater = KW_WaterDynamicScripts.GetCurrentWater(); if (KW_Extensions.IsCanExecuteCameraBuffers(camera, currentWater)) { CommandBuffer cmd = ctx.cmd; UpdateParams(); Vector3 position = ((Component)camera).transform.position; position.y = ((Component)currentWater).transform.position.y - 20f; float num = ((Vector4)(ref KW_CausticRendering.LodSettings))[currentWater.CausticActiveLods - 1] * 2f; Matrix4x4 val = Matrix4x4.TRS(position, Quaternion.identity, new Vector3(num, 40f, num)); UpdateMaterialParams(currentWater); if ((Object)(object)decalMesh == (Object)null) { decalMesh = CoreUtils.CreateCubeMesh(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f)); } CoreUtils.SetRenderTarget(cmd, ctx.cameraColorBuffer, (ClearFlag)0, 0, (CubemapFace)(-1), -1); cmd.DrawMesh(decalMesh, val, causticDecalMaterial); } } private void UpdateMaterialParams(WaterSystem water) { causticDecalMaterial.SetFloat("KW_CaustisStrength", water.CausticStrength); float num = 1f - (float)(Mathf.RoundToInt(Mathf.Log((float)water.FFT_SimulationSize, 2f)) - 5) / 4f; if (water.UseCausticDispersion && num > 0.1f) { causticDecalMaterial.EnableKeyword("USE_DISPERSION"); num = Mathf.Lerp(num * 0.25f, num, (float)water.CausticTextureSize / 1024f); causticDecalMaterial.SetFloat("KW_CausticDispersionStrength", num); } else { causticDecalMaterial.DisableKeyword("USE_DISPERSION"); } } protected override void Cleanup() { KW_Extensions.SafeDestroy((Object)causticDecalMaterial); } public void Release() { ((CustomPass)this).Cleanup(); } } public class KW_CausticRendering : MonoBehaviour { public Texture2D depth_tex; public RenderTexture causticLod0; public RenderTexture causticLod1; public RenderTexture causticLod2; public RenderTexture causticLod3; public RenderTexture causticRT; private Material causticComputeMaterial; private Material causticDecalMaterial; private Mesh causticMesh; private Mesh decalMesh; private CommandBuffer cb; private const string path_causticFolder = "CausticMaps"; private const string path_causticDepthTexture = "KW_CausticDepthTexture"; private const string path_causticDepthData = "KW_CausticDepthData"; private int ID_KW_CausticDepth = Shader.PropertyToID("KW_CausticDepthTex"); private int ID_KW_CausticDepthOrthoSize = Shader.PropertyToID("KW_CausticDepthOrthoSize"); private int ID_KW_CausticDepthNearFarDistance = Shader.PropertyToID("KW_CausticDepth_Near_Far_Dist"); private int ID_KW_CausticDepthPos = Shader.PropertyToID("KW_CausticDepthPos"); private const int nearPlaneDepth = -2; private const int farPlaneDepth = 100; private int currentMeshResolution; private bool isDepthTextureInitialized; public static Vector4 LodSettings = new Vector4(10f, 20f, 40f, 80f); public void Release() { OnDisable(); } private void OnDisable() { KW_Extensions.SafeDestroy((Object)depth_tex, (Object)causticComputeMaterial, (Object)causticDecalMaterial, (Object)causticMesh, (Object)decalMesh); KW_Extensions.ReleaseRenderTextures(causticLod0, causticLod1, causticLod2, causticLod3, causticRT); currentMeshResolution = 0; isDepthTextureInitialized = false; Sh