Example #1
0
        void OnPostRender()
        {
            Camera camera = GetComponent <Camera>();

            int  width           = camera.pixelWidth;
            int  height          = camera.pixelHeight;
            bool resizedViewport = m_currentWidth != 0 && m_currentWidth != width || m_currentHeight != 0 && m_currentHeight != height;

            m_currentWidth  = width;
            m_currentHeight = height;

            HVRViewportInterface viewport = FlipViewport();

            viewport.SetViewMatrix(camera.worldToCameraMatrix);
            viewport.SetProjMatrix(GL.GetGPUProjectionMatrix(camera.projectionMatrix, false));
            viewport.SetNearFarPlane(camera.nearClipPlane, camera.farClipPlane);
            viewport.SetDimensions(0, 0, width, height);
            viewport.SetFrameBuffer(null);
            HvrStaticInterface.Self().RenderCamera(null, viewport, resizedViewport);
        }
Example #2
0
        void OnPreRender()
        {
            if (CheckResources() == false)
            {
                return;
            }

            CommandBuffer_Validate();

            Camera cam = GetComponent <Camera>();

            //Viewport Settings
            viewportSizeMultiplier = Mathf.Clamp(viewportSizeMultiplier, viewportSizeMin, viewportSizeMax);

            viewportSettings.width  = Mathf.RoundToInt((float)cam.pixelWidth * viewportSizeMultiplier);
            viewportSettings.height = Mathf.RoundToInt((float)cam.pixelHeight * viewportSizeMultiplier);

            viewport = renderInterface.FlipViewport();
            viewport.SetViewMatrix(cam.worldToCameraMatrix);
            viewport.SetProjMatrix(GL.GetGPUProjectionMatrix(cam.projectionMatrix, false));
            viewport.SetNearFarPlane(cam.nearClipPlane, cam.farClipPlane);
            viewport.SetDimensions(0, 0, viewportSettings.width, viewportSettings.height);
            bool resizedViewport = viewport.frameBuffer.Resize(viewportSettings.width, viewportSettings.height);

            if (resizedViewport)
            {
                CommandBuffer_Remove(activeCameraEvent);
            }

            // Render viewport
            HvrStaticInterface.Self().RenderCamera(this, viewport, resizedViewport);

            HvrColorGrading colorGrading = GameObject.FindObjectOfType <HvrColorGrading>();

            if (colorGrading != null)
            {
                if (colorGradedTexture == null || colorGradedTexture.width != viewportSettings.width || colorGradedTexture.height != viewportSettings.height)
                {
                    if (colorGradedTexture)
                    {
                        colorGradedTexture.Release();
                    }

                    colorGradedTexture = new RenderTexture(viewportSettings.width, viewportSettings.height, 0);
                }

                colorGrading.DoGrade(viewport.frameBuffer.renderColourBuffer, colorGradedTexture);
            }
            else
            {
                if (colorGradedTexture != null)
                {
                    colorGradedTexture.Release();
                    colorGradedTexture = null;
                }
            }

            switch (compositeMethod)
            {
            case CompositeMethods.commandBuffer:
                // Command Buffer
                commandBuffer_material.SetTexture("_oCOL", colorGradedTexture ? colorGradedTexture : viewport.frameBuffer.renderColourBuffer);
                commandBuffer_material.SetTexture("_oDEP", viewport.frameBuffer.renderDepthBuffer);

                Matrix4x4 inverseProjection = (cam.projectionMatrix.inverse);
                commandBuffer_material.SetMatrix("_ProjectInverse", inverseProjection);

                Matrix4x4 inverseViewProjection = (cam.projectionMatrix * cam.worldToCameraMatrix).inverse;
                commandBuffer_material.SetMatrix("_ViewProjectInverse", inverseViewProjection);

                commandBuffer_material.SetInt("g_hdr", cam.hdr ? 1 : 0);
                break;

            default:
                break;
            }
        }