コード例 #1
0
        void AsyncDone(UnityEngine.Rendering.AsyncGPUReadbackRequest request)
        {
            var   pixels = request.GetData <Color>();
            Color c;

            if (false) //TEXTURE
            {
                var x = (int)((ViewportGazePoint.x) * rect.width);
                var y = (int)((ViewportGazePoint.y) * rect.height);

                //Debug.Log(x + " " + y);

                debugtex.SetPixels(pixels.ToArray());
                //debugtex.Apply(); //EXPENSIVE BUT OK FOR DEBBUGING

                depthR = debugtex.GetPixel(x, y).r;
            }
            else //PIXEL
            {
                depthR = pixels[0].r;
                c      = pixels[0];
            }

            var   wg          = gaze.GetWorldGazeDirection();
            float actualDepth = GetAdjustedDistance(GameplayReferences.HMDCameraComponent.farClipPlane, wg, GameplayReferences.HMD.forward);

            float actualDistance = Mathf.Lerp(GameplayReferences.HMDCameraComponent.nearClipPlane, actualDepth, depthR);

            if (actualDistance > GameplayReferences.HMDCameraComponent.farClipPlane * 2)
            {
                Debug.DrawRay(GameplayReferences.HMD.position, ViewportRay.direction * 100, Color.blue, 100.1f); //with adjustment
                return;
            }

            if (actualDistance > GameplayReferences.HMDCameraComponent.farClipPlane * 0.99f)
            {
                Debug.DrawRay(GameplayReferences.HMD.position, ViewportRay.direction * 100, Color.cyan, 100.1f); //with adjustment
                return;
            }

            depthR *= GameplayReferences.HMDCameraComponent.farClipPlane;

            Debug.DrawRay(GameplayReferences.HMD.position, ViewportRay.direction * actualDistance, Color.magenta, 100.1f); //with adjustment

            //SEEMS MORE CORRECT WHEN LOOKING IN CENTER
            Debug.DrawRay(GameplayReferences.HMD.position, ViewportRay.direction * depthR, new Color(1, 1, 1, 0.5f), 100.1f); //depth without accounting for difference from farclip and angle

            //TODO when using eye tracking, use 'actualDistance'

            Vector3 world = ViewportRay.origin + ViewportRay.direction * depthR;

            onPostRenderCommand.Invoke(ViewportRay, ViewportRay.direction * depthR, world);
        }
        static internal void Lua_System_Action_1_UnityEngine_Rendering_AsyncGPUReadbackRequest(LuaFunction ld, UnityEngine.Rendering.AsyncGPUReadbackRequest a1)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            ld.pcall(1, error);
            LuaDLL.lua_settop(l, error - 1);
        }