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); }
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); } }
private void panel1_Paint(object sender, PaintEventArgs e) { if (closeWhenPossible) { Close(); return; } udRenderInstance[] renderInstances = new udRenderInstance[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(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(); }