using System.Collections; using System.Collections.Generic; using UnityEngine; public class DepthFog : MonoBehaviour { Camera Cam; Material fogmat; public float StartDistance; public float EndDistance; public float Height; public Color FogCol; void Awake() { fogmat = new Material(Shader.Find("Hidden/DepthFog")); Cam = this.GetComponent(); } // Update is called once per frame void Update() { } private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (fogmat == null|| Cam==null) return; Shader.SetGlobalFloat("_StartDistance", StartDistance); Shader.SetGlobalFloat("_EndDistance", EndDistance); Shader.SetGlobalFloat("_Height", Height); Shader.SetGlobalColor("_FogCol", FogCol); Matrix4x4 vp = GL.GetGPUProjectionMatrix(Cam.projectionMatrix, false) * Cam.worldToCameraMatrix; vp = vp.inverse; Shader.SetGlobalMatrix("_InvVP", vp); Graphics.Blit(source, destination, fogmat); } }