1 module sbylib.graphics.material.standard.color;
2 
3 import sbylib.graphics.material.standard.material;
4 import sbylib.graphics.material.standard.renderpass;
5 
6 class ColorMaterial : Material {
7 
8     mixin RenderPass!(StandardRenderPass);
9 
10     mixin ShaderSource!(ShaderStage.Vertex, q{
11         #version 450
12         layout (location = 0) in vec3 position;
13 
14         layout (binding = 0) uniform UniformData {
15             mat4 worldMatrix;
16             mat4 viewMatrix;
17             mat4 projectionMatrix;
18         } uni;
19 
20         void main() {
21             gl_Position = uni.projectionMatrix * uni.viewMatrix * uni.worldMatrix * vec4(position, 1);
22             gl_Position.y = -gl_Position.y;
23         }
24     });
25 
26     mixin ShaderSource!(ShaderStage.Fragment, q{
27         #version 450
28         layout (location = 0) out vec4 fragColor;
29 
30         layout (binding = 1) uniform UniformData {
31             vec4 color;
32         } uni;
33 
34         void main() {
35             fragColor = uni.color;
36         }
37     });
38 
39     @vertex struct Vertex {
40         vec3 position;
41     }
42 
43     immutable CreateInfo i = {
44         rasterization: {
45             depthClampEnable: false,
46             rasterizerDiscardEnable: false,
47             polygonMode: PolygonMode.Fill,
48             cullMode: CullMode.None,
49             frontFace: FrontFace.CounterClockwise,
50             depthBiasEnable: false,
51             depthBiasConstantFactor: 0.0f,
52             depthBiasClamp: 0.0f,
53             depthBiasSlopeFactor: 0.0f,
54             lineWidth: 1.0f,
55         },
56         multisample: {
57             rasterizationSamples: SampleCount.Count1,
58             sampleShadingEnable: false,
59             alphaToCoverageEnable: false,
60             alphaToOneEnable: false,
61         },
62         depthStencil: {
63             depthTestEnable: true,
64             depthWriteEnable: true,
65             depthCompareOp: CompareOp.Less,
66         },
67         colorBlend: {
68             logicOpEnable: false,
69             attachments: [{
70                 blendEnable: false,
71                 colorWriteMask: ColorComponent.R
72                               | ColorComponent.G
73                               | ColorComponent.B
74                               | ColorComponent.A,
75             }]
76         }
77     };
78     mixin Info!i;
79 
80     struct VertexUniform {
81         mat4 worldMatrix;
82         mat4 viewMatrix;
83         mat4 projectionMatrix;
84     }
85 
86     struct FragmentUniform {
87         vec4 color;
88     }
89 
90     @uniform @binding(0) @stage(ShaderStage.Vertex) VertexUniform vertexUniform;
91     @uniform @binding(1) @stage(ShaderStage.Fragment) FragmentUniform fragmentUniform;
92 
93     mixin MaxObjects!(10);
94 
95     mixin Instance;
96 }