예제 #1
0
    /// <summary>
    /// Return a string from a pointer to char
    /// </summary>
    private void OnPreRender()
    {
        if (screenManager.camZedLeft == null || screenManager.camZedLeft.width == 0)
        {
            return;
        }
        if (canal.Equals(CANAL.FOREGROUND))
        {
            return;
        }

        RenderTexture tempYUV     = RenderTexture.GetTemporary(screenManager.camZedLeft.width, screenManager.camZedLeft.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
        RenderTexture tempYUVBlur = RenderTexture.GetTemporary(screenManager.camZedLeft.width, screenManager.camZedLeft.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);

        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.camZedLeft, tempYUV, matYUV);

        //Graphics.Blit(screenManager.camZedLeft, tempYUVBlur, matYUV);
        Blur(tempYUV, tempYUVBlur, blurMaterial, 1, 2, 1);


        Graphics.Blit(tempYUVBlur, tempAlpha, greenScreenMat);
        preprocessMat.SetTexture("_MaskTex", tempAlpha);

        Graphics.Blit(screenManager.camZedLeft, tempFinalAlpha, preprocessMat);

        //If the sigma has changed recompute the weights and offsets used by the blur
        if (sigma_ != 0)
        {
            if (sigma_ != currentSigma)
            {
                currentSigma = sigma_;

                ComputeWeights(currentSigma);

                //Send the values to the current shader
                blurMaterial.SetFloatArray("weights", weights_);
                blurMaterial.SetFloatArray("offset", offsets_);
            }
            Blur(tempFinalAlpha, finalTexture, blurMaterial, 0, 2, 1);
        }
        else
        {
            Graphics.Blit(tempFinalAlpha, finalTexture);
        }

        //Destroy all the temporary buffers
        RenderTexture.ReleaseTemporary(tempYUVBlur);
        RenderTexture.ReleaseTemporary(tempAlpha);
        RenderTexture.ReleaseTemporary(tempYUV);
        RenderTexture.ReleaseTemporary(tempFinalAlpha);
    }
    /// <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);
    }