private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (GetMat != null) { GetMat.SetFloat("_BlurSize", mBlurSize); GetMat.SetMatrix("_PreVPMarix", preVPMarix); Matrix4x4 currentVPMarix = GetCamera.projectionMatrix * GetCamera.worldToCameraMatrix; Matrix4x4 currentVPMarixInverse = currentVPMarix.inverse; GetMat.SetMatrix("_CurVPMarixInverse", currentVPMarixInverse); preVPMarix = currentVPMarix; Graphics.Blit(source, destination, GetMat); } else { Graphics.Blit(source, destination); } }
private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (GetMat != null) { float halfHeight = GetCamera.nearClipPlane * Mathf.Tan(GetCamera.fieldOfView * 0.5f * Mathf.Deg2Rad); Vector3 toTop = GetCamera.transform.up * halfHeight; Vector3 toRight = GetCamera.transform.right * halfHeight * GetCamera.aspect; Vector3 tlRay = GetCamera.transform.forward * GetCamera.nearClipPlane + toTop - toRight; float scale = tlRay.magnitude / GetCamera.nearClipPlane; tlRay = tlRay.normalized * scale; Vector3 trRay = GetCamera.transform.forward * GetCamera.nearClipPlane + toTop + toRight; trRay = tlRay.normalized * scale; Vector3 dlRay = GetCamera.transform.forward * GetCamera.nearClipPlane - toTop - toRight; dlRay = dlRay.normalized * scale; Vector3 drRay = GetCamera.transform.forward * GetCamera.nearClipPlane - toTop + toRight; drRay = drRay.normalized * scale; Matrix4x4 frustumCorners = Matrix4x4.identity; frustumCorners.SetRow(0, tlRay); frustumCorners.SetRow(1, trRay); frustumCorners.SetRow(2, drRay); frustumCorners.SetRow(3, dlRay); GetMat.SetFloat("_FogDensity", fogDensity); GetMat.SetColor("_FogColor", mFogColor); GetMat.SetFloat("_FogStart", mFogStart); GetMat.SetFloat("_FogEnd", mFogEnd); GetMat.SetMatrix("_FrustumCornersRay", frustumCorners); Graphics.Blit(source, destination, GetMat); } else { Graphics.Blit(source, destination); } }