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