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