コード例 #1
0
        private void Render()
        {
            _target.ClearAll();

            _modelPipeline.Apply();
            _camera.Step();
            _vsConstant.Value = _camera.GetViewProjectionMatrix();
            _vsConstant.Update();

            for (int pass = 0; pass < 5; ++pass)
            {
                _gsConstant.Value.EdgeIndex = (uint)pass;
                _gsConstant.Update();
                for (int i = 0; i < Model.PartCount; ++i)
                {
                    Model.GetPart(i).DrawAll();
                }
            }

            {
                var point2D = _camera.WorldPosToControl(new Vector3(-20, -25, 45));
                _spriteDebug.Apply();
                _spriteDebug.DrawString(_spriteFont, "X", point2D.X, point2D.Y, 1000);
            }

            _device.Present(true);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: acaly/LightDx
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget(Color.White.WithAlpha(1)));
                target.Apply();

                var sprite  = new Sprite(device);
                var guiFont = new TextureFontCache(device, SystemFonts.DefaultFont);

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();

                    sprite.Apply();
                    sprite.DrawString(guiFont, "Hello World!", 0, 0, 800);

                    device.Present(true);
                });
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: acaly/LightDx
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget(), device.CreateDepthStencilTarget());
                target.Apply();

                Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                           ShaderSource.FromResource("Shader.fx", ShaderType.Vertex | ShaderType.Pixel));
                pipeline.Apply();

                var vertexConstant = pipeline.CreateConstantBuffer <Matrix4x4>();
                pipeline.SetConstant(ShaderType.Vertex, 0, vertexConstant);

                var input      = pipeline.CreateVertexDataProcessor <Vertex>();
                var bufferData = new Vertex[6 * 6];
                for (int i = 0; i < bufferData.Length; ++i)
                {
                    bufferData[i].Color = Color.FromArgb(250, i / 6 * 40, 250 - i / 6 * 30).WithAlpha(1);
                }
                SetupCubeFace(bufferData, 00, new Vector3(0.5f, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0));
                SetupCubeFace(bufferData, 06, new Vector3(-0.5f, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1));
                SetupCubeFace(bufferData, 12, new Vector3(0, 0.5f, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1));
                SetupCubeFace(bufferData, 18, new Vector3(0, -0.5f, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0));
                SetupCubeFace(bufferData, 24, new Vector3(0, 0, 0.5f), new Vector3(0, 1, 0), new Vector3(1, 0, 0));
                SetupCubeFace(bufferData, 30, new Vector3(0, 0, -0.5f), new Vector3(1, 0, 0), new Vector3(0, 1, 0));
                var buffer = input.CreateImmutableBuffer(bufferData);

                var camera = new Camera(new Vector3(10, 0, 0));
                camera.SetForm(form);
                var proj = device.CreatePerspectiveFieldOfView((float)Math.PI / 4).Transpose();

                vertexConstant.Value = proj * camera.GetViewMatrix();
                var pt = new Vector4(0, 0, 0, 0);
                var r  = Vector4.Transform(pt, vertexConstant.Value);

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();

                    camera.Step();
                    vertexConstant.Value = proj * camera.GetViewMatrix();
                    vertexConstant.Update();

                    buffer.DrawAll();
                    device.Present(true);
                });
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: acaly/LightDx
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget());
                target.Apply();

                Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                           ShaderSource.FromResource("Shader.fx", ShaderType.Vertex | ShaderType.Pixel));
                pipeline.Apply();

                var input  = pipeline.CreateVertexDataProcessor <Vertex>();
                var buffer = input.CreateImmutableBuffer(new[] {
                    new Vertex {
                        Color = 0, Position = new Vector4(0.0f, 0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        Color = 1, Position = new Vector4(0.5f, -0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        Color = 2, Position = new Vector4(-0.5f, -0.5f, 0.5f, 1.0f)
                    },
                });

                var indexBuffer = pipeline.CreateImmutableIndexBuffer(new uint[] { 2, 0, 1 });

                var srBuffer = pipeline.CreateShaderResourceBuffer(new[]
                {
                    Color.Blue.WithAlpha(1),
                    Color.Red.WithAlpha(1),
                    Color.Green.WithAlpha(1),
                }, false);
                pipeline.SetResource(ShaderType.Vertex, 0, srBuffer);

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();
                    indexBuffer.DrawAll(buffer);
                    device.Present(true);
                });
            }
        }
コード例 #5
0
ファイル: DeferredTarget.cs プロジェクト: acaly/MMDRenderer
 public void ClearAll() => _renderTarget1.ClearAll();
