Exemplo n.º 1
0
    void Start()
    {
        // return if sqgraphic not init
        if (SqGraphicManager.Instance == null)
        {
            enabled = false;
            return;
        }

        // one instance only
        if (instance != null)
        {
            enabled = false;
            return;
        }

        instance    = this;
        attachedCam = GetComponent <Camera>();
        attachedCam.renderingPath = RenderingPath.Forward; // currently only fw is implement
        attachedCam.cullingMask   = 0;                     // draw nothing
        attachedCam.allowHDR      = true;                  // force hdr mode

        CreateRenderTarget();
        CreateCameraData();
        lastMsaaSample = msaaSample;
    }
Exemplo n.º 2
0
    void Update()
    {
        int instanceID = attachedCam.GetInstanceID();

        SetRenderMode(instanceID, Mathf.Clamp((int)renderMode, 0, (int)RenderMode.ForwardPass));

        // check aa change
        if (lastMsaaSample != msaaSample)
        {
            RemoveCamera(instanceID);
            OnDestroy();
            Start();
            ResetPipelineState();
            SqGraphicManager.Instance.resetingFrame = true;
        }

        // update VP matrix
        Matrix4x4 projRendering = GL.GetGPUProjectionMatrix(attachedCam.projectionMatrix, true);
        Matrix4x4 projCulling   = GL.GetGPUProjectionMatrix(attachedCam.projectionMatrix, false);
        Matrix4x4 invView       = attachedCam.worldToCameraMatrix.inverse; // didn't be the same as CameraToWorldMatrix, this is bullshit lol

        SetViewProjMatrix(instanceID,
                          attachedCam.worldToCameraMatrix,
                          projRendering,
                          projCulling,
                          invView,
                          projRendering.inverse,
                          transform.position, transform.forward, attachedCam.farClipPlane, attachedCam.nearClipPlane);

        Rect     viewRect = attachedCam.pixelRect;
        ViewPort vp;

        vp.TopLeftX = viewRect.xMin;
        vp.TopLeftY = viewRect.yMin;
        vp.Width    = viewRect.width;
        vp.Height   = viewRect.height;
        vp.MinDepth = 0f;
        vp.MaxDepth = 1f;

        RawRect rr;

        rr.left   = 0;
        rr.top    = 0;
        rr.right  = (int)viewRect.width;
        rr.bottom = (int)viewRect.height;

        SetViewPortScissorRect(instanceID, vp, rr);
        lastMsaaSample = msaaSample;
    }