protected override void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!Mat) { Graphics.Blit(source, destination); return; } int textureWidth = (int)(source.width * m_blurResolution + 0.5f); int textureHeight = (int)(source.height * m_blurResolution + 0.5f); RenderTexture blurTexture = CreateTexture(textureWidth, textureHeight, 0, source.format); Mat.SetVector(ShaderPropertyID.BloomColor, m_bloomColor); Mat.SetFloat(ShaderPropertyID.BloomSaturation, m_bloomSaturation); BlurMat.SetFloat(ShaderPropertyID.BloomIntensity, m_bloomIntensity); Mat.SetVector(ShaderPropertyID.BloomThreshold, m_bloomThreshold); Graphics.Blit(source, blurTexture, Mat, 0); Blur(blurTexture, eBlurType.Normal); Mat.SetTexture(ShaderPropertyID.BlurTex, blurTexture); Graphics.Blit(source, destination, Mat, 1); RenderTexture.ReleaseTemporary(blurTexture); }
protected override void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!Mat) { Graphics.Blit(source, destination); return; } if (m_camera == null || m_targetTrans == null) { Graphics.Blit(source, destination); return; } RenderTexture bokehTexture = CreateTexture(source); RenderTexture tmpTexture = CreateTexture(source, true); RenderTexture depthTexture = GetDepthTexture(source); if (m_blurDepthTex) { RenderTexture blurDepthTexture = CreateTexture(depthTexture); Graphics.Blit(depthTexture, blurDepthTexture); Blur(blurDepthTexture, eBlurType.Normal); BlurMat.SetTexture(ShaderPropertyID.DepthTex, blurDepthTexture); Blur(tmpTexture, bokehTexture, eBlurType.Depth); RenderTexture.ReleaseTemporary(blurDepthTexture); } else { BlurMat.SetTexture(ShaderPropertyID.DepthTex, depthTexture); Blur(tmpTexture, bokehTexture, eBlurType.Depth); } Mat.SetFloat(Shader.PropertyToID("_DepthOfField"), m_depthOfField); Mat.SetTexture(ShaderPropertyID.DepthTex, depthTexture); Mat.SetTexture(ShaderPropertyID.BokehTex, bokehTexture); Graphics.Blit(source, destination, Mat, 1); RenderTexture.ReleaseTemporary(tmpTexture); RenderTexture.ReleaseTemporary(depthTexture); RenderTexture.ReleaseTemporary(bokehTexture); }