public void AddForce(List <WaterForce.Data> data, float radius = 1f) { Vector2 resolution = this.Resolution; int num = 0; for (int i = 0; i < data.Count; i++) { Vector2 localPixelPosition = this.GetLocalPixelPosition(data[i].Position); if (WaterSimulationArea.ContainsLocalRaw(localPixelPosition, resolution)) { if (data[i].Force > 0f) { WaterSimulationArea._Array[num * 4] = localPixelPosition.x; WaterSimulationArea._Array[num * 4 + 1] = localPixelPosition.y; WaterSimulationArea._Array[num * 4 + 2] = data[i].Force * 500f; WaterSimulationArea._Array[num * 4 + 3] = 0f; num++; if (num == 512) { this.DispatchAddForce(num); num = 0; } } } } this.DispatchAddForce(num); }
public static void Register(WaterSimulationArea area) { WaterRipples instance = SceneSingleton <WaterRipples> .Instance; if (instance == null || instance._Areas.Contains(area)) { return; } instance._Areas.Add(area); }
public static void Unregister(WaterSimulationArea area) { WaterRipples instance = SceneSingleton <WaterRipples> .Instance; if (instance == null) { return; } instance._Areas.Remove(area); }
public static void AddForce(List <WaterForce.Data> data, float radius = 1f) { WaterRipples instance = SceneSingleton <WaterRipples> .Instance; if (instance == null || Time.timeScale == 0f) { return; } for (int i = instance._Areas.Count - 1; i >= 0; i--) { WaterSimulationArea waterSimulationArea = instance._Areas[i]; waterSimulationArea.AddForce(data, radius); } }
private void CreateDepthCamera() { if (this.Resolution.x <= 0f || this.Resolution.y <= 0f) { Debug.LogError("WaterSimulationArea: invalid resolution"); } GameObject gameObject = new GameObject("Depth"); gameObject.transform.SetParent(base.transform); this._DepthCamera = gameObject.AddComponent <Camera>(); this._DepthCamera.enabled = false; this._DepthCamera.backgroundColor = Color.clear; this._DepthCamera.clearFlags = CameraClearFlags.Color; this._DepthCamera.orthographic = true; this._DepthCamera.orthographicSize = this.Size.y * 0.5f; this._DepthCamera.aspect = this.Resolution.x / this.Resolution.y; this._DepthCamera.transform.localRotation = Quaternion.Euler(new Vector3(90f, 180f, 0f)); this._DepthCamera.transform.localScale = Vector3.one; this._DepthCamera.depthTextureMode = DepthTextureMode.Depth; WaterSimulationArea.SetDepthCameraParameters(ref this._DepthCamera, 10f, 0f, 20f); }
private void RenderStaticDepthTexture() { if (!this._EnableStaticCalculations) { if (this._StaticDepth != null) { this._StaticDepth.Release(); this._StaticDepth = null; } return; } if (this._DepthCamera.IsNullReference(this)) { return; } if (this._StaticDepth == null) { TextureUtility.RenderTextureDesc desc = new TextureUtility.RenderTextureDesc("[UWS] - Static Depth") { Width = this._StaticWidth, Height = this._StaticHeight, Depth = 24, Format = RenderTextureFormat.RFloat, Filter = FilterMode.Point }; this._StaticDepth = desc.CreateRenderTexture(); this._StaticDepth.Clear(Color.clear, false, true); } float y = this._DepthCamera.transform.localPosition.y; float nearClipPlane = this._DepthCamera.nearClipPlane; float farClipPlane = this._DepthCamera.farClipPlane; WaterSimulationArea.SetDepthCameraParameters(ref this._DepthCamera, 40f, 0f, 80f); this._DepthCamera.cullingMask = WaterQualitySettings.Instance.Ripples.StaticDepthMask; this._DepthCamera.targetTexture = this._StaticDepth; this._DepthCamera.SetReplacementShader(ShaderUtility.Instance.Get(ShaderList.Depth), string.Empty); this._DepthCamera.Render(); WaterSimulationArea.SetDepthCameraParameters(ref this._DepthCamera, y, nearClipPlane, farClipPlane); RipplesShader.SetStaticDepth(this._StaticDepth, this._RipplesMaterial); }