using UnityEngine; namespace AQUAS { public class AQUAS_CaptureBackground : MonoBehaviour { public GameObject waterObj; public RenderTexture target; private Camera cam; public int quality = 2; public LayerMask layerMask = -1; private void Start() { int num = (int)Mathf.Pow(2f, quality); target = new RenderTexture(Screen.width / num, Screen.height / num, 32, RenderTextureFormat.ARGBHalf); cam = GetComponent(); cam.targetTexture = target; cam.pixelRect = new Rect(0f, 0f, Screen.width / num, Screen.height / num); } private void OnPreCull() { if (!(waterObj == null)) { cam.cullingMask = layerMask; cam.cullingMask &= ~(1 << LayerMask.NameToLayer("Water")); waterObj.layer = LayerMask.NameToLayer("Water"); } } private void OnPostRender() { if (!(waterObj == null)) { waterObj.layer = LayerMask.NameToLayer("Default"); } } private void Update() { if (target.width != Screen.width || target.height != Screen.height) { target.Release(); target.width = Screen.width; target.height = Screen.height; } } private void OnRenderImage(RenderTexture source, RenderTexture destination) { Graphics.Blit(source, destination); if (waterObj != null) { waterObj.GetComponent().sharedMaterials[1].SetTexture("_BackgroundTex", target); target.Release(); } else { target.Release(); } } } }