Example #1
0
        private void CreateShaderModules()
        {
            this.vertShader = ShanqShader.CreateVertexModule(this.device,
                                                             shanq => from input in shanq.GetInput <Vertex>()
                                                             select new VertexOutput {
                Colour   = input.Colour,
                Position = new vec4(input.Position, 0, 1)
            });

            this.fragShader = ShanqShader.CreateFragmentModule(this.device,
                                                               shanq => from input in shanq.GetInput <FragmentInput>()
                                                               select new FragmentOutput {
                Colour = new vec4(input.Colour, 1)
            });
        }
Example #2
0
        private void CreateShaderModules()
        {
            this.vertShader = ShanqShader.CreateVertexModule(this.device,
                                                             shanq => from input in shanq.GetInput <Vertex>()
                                                             from ubo in shanq.GetBinding <UniformBufferObject>()
                                                             let transform = ubo.Proj * ubo.View * ubo.Model
                                                                             select new VertexOutput {
                Position = transform * new vec4(input.Position, 0, 1),
                Colour   = input.Colour
            });

            this.fragShader = ShanqShader.CreateFragmentModule(this.device,
                                                               shanq => from input in shanq.GetInput <FragmentInput>()
                                                               from ubo in shanq.GetBinding <UniformBufferObject>()
                                                               let colour = new vec4(input.Colour, 1)
                                                                            select new FragmentOutput {
                Colour = colour
            });
        }
Example #3
0
 public static ShaderModule CreateVertexModule <TOutput>(this Device device, Func <IShanqFactory, IQueryable <TOutput> > shaderFunction, string entryPointName = ShanqShader.DefaultModuleEntryPoint)
 {
     return(ShanqShader.CreateVertexModule(device, VectorTypeLibrary.Instance, shaderFunction, entryPointName));
 }
Example #4
0
 public static ShaderModule CreateVertexModule <TOutput>(this Device device, Func <IShanqFactory, IQueryable <TOutput> > shaderFunction)
 {
     return(ShanqShader.CreateVertexModule(device, VectorTypeLibrary.Instance, shaderFunction));
 }
Example #5
0
        private void CreateGraphicsPipeline()
        {
            var vertShader = ShanqShader.CreateVertexModule(this.device,
                                                            shanq => from input in shanq.GetInput <Vertex>()
                                                            from ubo in shanq.GetBinding <UniformBufferObject>()
                                                            let transform = ubo.Proj * ubo.View * ubo.Model
                                                                            select new VertexOutput
            {
                Position = transform * new vec4(input.Position, 0, 1),
                Colour   = input.Colour
            });

            var fragShader = ShanqShader.CreateFragmentModule(this.device,
                                                              shanq => from input in shanq.GetInput <FragmentInput>()
                                                              from ubo in shanq.GetBinding <UniformBufferObject>()
                                                              let colour = new vec4(input.Colour, 1)
                                                                           select new FragmentOutput
            {
                Colour = colour
            });

            var bindingDescription    = Vertex.GetBindingDescription();
            var attributeDescriptions = Vertex.GetAttributeDescriptions();

            this.pipelineLayout = device.CreatePipelineLayout(new PipelineLayoutCreateInfo()
            {
                SetLayouts = new[]
                {
                    this.descriptorSetLayout
                }
            });

            this.pipeline = device.CreateGraphicsPipelines(null, new[]
            {
                new GraphicsPipelineCreateInfo
                {
                    Layout           = this.pipelineLayout,
                    RenderPass       = this.renderPass,
                    Subpass          = 0,
                    VertexInputState = new PipelineVertexInputStateCreateInfo()
                    {
                        VertexBindingDescriptions   = new [] { bindingDescription },
                        VertexAttributeDescriptions = attributeDescriptions
                    },
                    InputAssemblyState = new PipelineInputAssemblyStateCreateInfo
                    {
                        PrimitiveRestartEnable = false,
                        Topology = PrimitiveTopology.TriangleList
                    },
                    ViewportState = new PipelineViewportStateCreateInfo
                    {
                        Viewports = new[]
                        {
                            new Viewport
                            {
                                X        = 0f,
                                Y        = 0f,
                                Width    = this.swapChainExtent.Width,
                                Height   = this.swapChainExtent.Height,
                                MaxDepth = 1,
                                MinDepth = 0
                            }
                        },
                        Scissors = new[]
                        {
                            new Rect2D
                            {
                                Offset = new Offset2D(),
                                Extent = this.swapChainExtent
                            }
                        }
                    },
                    RasterizationState = new PipelineRasterizationStateCreateInfo
                    {
                        DepthClampEnable        = false,
                        RasterizerDiscardEnable = false,
                        PolygonMode             = PolygonMode.Fill,
                        LineWidth       = 1,
                        CullMode        = CullModeFlags.Back,
                        FrontFace       = FrontFace.CounterClockwise,
                        DepthBiasEnable = false
                    },
                    MultisampleState = new PipelineMultisampleStateCreateInfo
                    {
                        SampleShadingEnable  = false,
                        RasterizationSamples = SampleCountFlags.SampleCount1,
                        MinSampleShading     = 1
                    },
                    ColorBlendState = new PipelineColorBlendStateCreateInfo
                    {
                        Attachments = new[]
                        {
                            new PipelineColorBlendAttachmentState
                            {
                                ColorWriteMask = ColorComponentFlags.R
                                                 | ColorComponentFlags.G
                                                 | ColorComponentFlags.B
                                                 | ColorComponentFlags.A,
                                BlendEnable                 = false,
                                SourceColorBlendFactor      = BlendFactor.One,
                                DestinationColorBlendFactor = BlendFactor.Zero,
                                ColorBlendOp                = BlendOp.Add,
                                SourceAlphaBlendFactor      = BlendFactor.One,
                                DestinationAlphaBlendFactor = BlendFactor.Zero,
                                AlphaBlendOp                = BlendOp.Add
                            }
                        },
                        LogicOpEnable  = false,
                        LogicOp        = LogicOp.Copy,
                        BlendConstants = new float[] { 0, 0, 0, 0 }
                    },
                    Stages = new[]
                    {
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Vertex,
                            Module = vertShader,
                            Name   = "main"
                        },
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Fragment,
                            Module = fragShader,
                            Name   = "main"
                        }
                    }
                }
            }).Single();
        }