示例#1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                m_Device.Init(panelOutput.Handle, false, true);
            }
            catch (Exception _e)
            {
                m_Device = null;
                MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Project 4D Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            m_CS_Simulator = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Simulator.hlsl")), "CS", null);
            m_CS_Project4D = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Project4D.hlsl")), "CS", null);
            m_PS_Display   = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Display.hlsl")), VERTEX_FORMAT.T2, "VS", null, "PS", null);

            m_CB_Camera     = new ConstantBuffer <CB_Camera>(m_Device, 1);
            m_CB_Camera4D   = new ConstantBuffer <CB_Camera4D>(m_Device, 2);
            m_CB_Simulation = new ConstantBuffer <CB_Simulation>(m_Device, 3);

            {
                VertexT2[] Vertices = new VertexT2[4] {
                    new VertexT2()
                    {
                        UV = new float2(-1.0f, 1.0f)
                    },
                    new VertexT2()
                    {
                        UV = new float2(-1.0f, -1.0f)
                    },
                    new VertexT2()
                    {
                        UV = new float2(1.0f, 1.0f)
                    },
                    new VertexT2()
                    {
                        UV = new float2(1.0f, -1.0f)
                    },
                };
                m_PrimQuad = new Primitive(m_Device, 4, VertexT2.FromArray(Vertices), null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.T2);
            }

            /////////////////////////////////////////////////////////////////////////////////////
            // Create and fill the structured buffers with initial points lying on the surface of a hypersphere
            m_SB_Velocities4D = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true);
            m_SB_Points4D[0]  = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true);
            m_SB_Points4D[1]  = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true);
            m_SB_Points2D     = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, false);

            buttonInit_Click(buttonInit, EventArgs.Empty);

            /////////////////////////////////////////////////////////////////////////////////////
            // Setup camera
            m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 10.0f);
            m_Manipulator.Attach(panelOutput, m_Camera);
            m_Manipulator.InitializeCamera(new float3(0, 0, 2), new float3(0, 0, 0), float3.UnitY);
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();

            m_Device = new Device();
            m_Device.Init(panel1.Handle, false, false);

            m_Shader_RenderCellPlanes      = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellPlanes.hlsl"), VERTEX_FORMAT.T2, "VS", null, "PS", null);
            m_Shader_RenderCellMesh        = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellMesh.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS", null);
            m_Shader_RenderCellMesh_Opaque = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellMesh_Opaque.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS", null);
            m_Shader_PostProcess           = new Shader(m_Device, new System.IO.FileInfo("Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null);
            m_Shader_PostProcess2          = new Shader(m_Device, new System.IO.FileInfo("Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null);

            VertexT2[] Vertices = new VertexT2[4] {
                new VertexT2()
                {
                    UV = new float2(0, 0)
                },
                new VertexT2()
                {
                    UV = new float2(0, 1)
                },
                new VertexT2()
                {
                    UV = new float2(1, 0)
                },
                new VertexT2()
                {
                    UV = new float2(1, 1)
                },
            };
            m_Prim_Quad = new Primitive(m_Device, 4, VertexT2.FromArray(Vertices), null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.T2);


            m_RT_WorldPositions[0] = new Texture2D(m_Device, (uint)panel1.Width, (uint)panel1.Height, 1, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.AUTO, false, false, null);
            m_RT_WorldPositions[1] = new Texture2D(m_Device, (uint)panel1.Width, (uint)panel1.Height, 1, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.AUTO, false, false, null);
            m_Device.Clear(m_RT_WorldPositions[0], float4.Zero);
            m_Device.Clear(m_RT_WorldPositions[1], float4.Zero);

            // Setup camera
            m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 0);
            m_CB_Mesh   = new ConstantBuffer <CB_Mesh>(m_Device, 1);

            m_Camera.CreatePerspectiveCamera(120.0f * (float)Math.PI / 180.0f, (float)panel1.Width / panel1.Height, 0.01f, 100.0f);
            m_Camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged);

            m_CameraManipulator.Attach(panel1, m_Camera);
            m_CameraManipulator.InitializeCamera(-0.1f * float3.UnitZ, float3.Zero, float3.UnitY);

            // Initalize random neighbors
            integerTrackbarControlNeighborsCount_ValueChanged(integerTrackbarControlNeighborsCount, 0);

            Application.Idle += new EventHandler(Application_Idle);
        }