Files
Hazel/Sandbox/assets/shaders/Renderer2D_quad.glsl
2025-07-09 17:56:51 +08:00

68 lines
1.4 KiB
GLSL

// Basic quad Texture Shader
#type vertex
#version 450 core
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec4 a_Color;
layout(location = 2) in vec2 a_TexCoord;
layout(location = 3) in float a_TexIndex;
layout(location = 4) in float a_TilingFactor;
layout(location = 5) in int a_EntityID;
layout(std140, binding = 0) uniform Camera
{
mat4 u_ViewProjection;
};
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
layout (location = 0) out VertexOutput Output;
layout (location = 3) out flat float v_TexIndex;
layout (location = 4) out flat int v_EntityID;
void main()
{
Output.Color = a_Color;
Output.TexCoord = a_TexCoord;
Output.TilingFactor = a_TilingFactor;
v_TexIndex = a_TexIndex;
v_EntityID = a_EntityID;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}
#type fragment
#version 450 core
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID;
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TilingFactor;
};
layout (location = 0) in VertexOutput Input;
layout (location = 3) in flat float v_TexIndex;
layout (location = 4) in flat int v_EntityID;
layout (binding = 0) uniform sampler2D u_Textures[32];
void main()
{
o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color;
if(o_Color.a == 0.0f)
discard;
o_EntityID = v_EntityID;
}