Esempio n. 1
0
    /// <summary>
    /// Initialization logic that must be done after the ZED camera has finished initializing.
    /// Added to the ZEDManager.OnZEDReady() callback in OnEnable().
    /// </summary>
    private void ZEDReady()
    {
        //Set up textures and materials used for the final output.
        finalTexture = new RenderTexture(sl.ZEDCamera.GetInstance().ImageWidth, sl.ZEDCamera.GetInstance().ImageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
        finalTexture.SetGlobalShaderProperty("ZEDMaskTexGreenScreen");
        finalMat.SetTexture("_MaskTex", finalTexture);
        greenScreenMat = Resources.Load("Materials/Mat_ZED_Compute_GreenScreen") as Material;
        blurMaterial   = Resources.Load("Materials/PostProcessing/Mat_ZED_Blur") as Material;
        matYUV         = Resources.Load("Materials/Mat_ZED_YUV") as Material;
        matYUV.SetInt("_isLinear", System.Convert.ToInt32(QualitySettings.activeColorSpace));

        preprocessMat = Resources.Load("Materials/Mat_ZED_Preprocess") as Material;
        preprocessMat.SetTexture("_CameraTex", screenManager.TextureEye);
        ZEDPostProcessingTools.ComputeWeights(1, out weights_, out offsets_);

        //Send the values to the current shader.
        blurMaterial.SetFloatArray("weights2", weights_);
        blurMaterial.SetFloatArray("offset2", offsets_);
        greenScreenMat.SetTexture("_CameraTex", screenManager.TextureEye);

        UpdateShader();
        UpdateCanal();
        if (System.IO.File.Exists("ZED_Settings.conf"))
        {
            sl.ZEDCamera.GetInstance().LoadCameraSettings("ZED_Settings.conf");
            sl.ZEDCamera.GetInstance().SetCameraSettings();
        }
    }
Esempio n. 2
0
    /// <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);
    }
Esempio n. 3
0
    private void Start()
    {
        //No environmental lighting per default
        Shader.SetGlobalFloat("_ZEDExposure", -1);
        //Load the materials
        matStencilToMask = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_Stencil2Mask") as Material);
        matComposeMask   = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_MaskCompositor") as Material);

        //Load and configure the post process
        postprocessMaterial = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_PostProcessing") as Material);
        postprocessMaterial.SetFloat("_gamma", 1.0f / (0.87f * 0.9f));
        postprocessMaterial.SetFloat("_MinBlack", 15.0f / 255.0f);
        postprocessMaterial.SetInt("_NoiseSize", 2);

        //Configure the weights for the blur
        float[] weights;
        float[] offsets;
        ZEDPostProcessingTools.ComputeWeights(0.3f, out weights, out offsets);

        //Set the blur config to the shader, should be constant
        blurMaterial = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_Blur") as Material);
        blurMaterial.SetFloatArray("weights", weights);
        blurMaterial.SetFloatArray("offset", offsets);
        blurMaterial.SetTexture("_Mask", mask);

        // set up render texture for hands depth data to pass into the texture
        //handsDepthMapRenderTex = new RenderTexture (LeftHandsDepthMap.width, LeftHandsDepthMap.height, LeftHandsDepthMap.depth, LeftHandsDepthMap.format);


        //Force unity the 16:9 mode
#if UNITY_EDITOR
        UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect16by9, true);
        UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect16by10, false);
        UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect4by3, false);
        UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect5by4, false);
#endif
        CreateRenderTexture();

        //Load the blender for the zedmesher
        blender = new Material(Resources.Load("Materials/SpatialMapping/Mat_ZED_PostProcess_Blend") as Material);

        //Set the bounds larger
        bounds = new Bounds(transform.position, new Vector3(20, 20, 20));

        // If AR REMOVE
        aspectRatio = new WindowAspectRatio(mainCamera);
    }
    /// <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);
    }
    /// <summary>
    /// Initialization logic that must be done after the ZED camera has finished initializing.
    /// Added to the ZEDManager.OnZEDReady() callback in OnEnable().
    /// </summary>
    private void ZEDReady()
    {
        //Set up textures and materials used for the final output.
        if (cameraManager == null)
        {
            return;
        }

        //We set the material again in case it has changed.
        //screen = gameObject.transform.GetChild(0).gameObject;
        finalMat = screenManager.matRGB;

        finalTexture = new RenderTexture(cameraManager.zedCamera.ImageWidth, cameraManager.zedCamera.ImageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
        if (screenManager.forwardMat)
        {
            screenManager.forwardMat.SetTexture("ZEDMaskTexGreenScreen", finalTexture);
        }
        if (screenManager.deferredMat)
        {
            screenManager.deferredMat.SetTexture("ZEDMaskTexGreenScreen", finalTexture);
        }

        finalMat.SetTexture("_MaskTex", finalTexture);
        greenScreenMat = new Material(Resources.Load("Materials/Mat_ZED_Compute_GreenScreen") as Material);
        blurMaterial   = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_Blur") as Material);
        matYUV         = new Material(Resources.Load("Materials/Mat_ZED_YUV") as Material);
        matYUV.SetInt("_isLinear", System.Convert.ToInt32(QualitySettings.activeColorSpace));

        preprocessMat = new Material(Resources.Load("Materials/Mat_ZED_Preprocess") as Material);
        preprocessMat.SetTexture("_CameraTex", screenManager.TextureEye);
        ZEDPostProcessingTools.ComputeWeights(1, out weights_, out offsets_);

        //Send the values to the current shader.
        blurMaterial.SetFloatArray("weights2", weights_);
        blurMaterial.SetFloatArray("offset2", offsets_);
        greenScreenMat.SetTexture("_CameraTex", screenManager.TextureEye);

        UpdateShader();
        UpdateCanal();
        if (System.IO.File.Exists("ZED_Settings.conf"))
        {
            cameraManager.zedCamera.LoadCameraSettings("ZED_Settings.conf");
            cameraManager.zedCamera.SetCameraSettings();
        }
    }