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