/// <summary> /// Post process pipeline /// </summary> /// <param name="source"></param> /// <param name="destination"></param> /// <param name="bluredMask"></param> private void ApplyPostProcess(RenderTexture source, RenderTexture destination, RenderTexture bluredMask) { RenderTexture tempDestination = RenderTexture.GetTemporary(source.width, source.height, source.depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); Graphics.Blit(source, tempDestination, postprocessMaterial); ZEDPostProcessingTools.Blur(mask, bluredMask, blurMaterial, 3, 1, 1); blurMaterial.SetTexture("_Mask", bluredMask); ZEDPostProcessingTools.Blur(tempDestination, destination, blurMaterial, 2, 1, 1); mask.SetGlobalShaderProperty("_ZEDMaskVirtual"); RenderTexture.ReleaseTemporary(tempDestination); }
/// <summary> /// Where various image processing effects are applied, including the green screen effect itself. /// </summary> private void OnPreRender() { if (screenManager.TextureEye == null || screenManager.TextureEye.width == 0) { return; } if (canal.Equals(CANAL.FOREGROUND)) { return; } RenderTexture tempAlpha = RenderTexture.GetTemporary(finalTexture.width, finalTexture.height, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); RenderTexture tempFinalAlpha = RenderTexture.GetTemporary(finalTexture.width, finalTexture.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); Graphics.Blit(screenManager.TextureEye, tempAlpha, greenScreenMat); //preprocessMat.SetTexture("_MaskTex", tempAlpha); preprocessMat.SetTexture(maskTexID, tempAlpha); Graphics.Blit(screenManager.TextureEye, tempFinalAlpha, preprocessMat); //If the sigma has changed, recompute the weights and offsets used by the blur. if (sigma_ == 0) { if (sigma_ != currentSigma) { currentSigma = sigma_; ZEDPostProcessingTools.ComputeWeights(currentSigma, out weights_, out offsets_); //Send the values to the current shader //blurMaterial.SetFloatArray("weights", weights_); blurMaterial.SetFloatArray(weightsID, weights_); //blurMaterial.SetFloatArray("offset", offsets_); blurMaterial.SetFloatArray(offsetID, offsets_); } ZEDPostProcessingTools.Blur(tempFinalAlpha, finalTexture, blurMaterial, 0, 1, 1); } else { Graphics.Blit(tempFinalAlpha, finalTexture); } //Destroy all the temporary buffers RenderTexture.ReleaseTemporary(tempAlpha); RenderTexture.ReleaseTemporary(tempFinalAlpha); }