void OnRenderImage(RenderTexture source, RenderTexture destination) { if (CMainMaterial) { // 申请两块降低了分辨率的RT RenderTexture rt1 = RenderTexture.GetTemporary(source.width >> down_sample_factor, source.height >> down_sample_factor, 0, source.format); RenderTexture rt2 = RenderTexture.GetTemporary(source.width >> down_sample_factor, source.height >> down_sample_factor, 0, source.format); Graphics.Blit(source, rt1); // 使用降低分辨率的rt进行模糊:pass0 CMainMaterial.SetFloat("_BlurFactor", blur_factor); CMainMaterial.SetVector("_BlurCenter", blur_center); Graphics.Blit(rt1, rt2, CMainMaterial, 0); // 使用rt2和原始图像lerp:pass1 CMainMaterial.SetTexture("_BlurTex", rt2); CMainMaterial.SetFloat("_LerpFactor", lerp_factor); Graphics.Blit(source, destination, CMainMaterial, 1); // 释放RT RenderTexture.ReleaseTemporary(rt1); RenderTexture.ReleaseTemporary(rt2); } else { Graphics.Blit(source, destination); } }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (CMainMaterial) { CMainMaterial.SetFloat("_BlurFactor", blur_factor); CMainMaterial.SetVector("_BlurCenter", blur_center); Graphics.Blit(source, destination, CMainMaterial); } else { Graphics.Blit(source, destination); } }
public float saturation = 1.0f; //饱和度 //覆写OnRenderImage函数 void OnRenderImage(RenderTexture src, RenderTexture dest) { //仅仅当有材质的时候才进行后处理,如果_Material为空,不进行后处理 if (CMainMaterial) { //通过Material.SetXXX("name",value)可以设置shader中的参数值 CMainMaterial.SetFloat("_Brightness", brightness); CMainMaterial.SetFloat("_Saturation", saturation); CMainMaterial.SetFloat("_Contrast", contrast); //使用Material处理Texture,dest不一定是屏幕,后处理效果可以叠加的! Graphics.Blit(src, dest, CMainMaterial); } else { //直接绘制 Graphics.Blit(src, dest); } }