Example #1
0
    private void UpdateView()
    {
        if (renderView == null || renderView.pRenderView == IntPtr.Zero)
        {
            SetRenderView();
        }

        udRenderInstance[] modelArray   = UDUtilities.getUDSInstances();
        Matrix4x4          watcherTrans = transform.localToWorldMatrix;

        double[] frontPlaneView = UDUtilities.GetUDMatrix(watcherTrans);
        renderView.SetMatrix(Vault.udRenderTargetMatrix.Camera, frontPlaneView);
        Matrix4x4 projection = Matrix4x4.Ortho(-width / 2, width / 2, height / 2, -height / 2, zNear, zFar);

        renderView.SetMatrix(Vault.udRenderTargetMatrix.Projection, UDUtilities.GetUDMatrix(projection));
        RenderOptions options = new RenderOptions();

        //we need the highest LOD if we are not updating the mesh every frame
        if (blockOnStream)
        {
            options.options.flags = udRenderContextFlags.udRF_BlockingStreaming;
        }

        try
        {
            GlobalVDKContext.renderer.Render(renderView, modelArray, modelArray.Length, options);
        }
        catch (Exception e) {
            Debug.Log("VDK dropped frame: " + e.ToString());
        }
        MakeSheetMesh(width, height, (int)widthPix, (int)heightPix, depthBuffer);
    }
Example #2
0
    /*
     * generates and stores a depth image rom a z buffer for use in spacial calculations
     * this is pretty expensive
     */
    public void setDepthImageFromZ(float[] value)
    {
        if (cam == null)
        {
            return;
        }

        if (depthBuffer == null || depthBuffer.Length != value.Length)
        {
            depthBuffer = new float[value.Length];
        }

        for (int i = 0; i < depthBuffer.Length; ++i)
        {
            depthBuffer[i] = UDUtilities.zBufferToDepth(depthBuffer[i], cam.nearClipPlane, cam.farClipPlane, false);
        }
    }
Example #3
0
    private void UpdateView()
    {
        if (renderView == null || renderView.pRenderView == IntPtr.Zero)
        {
            SetRenderView();
        }

        vdkRenderInstance[] modelArray   = UDUtilities.getUDSInstances();
        Matrix4x4           watcherTrans = transform.localToWorldMatrix;

        double[] frontPlaneView = UDUtilities.GetUDMatrix(watcherTrans);
        renderView.SetMatrix(Vault.RenderViewMatrix.Camera, frontPlaneView);
        Matrix4x4 projection = Matrix4x4.Ortho(-width / 2, width / 2, height / 2, -height / 2, zNear, zFar);

        renderView.SetMatrix(Vault.RenderViewMatrix.Projection, UDUtilities.GetUDMatrix(projection));
        GlobalVDKContext.renderer.Render(renderView, modelArray, modelArray.Length);
        MakeSheetMesh(width, height, (int)widthPix, (int)heightPix, depthBuffer);
    }
Example #4
0
    public override void Render(PostProcessRenderContext context)
    {
        Camera cam = context.camera;

        cam.depthTextureMode |= DepthTextureMode.Depth;
        if (!GlobalVDKContext.isCreated)
        {
            return;
        }

        if (context.width != width || context.height != height)
        {
            RebuildBuffers(context.width, context.height);
        }

        GameObject[]        objects    = GameObject.FindGameObjectsWithTag("UDSModel");
        vdkRenderInstance[] modelArray = UDUtilities.getUDSInstances();
        if (modelArray.Length > 0)
        {
            vRenderView.SetMatrix(Vault.RenderViewMatrix.View, UDUtilities.GetUDMatrix(cam.worldToCameraMatrix));
            vRenderView.SetMatrix(Vault.RenderViewMatrix.Projection, UDUtilities.GetUDMatrix(cam.projectionMatrix));

            GlobalVDKContext.renderer.Render(vRenderView, modelArray, modelArray.Length);

            //make sure that the textures exist before operating on them
            if (colourTexture == null || depthTexture == null)
            {
                InitialiseTextures();
            }

            colourTexture.SetPixels32(colourBuffer);
            colourTexture.Apply();

            depthTexture.LoadRawTextureData <float>(new Unity.Collections.NativeArray <float>(depthBuffer, Unity.Collections.Allocator.Temp));
            depthTexture.Apply();

            var sheet = context.propertySheets.Get(Shader.Find("Hidden/VDK/VDKShader"));
            sheet.properties.SetTexture("_udCol", colourTexture);
            sheet.properties.SetTexture("_udDep", depthTexture);
            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
        }
    }
Example #5
0
 /*
  * converts the z buffer value to a world space displacement
  */
 float zBufferToDepth(float z)
 {
     return(UDUtilities.zBufferToDepth(z, zNear, zFar));
 }
Example #6
0
    public override void Render(PostProcessRenderContext context)
    {
        Camera cam = context.camera;

        cam.depthTextureMode |= DepthTextureMode.Depth;
        if (!GlobalVDKContext.isCreated)
        {
            return;
        }

        vdkCameraOptions optionsContainer = cam.GetComponent <vdkCameraOptions>();
        RenderOptions    options;
        float            resolutionScaling;

        if (optionsContainer != null)
        {
            options           = optionsContainer.optionsStruct;
            resolutionScaling = optionsContainer.resolutionScaling;
        }
        else
        {
            optionsContainer  = null;
            options           = new RenderOptions();
            resolutionScaling = 1;
        }

        if ((int)context.width * resolutionScaling != width || (int)context.height * resolutionScaling != height)
        {
            RebuildBuffers((int)(context.width * resolutionScaling), (int)(context.height * resolutionScaling));
        }

        GameObject[]       objects    = GameObject.FindGameObjectsWithTag("UDSModel");
        udRenderInstance[] modelArray = UDUtilities.getUDSInstances();
        if (modelArray.Length > 0)
        {
            vRenderView.SetMatrix(Vault.udRenderTargetMatrix.View, UDUtilities.GetUDMatrix(cam.worldToCameraMatrix));
            vRenderView.SetMatrix(Vault.udRenderTargetMatrix.Projection, UDUtilities.GetUDMatrix(cam.projectionMatrix));

            //interface to input render options: this allows setting of render flags, picking and filtering from unity objects attached to the camera

            GlobalVDKContext.renderer.Render(vRenderView, modelArray, modelArray.Length, options);

            //pass the depth buffer back to the unity interface for further processing:
            if (optionsContainer != null && optionsContainer.recordDepthBuffer)
            {
                optionsContainer.setDepthImageFromZ(depthBuffer);//for as yet unimplemented features
            }
            //make sure that the textures exist before operating on them
            if (colourTexture == null || depthTexture == null)
            {
                InitialiseTextures();
            }

            colourTexture.SetPixels32(colourBuffer);
            colourTexture.Apply();

            depthTexture.LoadRawTextureData <float>(new Unity.Collections.NativeArray <float>(depthBuffer, Unity.Collections.Allocator.Temp));
            depthTexture.Apply();

            var sheet = context.propertySheets.Get(Shader.Find("Hidden/VDK/VDKShader"));
            sheet.properties.SetTexture("_udCol", colourTexture);
            sheet.properties.SetTexture("_udDep", depthTexture);
            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
        }
    }