179 lines
4.8 KiB
GLSL
179 lines
4.8 KiB
GLSL
// Instanced quad shader
|
|
|
|
#type vertex
|
|
#version 450 core
|
|
|
|
layout(location = 0) in mat4 a_Transform;
|
|
layout(location = 4) in vec4 a_Color;
|
|
layout(location = 5) in float a_TexIndex;
|
|
layout(location = 6) in float a_TilingFactor;
|
|
layout(location = 7) in int a_ObjectID;
|
|
|
|
// Camera uniform buffer (binding = 0)
|
|
layout(std140, binding = 0) uniform CameraData
|
|
{
|
|
mat4 u_ViewProjection;
|
|
mat4 u_View;
|
|
mat4 u_Projection;
|
|
vec3 u_CameraPosition;
|
|
};
|
|
|
|
out vec4 v_Color;
|
|
out vec2 v_TexCoord;
|
|
out float v_TilingFactor;
|
|
flat out float v_TexIndex;
|
|
flat out int v_ObjectID;
|
|
|
|
const vec3 s_Positions[4] = vec3[](
|
|
vec3(-0.5, -0.5, 0.0),
|
|
vec3(0.5, -0.5, 0.0),
|
|
vec3(0.5, 0.5, 0.0),
|
|
vec3(-0.5, 0.5, 0.0));
|
|
|
|
const vec2 s_TexCoords[4] = vec2[](
|
|
vec2(0.0, 0.0),
|
|
vec2(1.0, 0.0),
|
|
vec2(1.0, 1.0),
|
|
vec2(0.0, 1.0));
|
|
|
|
void main()
|
|
{
|
|
int vertexIndex = gl_VertexID % 4;
|
|
vec4 worldPosition = a_Transform * vec4(s_Positions[vertexIndex], 1.0);
|
|
|
|
v_Color = a_Color;
|
|
v_TexCoord = s_TexCoords[vertexIndex];
|
|
v_TilingFactor = a_TilingFactor;
|
|
v_TexIndex = a_TexIndex;
|
|
v_ObjectID = a_ObjectID;
|
|
|
|
gl_Position = u_ViewProjection * worldPosition;
|
|
}
|
|
|
|
#type fragment
|
|
#version 450 core
|
|
|
|
layout(location = 0) out vec4 o_Color;
|
|
layout(location = 1) out int o_ObjectID;
|
|
|
|
in vec4 v_Color;
|
|
in vec2 v_TexCoord;
|
|
in float v_TilingFactor;
|
|
flat in float v_TexIndex;
|
|
flat in int v_ObjectID;
|
|
|
|
uniform sampler2D u_Textures[32];
|
|
|
|
void main()
|
|
{
|
|
vec4 texColor = v_Color;
|
|
|
|
switch (int(v_TexIndex))
|
|
{
|
|
case 0:
|
|
texColor *= texture(u_Textures[0], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 1:
|
|
texColor *= texture(u_Textures[1], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 2:
|
|
texColor *= texture(u_Textures[2], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 3:
|
|
texColor *= texture(u_Textures[3], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 4:
|
|
texColor *= texture(u_Textures[4], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 5:
|
|
texColor *= texture(u_Textures[5], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 6:
|
|
texColor *= texture(u_Textures[6], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 7:
|
|
texColor *= texture(u_Textures[7], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 8:
|
|
texColor *= texture(u_Textures[8], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 9:
|
|
texColor *= texture(u_Textures[9], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 10:
|
|
texColor *= texture(u_Textures[10], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 11:
|
|
texColor *= texture(u_Textures[11], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 12:
|
|
texColor *= texture(u_Textures[12], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 13:
|
|
texColor *= texture(u_Textures[13], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 14:
|
|
texColor *= texture(u_Textures[14], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 15:
|
|
texColor *= texture(u_Textures[15], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 16:
|
|
texColor *= texture(u_Textures[16], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 17:
|
|
texColor *= texture(u_Textures[17], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 18:
|
|
texColor *= texture(u_Textures[18], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 19:
|
|
texColor *= texture(u_Textures[19], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 20:
|
|
texColor *= texture(u_Textures[20], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 21:
|
|
texColor *= texture(u_Textures[21], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 22:
|
|
texColor *= texture(u_Textures[22], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 23:
|
|
texColor *= texture(u_Textures[23], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 24:
|
|
texColor *= texture(u_Textures[24], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 25:
|
|
texColor *= texture(u_Textures[25], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 26:
|
|
texColor *= texture(u_Textures[26], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 27:
|
|
texColor *= texture(u_Textures[27], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 28:
|
|
texColor *= texture(u_Textures[28], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 29:
|
|
texColor *= texture(u_Textures[29], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 30:
|
|
texColor *= texture(u_Textures[30], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
case 31:
|
|
texColor *= texture(u_Textures[31], v_TexCoord * v_TilingFactor);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (texColor.a == 0.0)
|
|
discard;
|
|
|
|
o_Color = texColor;
|
|
o_ObjectID = v_ObjectID;
|
|
}
|