public void SendToCuda()
 {
     CudaUtil.SendCamera(
         position.x, position.y, position.z,
         rotation.imaginaryPart.x, rotation.imaginaryPart.y, rotation.imaginaryPart.z, rotation.realPart,
         fov, aspectRatio, viewDistance, (int)Sampler.regular);
 }
        private void MainWnd_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Escape:
                WorkFlowUtil.FinalizeApplication();
                Application.Exit();
                break;

            case Keys.F:
                DebugLogger.Text = DirectX12_Test.MainWnd().ToString();
                break;

            case Keys.I:
                if (commonInfo.isInitialized)
                {
                    DebugLogger.Text = "Scene已经初始化过了!";
                }
                else
                {
                    WorkFlowUtil.InitializeScene(ref commonInfo);
                    commonInfo.isInitialized = true;

                    DebugLogger.Text = "Scene初始化成功!";
                }
                break;

            case Keys.T:
                DebugLogger.Text = CudaUtil.test().ToString();
                break;
            }
        }
        public static void InitializeScene(ref CommonInfo commonInfo)//该函数初始化的时候只执行一次,是按下I键后启动
        {
            CudaUtil.OpenDebugConsole();

            CudaUtil.InitializeResources(CommonInfo.Width, CommonInfo.Heght, 64);

            CudaUtil.AddBufferMap(commonInfo.frame_buffer0_data.Scan0);
            CudaUtil.AddBufferMap(commonInfo.frame_buffer1_data.Scan0);
            CudaUtil.AddBufferMap(commonInfo.picking_buffer_data.Scan0);

            commonInfo.frameBuffer0.UnlockBits(commonInfo.frame_buffer0_data);
            commonInfo.frameBuffer1.UnlockBits(commonInfo.frame_buffer1_data);
            commonInfo.pickingBuffer.UnlockBits(commonInfo.picking_buffer_data);

            Point3[] points = new Point3[3];
            points[0] = new Point3(-1.0f, 0.0f, -15.0f);
            points[1] = new Point3(1.0f, 0.0f, -15.0f);
            points[2] = new Point3(0.5f, 1.0f, -15.0f);

            Point2[] uv = new Point2[3];
            uv[0] = new Point2(0.0f, 0.0f);
            uv[1] = new Point2(1.0f, 0.0f);
            uv[2] = new Point2(0.5f, 1.0f);

            //CudaUtil.AddTriangle(Color.White, points, uv);
            CudaUtil.AddSphere(new Point3(0.0f, 0.0f, -5.0f), Color.White, 2.0f);
            CudaUtil.AddSphere(new Point3(4.0f, 0.0f, -5.0f), Color.White, 2.0f);
            CudaUtil.AddPlane(new Point3(0.0f, -2.0f, 0.0f), Color.White, new Normal(0.0f, 1.0f, 0.0f));

            CudaUtil.AddTexture("C:\\Users\\Hordr\\source\\repos\\CavakazeRenderer\\CavakazeRenderer\\bin\\Debug\\Textures\\albedo.png");
            CudaUtil.AddTexture("C:\\Users\\Hordr\\source\\repos\\CavakazeRenderer\\CavakazeRenderer\\bin\\Debug\\Textures\\normal.png");
            CudaUtil.AddTexture("C:\\Users\\Hordr\\source\\repos\\CavakazeRenderer\\CavakazeRenderer\\bin\\Debug\\Textures\\metallic.png");
            CudaUtil.AddTexture("C:\\Users\\Hordr\\source\\repos\\CavakazeRenderer\\CavakazeRenderer\\bin\\Debug\\Textures\\roughness.png");
            CudaUtil.AddTexture("C:\\Users\\Hordr\\source\\repos\\CavakazeRenderer\\CavakazeRenderer\\bin\\Debug\\Textures\\ao.png");
            CudaUtil.GenerateTextureList();
            CudaUtil.SetPrimitiveDesinyPBRMaterial(0, 0, 1, 2, 3, 4);
            CudaUtil.SetPrimitiveDesinyPBRMaterial(1, 0, 1, 2, 3, 4);
            CudaUtil.SetPrimitiveDesinyPBRMaterial(2, 0, 1, 2, 3, 4);
            CudaUtil.GenerateScene();
        }
        private void MainWnd_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (commonInfo.isInitialized)
                {
                    commonInfo.currentMouseX = e.X;
                    commonInfo.currentMouseY = e.Y;

                    commonInfo.accumulatedX += commonInfo.currentMouseX - commonInfo.lastMouseX;
                    commonInfo.accumulatedY += commonInfo.currentMouseY - commonInfo.lastMouseY;

                    commonInfo.lastMouseX = commonInfo.currentMouseX;
                    commonInfo.lastMouseY = commonInfo.currentMouseY;

                    //DebugLogger.Text = "X坐标: " + commonInfo.accumulatedX.ToString() + "Y坐标: " + commonInfo.accumulatedY.ToString();

                    commonInfo.scene.camera.Update(ref commonInfo);

                    CudaUtil.SendCamera(commonInfo.scene.camera);
                    WorkFlowUtil.Update(ref commonInfo);
                    switch (commonInfo.swampIdx)
                    {
                    case false: BackgroundImage = commonInfo.frameBuffer1; break;

                    case true: BackgroundImage = commonInfo.frameBuffer0; break;
                    }
                    WorkFlowUtil.RenderScene(ref commonInfo);
                    DebugLogger.Text = commonInfo.DebugInfo;
                }
                else
                {
                    DebugLogger.Text = "Scene还未初始化!还不能进行渲染,请按下I键进行初始化!";
                }
            }
        }
        public static void RenderScene(ref CommonInfo commonInfo)//该函数也是在拖拽住鼠标的时候每一帧执行一次,顺序是在Update函数执行完毕的时候才会执行这个函数
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            switch (commonInfo.swampIdx)
            {
            case false:
                CudaUtil.RenderScene(0, 2);
                break;

            case true:
                CudaUtil.RenderScene(1, 2);
                break;
            }

            commonInfo.swampIdx = !commonInfo.swampIdx;
            stopwatch.Stop();
            TimeSpan timeSpan     = stopwatch.Elapsed;
            double   totalSeconds = timeSpan.TotalSeconds;
            double   FPS          = 1 / totalSeconds;

            commonInfo.DebugInfo = " Render Overhead: " + totalSeconds.ToString();
        }
 public override void AddToCuda()
 {
     CudaUtil.AddPlane(centre, materialColor, normal);
 }
 public override void AddToCuda()
 {
     CudaUtil.AddTriangle(materialColor, points, uv);
 }
 public override void AddToCuda()
 {
     CudaUtil.AddSphere(centre, materialColor, radius);
 }
 public static void FinalizeApplication()
 {
     CudaUtil.FreeResources();
 }