Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        centrePoint = new double[3] {
            (double)this.transform.position.x, (double)this.transform.position.y, (double)this.transform.position.z
        };
        yawPitchRoll = new double[3]
        {
            (double)this.transform.eulerAngles.z / 180 * (double)Mathf.PI,
            (double)this.transform.eulerAngles.x / 180 * (double)Mathf.PI,
            (double)this.transform.eulerAngles.y / 180 * (double)Mathf.PI
        };
        halfsize = new double[3] {
            (double)this.transform.localScale.x / 2, (double)this.transform.localScale.y / 2, (double)this.transform.localScale.z / 2
        };
        vFilter.SetAsBox(centrePoint, halfsize, yawPitchRoll);
        vFilter.SetInverted(inverted);
        cam = Camera.main;
        if (cam == null)
        {
            return;
        }
        vdkCameraOptions optionsContainer = null;

        optionsContainer = cam.GetComponent <vdkCameraOptions>();
        if (optionsContainer != null)
        {
            optionsContainer.optionsStruct.options.pFilter = this.vFilter.pQueryFilter;
        }
    }
Ejemplo n.º 2
0
 void StopRendering()
 {
     if (cam != null)
     {
         vdkCameraOptions opts = cam.GetComponent <vdkCameraOptions>();
         if (opts != null)
         {
             opts.optionsStruct.options.pFilter = IntPtr.Zero;
         }
     }
 }
Ejemplo n.º 3
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);
        }
    }