Exemple #1
0
        public IrregularPentagon(IrregularPentagon parent, int number)
        {
            if (number < 0 || number > 4)
            {
                throw new ArgumentException($"Номер соседа должен быть в диапазоне [0;4], не {number}");
            }

            ModelMatrix = Matrix4x4.CreateTranslation(0, (float)R * 2, 0) *
                          Matrix4x4.CreateRotationZ((float)AngleBb) *
                          parent.ModelMatrix;
        }
Exemple #2
0
        private static void CreateResources()
        {
            _instanceCount = 5;

            ResourceFactory factory = _graphicsDevice.ResourceFactory;

            _vertexBuffer = factory.CreateBuffer(
                new BufferDescription(IrregularPentagon.VerticesCount * VertexPositionColor.SizeInBytes,
                                      BufferUsage.VertexBuffer));
            _indexBuffer = factory.CreateBuffer(
                new BufferDescription(IrregularPentagon.IndicesCount * sizeof(ushort),
                                      BufferUsage.IndexBuffer));
            _projMatrixBuffer = factory.CreateBuffer(
                new BufferDescription(sizeof(float) * 4 * 4,
                                      BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            _projMatrixBuffer.Name = "Projection Buffer";
            _modelMatrixBuffer     = factory.CreateBuffer(
                new BufferDescription(sizeof(float) * 4 * 4,
                                      BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            _modelMatrixBuffer.Name = "Model Buffer";


            _graphicsDevice.UpdateBuffer(_vertexBuffer, 0, IrregularPentagon.Vertices);
            _graphicsDevice.UpdateBuffer(_indexBuffer, 0, IrregularPentagon.Indices);

            ViewProjectionUpdate();

            VertexLayoutDescription vertexLayout = new VertexLayoutDescription(
                new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate,
                                             VertexElementFormat.Float2),
                new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate,
                                             VertexElementFormat.Float4));

            _layout = factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    new ResourceLayoutElementDescription("ViewProjectionMatrix", ResourceKind.UniformBuffer, ShaderStages.Vertex),
                    new ResourceLayoutElementDescription("ModelMatrix", ResourceKind.UniformBuffer, ShaderStages.Vertex)));


            ShaderDescription vertexShaderDesc = new ShaderDescription(ShaderStages.Vertex,
                                                                       Resources.VertexShader,
                                                                       "main");
            ShaderDescription fragmentShaderDesc = new ShaderDescription(ShaderStages.Fragment,
                                                                         Resources.FragmentShader,
                                                                         "main");

            _shaders = factory.CreateFromSpirv(vertexShaderDesc, fragmentShaderDesc);


            VertexLayoutDescription vertexLayoutPerInstance = new VertexLayoutDescription(
                new VertexElementDescription("InstanceCoord", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float1));

            vertexLayoutPerInstance.InstanceStepRate = 1;

            _instanceVB = factory.CreateBuffer(new BufferDescription(sizeof(float) * _instanceCount, BufferUsage.VertexBuffer));
            float[] infos = new float[_instanceCount];


            for (uint i = 0; i < _instanceCount; i++)
            {
                infos[i] = i / 0.1f;
            }

            _graphicsDevice.UpdateBuffer(_instanceVB, 0, infos);

            GraphicsPipelineDescription pipelineDescription = new GraphicsPipelineDescription
            {
                BlendState        = BlendStateDescription.SingleAlphaBlend,
                DepthStencilState = new DepthStencilStateDescription(
                    true,
                    true,
                    ComparisonKind.LessEqual),
                RasterizerState = new RasterizerStateDescription(
                    FaceCullMode.Back,
                    PolygonFillMode.Solid,
                    FrontFace.Clockwise,
                    true,
                    false),
                PrimitiveTopology = PrimitiveTopology.TriangleStrip,
                ResourceLayouts   = new [] { _layout },
                ShaderSet         = new ShaderSetDescription(new[] { vertexLayout, vertexLayoutPerInstance }, _shaders),
                Outputs           = _graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
            };

            _pipeline = factory.CreateGraphicsPipeline(pipelineDescription);

            _mainResourceSet = factory.CreateResourceSet(new ResourceSetDescription(_layout,
                                                                                    _projMatrixBuffer, _modelMatrixBuffer));

            _commandList = factory.CreateCommandList();

            var firstPentagon  = new IrregularPentagon();
            var secondPentagon = new IrregularPentagon(firstPentagon, 0);

            _pentagons.Add(firstPentagon);
            _pentagons.Add(secondPentagon);
        }