void AddBokeh(RenderTexture bokehInfo, RenderTexture tempTex, RenderTexture finalTarget) { if (bokehMaterial) { var meshes = Quads.GetMeshes(tempTex.width, tempTex.height); // quads: exchanging more triangles with less overdraw RenderTexture.active = tempTex; GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f)); GL.PushMatrix(); GL.LoadIdentity(); // point filter mode is important, otherwise we get bokeh shape & size artefacts bokehInfo.filterMode = FilterMode.Point; float arW = (bokehInfo.width * 1.0f) / (bokehInfo.height * 1.0f); float sc = 2.0f / (1.0f * bokehInfo.width); sc += bokehScale * maxBlurSpread * BOKEH_EXTRA_BLUR * oneOverBaseSize; bokehMaterial.SetTexture("_Source", bokehInfo); bokehMaterial.SetTexture("_MainTex", bokehTexture); bokehMaterial.SetVector("_ArScale", new Vector4(sc, sc * arW, 0.5f, 0.5f * arW)); bokehMaterial.SetFloat("_Intensity", bokehIntensity); bokehMaterial.SetPass(0); foreach (Mesh m in meshes) { if (m) { Graphics.DrawMeshNow(m, Matrix4x4.identity); } } GL.PopMatrix(); Graphics.Blit(tempTex, finalTarget, dofMaterial, 8); // important to set back as we sample from this later on bokehInfo.filterMode = FilterMode.Bilinear; } }