68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace AQUAS
|
|
{
|
|
public class AQUAS_RenderDepth : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public GameObject plane;
|
|
|
|
private Material material;
|
|
|
|
private RenderTexture target;
|
|
|
|
private string shaderPath;
|
|
|
|
private bool checkForGridProjection = true;
|
|
|
|
private void Start()
|
|
{
|
|
material = new Material(Shader.Find("Hidden/AQUAS/Utils/Screen Depth"));
|
|
target = new RenderTexture(Screen.width / 1, Screen.height / 1, 32, RenderTextureFormat.ARGBHalf);
|
|
target.filterMode = FilterMode.Bilinear;
|
|
GetComponent<Camera>().targetTexture = target;
|
|
shaderPath = plane.GetComponent<Renderer>().sharedMaterials[0].shader.name;
|
|
plane.GetComponent<Renderer>().sharedMaterial.shader = Shader.Find("Hidden/AQUAS/Desktop/Front/Opaque");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (GetComponentInParent<AQUAS_ProjectedGrid>() != null && GetComponents<AQUAS_ProjectedGrid>() != null && checkForGridProjection)
|
|
{
|
|
base.gameObject.AddComponent<AQUAS_ProjectedGrid>();
|
|
GetComponent<AQUAS_ProjectedGrid>().waterplane = base.transform.parent.GetComponent<AQUAS_ProjectedGrid>().waterplane;
|
|
GetComponent<AQUAS_ProjectedGrid>().waterLevel = base.transform.parent.GetComponent<AQUAS_ProjectedGrid>().waterLevel;
|
|
checkForGridProjection = false;
|
|
}
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
plane.GetComponent<Renderer>().sharedMaterial.shader = Shader.Find(shaderPath);
|
|
}
|
|
|
|
private void OnPreCull()
|
|
{
|
|
if (!(plane == null))
|
|
{
|
|
plane.layer = LayerMask.NameToLayer("Water");
|
|
}
|
|
}
|
|
|
|
private void OnPostRender()
|
|
{
|
|
if (!(plane == null))
|
|
{
|
|
plane.layer = LayerMask.NameToLayer("Default");
|
|
}
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
Graphics.Blit(source, destination, material);
|
|
plane.GetComponent<Renderer>().sharedMaterial.SetTexture("_DeTex", target);
|
|
target.Release();
|
|
}
|
|
}
|
|
}
|