| 1 | | ## VertexShader |
| | 1 | == Vertex Shader |
| | 2 | {{{#!glsl |
| | 3 | #version 450 |
| | 4 | |
| | 5 | #extension GL_ARB_separate_shader_objects : enable |
| | 6 | #extension GL_ARB_shading_language_420pack : enable |
| | 7 | |
| | 8 | layout (location = 0) in vec4 inPos; |
| | 9 | layout (location = 1) in vec2 inUV; |
| | 10 | |
| | 11 | struct Instance |
| | 12 | { |
| | 13 | mat4 model; |
| | 14 | vec4 arrayIndex; |
| | 15 | }; |
| | 16 | |
| | 17 | layout (binding = 0) uniform UBO |
| | 18 | { |
| | 19 | mat4 projection; |
| | 20 | mat4 view; |
| | 21 | Instance instance[8]; |
| | 22 | } ubo; |
| | 23 | |
| | 24 | layout (location = 0) out vec3 outUV; |
| | 25 | |
| | 26 | void main() |
| | 27 | { |
| | 28 | outUV = vec3(inUV, ubo.instance[gl_InstanceIndex].arrayIndex.x); |
| | 29 | mat4 modelView = ubo.view * ubo.instance[gl_InstanceIndex].model; |
| | 30 | gl_Position = ubo.projection * modelView * inPos; |
| | 31 | } |
| | 32 | }}} |
| | 33 | |
| | 34 | == Fragment Shader |
| | 35 | {{{#!glsl |
| | 36 | #version 450 |
| | 37 | |
| | 38 | #extension GL_ARB_separate_shader_objects : enable |
| | 39 | #extension GL_ARB_shading_language_420pack : enable |
| | 40 | |
| | 41 | layout (binding = 1) uniform sampler2DArray samplerArray; |
| | 42 | |
| | 43 | layout (location = 0) in vec3 inUV; |
| | 44 | |
| | 45 | layout (location = 0) out vec4 outFragColor; |
| | 46 | |
| | 47 | void main() |
| | 48 | { |
| | 49 | outFragColor = texture(samplerArray, inUV); |
| | 50 | } |
| | 51 | }}} |