예제 #1
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);
    }
예제 #2
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);
        }
    }
예제 #3
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if (closeWhenPossible)
            {
                Close();
                return;
            }

            vdkRenderInstance[] renderInstances = new vdkRenderInstance[listBox1.Items.Count];

            time += 0.01f;
            double angle = -Math.PI / 3.0;

            double[] matrix = new double[16];
            matrix[0] = Math.Cos(time) * Math.Sin(angle);
            matrix[1] = -Math.Sin(time) * Math.Sin(angle);
            matrix[2] = Math.Cos(angle);

            matrix[4] = Math.Sin(time) * Math.Sin(angle);
            matrix[5] = Math.Cos(time) * Math.Sin(angle);
            matrix[6] = Math.Cos(angle);

            matrix[8]  = 0;
            matrix[9]  = 0;
            matrix[10] = Math.Sin(angle);

            matrix[12] = 0;
            matrix[13] = 1;
            matrix[14] = -0.25;

            matrix[15] = 1.0;

            for (int i = 0; i < listBox1.Items.Count; ++i)
            {
                renderInstances[i].pointCloud  = (listBox1.Items[i] as PointCloud).pointCloud.pModel;
                renderInstances[i].worldMatrix = matrix;//(listBox1.Items[i] as PointCloud).matrix;
            }

            double[] cameraMatrix =
            {
                1, 0, 0, 0,
                0, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1
            };

            renderView.SetMatrix(Vault.RenderViewMatrix.Camera, cameraMatrix);

            renderCtx.Render(renderView, renderInstances, renderInstances.Length);

            // Copy it to the bitmap
            BitmapData bData = bmp.LockBits(new Rectangle(0, 0, (int)vdkWidth, (int)vdkHeight), ImageLockMode.WriteOnly, bmp.PixelFormat);

            System.Runtime.InteropServices.Marshal.Copy((int[])(object)vdkColorBuffer, 0, bData.Scan0, (int)(vdkWidth * vdkHeight));
            bmp.UnlockBits(bData);

            // Draw the bitmap
            e.Graphics.DrawImage(bmp, 0, 0);

            panel1.Invalidate();
        }