コード例 #6
0
ファイル: Program.cs プロジェクト: acaly/RandomRock
        static void Main()
        {
            const float BlockSize = 0.02f;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            var func          = MakeFunction(1 / BlockSize);
            var meshGenerator = new DCSolver(func, (int)(4 / BlockSize));
            var rawMesh       = meshGenerator.Solve();

            rawMesh = new MeshSimplifier(rawMesh, ClusterSizeHelper.GetSampleAverage(rawMesh, 3)).Run();
            var m = NormalMesh.MakeNormal(rawMesh);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget(Color.AliceBlue.WithAlpha(1)), device.CreateDepthStencilTarget());
                target.Apply();

                Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                           ShaderSource.FromResource("Viewer.Shader.fx", ShaderType.Vertex | ShaderType.Pixel));
                pipeline.Apply();

                var vertexConstant = pipeline.CreateConstantBuffer <Matrix4x4>();
                pipeline.SetConstant(ShaderType.Vertex, 0, vertexConstant);

                var input = pipeline.CreateVertexDataProcessor <Vertex>();
                var vb    = input.CreateImmutableBuffer(m.Vertices.Select(vv => new Vertex {
                    Position = new Vector4(m.Positions[vv.Position] * BlockSize, 1),
                    Normal   = new Vector4(vv.Normal, 0),
                }).ToArray());

                var ib = pipeline.CreateImmutableIndexBuffer(m.Triangles.SelectMany(tt => new[] { tt.Va, tt.Vb, tt.Vc }).ToArray());

                var camera = new Camera(new Vector3(10, 0, 0));
                camera.SetForm(form);
                var proj = device.CreatePerspectiveFieldOfView((float)Math.PI / 4).Transpose();

                vertexConstant.Value = proj * camera.GetViewMatrix();
                var pt = new Vector4(0, 0, 0, 0);
                var r  = Vector4.Transform(pt, vertexConstant.Value);

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();

                    camera.Step();
                    var view             = camera.GetViewMatrix();
                    vertexConstant.Value = proj * view;
                    vertexConstant.Update();

                    ib.DrawAll(vb);
                    device.Present(true);
                });
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: acaly/LightDx
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget());
                target.Apply();

                Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                           ShaderSource.FromResource("Shader.fx", ShaderType.Vertex | ShaderType.Pixel));
                pipeline.Apply();

                var inputGroup = pipeline.CreateVertexDataProcessors(new[] {
                    typeof(VertexP),
                    typeof(VertexC),
                });
                var input1 = inputGroup.GetVertexDataProcessor <VertexP>();
                var input2 = inputGroup.GetVertexDataProcessor <VertexC>();

                var buffer1       = input1.CreateDynamicBuffer(3);
                var vertexPosData = new[] {
                    new VertexP {
                        Position = new Vector4(0, 0, 0.5f, 1)
                    },
                    new VertexP {
                        Position = new Vector4(0, 0, 0.5f, 1)
                    },
                    new VertexP {
                        Position = new Vector4(0, 0, 0.5f, 1)
                    },
                };
                var buffer2 = input2.CreateImmutableBuffer(new[] {
                    new VertexC {
                        Color = Color.Green.WithAlpha(1)
                    },
                    new VertexC {
                        Color = Color.Red.WithAlpha(1)
                    },
                    new VertexC {
                        Color = Color.Blue.WithAlpha(1)
                    },
                });
                var bufferGroup = new[] { buffer1, buffer2 };

                var indexBuffer = pipeline.CreateImmutableIndexBuffer(new uint[] { 0, 1, 2 });

                var constantBuffer = pipeline.CreateConstantBuffer <ConstantBuffer>();
                pipeline.SetConstant(ShaderType.Vertex, 0, constantBuffer);
                pipeline.SetConstant(ShaderType.Pixel, 0, constantBuffer);

                constantBuffer.Value.GlobalAlpha = new Vector4(1, 1, 1, 1);

                form.Show();

                var i    = 0;
                var rand = new Random();

                var clock = Stopwatch.StartNew();
                device.RunMultithreadLoop(delegate()
                {
                    var angle    = -clock.Elapsed.TotalSeconds * Math.PI / 3;
                    var distance = Math.PI * 2 / 3;

                    SetCoordinate(device, ref vertexPosData[0].Position, angle);
                    SetCoordinate(device, ref vertexPosData[1].Position, angle - distance);
                    SetCoordinate(device, ref vertexPosData[2].Position, angle + distance);
                    buffer1.Update(vertexPosData);

                    constantBuffer.Value.Time = ((float)clock.Elapsed.TotalSeconds % 2) / 2;

                    if (++i == 60)
                    {
                        i = 0;
                        constantBuffer.Value.GlobalAlpha.X = (float)rand.NextDouble() * 0.5f + 0.5f;
                        constantBuffer.Value.GlobalAlpha.Y = (float)rand.NextDouble() * 0.5f + 0.5f;
                        constantBuffer.Value.GlobalAlpha.Z = (float)rand.NextDouble() * 0.5f + 0.5f;
                    }
                    constantBuffer.Update();

                    target.ClearAll();
                    indexBuffer.DrawAll(inputGroup, bufferGroup);

                    device.Present(true);
                });
            }
        }
コード例 #8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget());
                target.Apply();

                Pipeline pipeline = device.CompilePipeline(InputTopology.Triangle,
                                                           ShaderSource.FromResource("Shader.fx", ShaderType.Vertex | ShaderType.Pixel));

                Texture2D texture;
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TextureTriangle.Hiyori.png"))
                {
                    using (var bitmap = new Bitmap(stream))
                    {
                        texture = device.CreateTexture2D(bitmap);
                        pipeline.SetResource(0, texture);
                    }
                }

                pipeline.Apply();

                var input  = pipeline.CreateVertexDataProcessor <Vertex>();
                var buffer = input.CreateImmutableBuffer(new[] {
                    new Vertex {
                        TexCoord = new Vector4(0, 0, 0, 0), Position = new Vector4(-0.5f, 0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(0.5f, 0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(-0.5f, -0.5f, 0.5f, 1.0f)
                    },

                    new Vertex {
                        TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(-0.5f, -0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(0.5f, 0.5f, 0.5f, 1.0f)
                    },
                    new Vertex {
                        TexCoord = new Vector4(1, 1, 0, 0), Position = new Vector4(0.5f, -0.5f, 0.5f, 1.0f)
                    },
                });

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();
                    buffer.DrawAll();
                    device.Present(true);
                });
            }
        }
コード例 #9
0
 public void ClearAll()
 {
     _target.ClearAll();
 }