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

62 lines
1.3 KiB
C#

using UnityEngine;
namespace AQUAS
{
public class AQUAS_BoundaryMask : MonoBehaviour
{
public Material mat;
public Material matNull;
public RenderTexture target;
private Camera cam;
public GameObject nextCam;
public GameObject boundaryObj;
private void Start()
{
mat = new Material(Shader.Find("Hidden/AQUAS/Utils/Boundary Mask"));
matNull = new Material(Shader.Find("Hidden/AQUAS/Null"));
target = new RenderTexture(Screen.width, Screen.height, 32, RenderTextureFormat.ARGBHalf);
cam = GetComponent<Camera>();
cam.targetTexture = target;
cam.pixelRect = new Rect(0f, 0f, Screen.width, Screen.height);
}
private void OnPreCull()
{
if (!(boundaryObj == null))
{
boundaryObj.layer = LayerMask.NameToLayer("Water");
}
}
private void OnPostRender()
{
if (!(boundaryObj == null))
{
boundaryObj.layer = LayerMask.NameToLayer("Default");
}
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (boundaryObj == null)
{
Graphics.Blit(source, destination, matNull);
nextCam.GetComponent<AQUAS_VolumeMask>().mat.SetTexture("_MaskTex", target);
target.Release();
}
else
{
Graphics.Blit(source, destination, mat);
nextCam.GetComponent<AQUAS_VolumeMask>().mat.SetTexture("_MaskTex", target);
target.Release();
}
}
}
}