示例#1
0
        void Update()
        {
            if (matRenderer == null || sensorData == null)
            {
                return;
            }

            if (backgroundRemovalManager != null && alphaTex == null)
            {
                // alpha texture
                alphaTex = backgroundRemovalManager.GetAlphaTex();

                if (alphaTex != null)
                {
                    matRenderer.SetTexture("_AlphaTex", alphaTex);
                }
            }

            if (colorTex == null)
            {
                // color texture
                colorTex = sensorData.colorImageTexture;
                if (backgroundRemovalManager != null)
                {
                    colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex;
                }

                if (colorTex != null)
                {
                    matRenderer.SetInt("_TexResX", colorTex.width);
                    matRenderer.SetInt("_TexResY", colorTex.height);

                    matRenderer.SetTexture("_ColorTex", colorTex);
                }
            }

            if (colorTex == null)
            {
                return;
            }

            if (sensorData.colorDepthBuffer == null)
            {
                int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2;
                sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint));
                matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer);

                ScaleRendererTransform(colorTex);
            }

            matRenderer.SetFloat("_DepthDistance", depthDistance);
            matRenderer.SetFloat("_InvDepthVal", invalidDepthValue);

            // update lighting parameters
            lighting.UpdateLighting(matRenderer, applyLighting);
        }
示例#2
0
        void Update()
        {
            if (matRenderer == null || sensorInt == null)
            {
                return;
            }

            if (alphaTex == null)
            {
                // alpha texture
                alphaTex = backgroundRemovalManager.GetAlphaTex();

                if (alphaTex != null)
                {
                    matRenderer.SetTexture("_AlphaTex", alphaTex);
                }
            }

            if (colorTex == null)
            {
                // color texture
                colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex;  // sensorInt.pointCloudColorTexture

                if (colorTex != null)
                {
                    matRenderer.SetInt("_TexResX", colorTex.width);
                    matRenderer.SetInt("_TexResY", colorTex.height);

                    matRenderer.SetTexture("_ColorTex", colorTex);
                }
            }

            if (colorTex == null || alphaTex == null /**|| foregroundCamera == null*/)
            {
                return;
            }

            if (sensorInt.pointCloudResolution == DepthSensorBase.PointCloudResolution.DepthCameraResolution)
            {
                if (depthImageBuffer == null)
                {
                    //int depthImageLength = sensorData.depthImageWidth * sensorData.depthImageHeight;
                    //depthImageCopy = new ushort[depthImageLength];

                    int depthBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 2;
                    depthImageBuffer = KinectInterop.CreateComputeBuffer(depthImageBuffer, depthBufferLength, sizeof(uint));
                    matRenderer.SetBuffer("_DepthMap", depthImageBuffer);

                    ScaleRendererTransform(colorTex);
                }

                if (depthImageBuffer != null && sensorData.depthImage != null)
                {
                    //KinectInterop.CopyBytes(sensorData.depthImage, sizeof(ushort), depthImageCopy, sizeof(ushort));

                    int depthBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 2;
                    KinectInterop.SetComputeBufferData(depthImageBuffer, sensorData.depthImage, depthBufferLength, sizeof(uint));
                }

                //Debug.Log("ForegroundBlendRenderer DepthFrameTime: " + lastDepthFrameTime);
            }
            else
            {
                if (sensorData.colorDepthBuffer == null)
                {
                    int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2;
                    sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint));
                    matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer);

                    ScaleRendererTransform(colorTex);
                }

                //Debug.Log("ForegroundBlendRenderer ColorDepthBufferTime: " + sensorData.lastColorDepthBufferTime);
            }

            matRenderer.SetFloat("_DepthDistance", 0f);
            matRenderer.SetFloat("_InvDepthVal", invalidDepthValue);

            // update lighting parameters
            lighting.UpdateLighting(matRenderer, applyLighting);
        }
        void Update()
        {
            if (matRenderer == null || sensorData == null)
            {
                return;
            }

            if (alphaTex == null || alphaTex.width != sensorData.colorImageWidth || alphaTex.height != sensorData.colorImageHeight)
            {
                // alpha texture
                alphaTex = backgroundRemovalManager != null?backgroundRemovalManager.GetAlphaTex() : null;

                if (alphaTex != null)
                {
                    matRenderer.SetTexture("_AlphaTex", alphaTex);
                }
            }

            if (colorTex == null || colorTex.width != sensorData.colorImageWidth || colorTex.height != sensorData.colorImageHeight)
            {
                // color texture
                colorTex = sensorData.colorImageTexture;
                if (backgroundRemovalManager != null)
                {
                    colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex;
                }

                if (colorTex != null)
                {
                    matRenderer.SetInt("_TexResX", colorTex.width);
                    matRenderer.SetInt("_TexResY", colorTex.height);

                    matRenderer.SetTexture("_ColorTex", colorTex);
                }
            }

            if (colorTex == null)
            {
                return;
            }

            int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2;

            if (sensorData.colorDepthBuffer == null || sensorData.colorDepthBuffer.count != bufferLength)
            {
                sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint));
                matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer);
                //Debug.Log("Created colorDepthBuffer with len: " + bufferLength);
            }

            matRenderer.SetFloat("_DepthDistance", depthDistance);
            matRenderer.SetFloat("_InvDepthVal", invalidDepthValue);

            int curScreenW = foregroundCamera ? foregroundCamera.pixelWidth : Screen.width;
            int curScreenH = foregroundCamera ? foregroundCamera.pixelHeight : Screen.height;

            if (lastScreenW != curScreenW || lastScreenH != curScreenH || lastColorW != sensorData.colorImageWidth || lastColorH != sensorData.colorImageHeight)
            {
                ScaleRendererTransform(colorTex, curScreenW, curScreenH);
            }

            // update lighting parameters
            lighting.UpdateLighting(matRenderer, applyLighting);
        }