Created
February 22, 2020 03:19
-
-
Save Shell64/8d6156213b02541ad28bdb51862452a7 to your computer and use it in GitHub Desktop.
SpriteBatch Vertex Shader GLSL code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 core | |
layout (location = 0) in vec3 VertexPosition; | |
layout (location = 1) in vec2 VertexTexCoord; | |
layout (location = 2) in vec4 VertexColor; | |
int QuadIndexOffsets[6] = int[6](0, 1, 2, 2, 3, 0); | |
vec2 QuadCoords[6] = vec2[6](vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0), vec2(1.0, 1.0), vec2(0.0, 1.0), vec2(0.0, 0.0)); | |
uniform samplerBuffer VertexBuffer; | |
uniform mat4 ProjectionMatrix; | |
out vec2 VaryingTexCoord; | |
out vec4 VaryingColor; | |
void main() | |
{ | |
int QuadID = gl_VertexID / 6; | |
int QuadVertexID = gl_VertexID - 6 * QuadID; | |
int VertexID = QuadID * 4 + QuadIndexOffsets[QuadVertexID]; | |
int BufferIndex = QuadID * 2; | |
vec4 Attributes0 = texelFetch(VertexBuffer, BufferIndex); | |
vec4 Attributes1 = texelFetch(VertexBuffer, BufferIndex + 1); | |
mat3x2 QuadTransform = mat3x2(Attributes0.xy, Attributes0.zw, Attributes1.xy); | |
vec2 QuadCoord = QuadCoords[QuadVertexID]; | |
vec2 Position = QuadTransform * vec3(QuadCoord, 1.0); | |
VaryingTexCoord = QuadCoord; | |
VaryingColor = vec4(Attributes1.w); | |
gl_Position = ProjectionMatrix * vec4(Position.xy, Attributes1.z, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment