94 lines
2.1 KiB
GLSL
94 lines
2.1 KiB
GLSL
#type vertex
|
|
#version 450 core
|
|
|
|
layout(location = 0) in vec3 a_Position;
|
|
layout(location = 1) in vec4 a_Color;
|
|
layout(location = 2) in vec3 a_Normal;
|
|
layout(location = 3) in vec2 a_TexCoord;
|
|
layout(location = 4) in int a_EntityID;
|
|
|
|
layout(std140, binding = 0) uniform Camera
|
|
{
|
|
mat4 u_ViewProjection;
|
|
vec3 u_ViewPosition;
|
|
};
|
|
|
|
layout(std140, binding = 1) uniform Transform
|
|
{
|
|
mat4 u_Transform;
|
|
};
|
|
|
|
struct VertexOutput
|
|
{
|
|
vec4 Color;
|
|
vec2 TexCoord;
|
|
vec3 Normal;
|
|
vec3 ViewPos;
|
|
};
|
|
|
|
layout (location = 0) out VertexOutput Output;
|
|
layout (location = 4) out flat int v_EntityID;
|
|
layout (location = 5) out vec4 v_Pos;
|
|
|
|
void main()
|
|
{
|
|
Output.Color = a_Color;
|
|
Output.TexCoord = a_TexCoord;
|
|
Output.Normal = mat3(transpose(inverse(u_Transform))) * a_Normal;
|
|
Output.ViewPos = u_ViewPosition;
|
|
|
|
v_EntityID = a_EntityID;
|
|
|
|
v_Pos = u_Transform * vec4(a_Position, 1.0);
|
|
gl_Position = u_ViewProjection * v_Pos;
|
|
}
|
|
|
|
#type fragment
|
|
#version 450 core
|
|
|
|
layout (location = 0) out vec4 color;
|
|
layout (location = 1) out int color2;
|
|
|
|
struct VertexOutput
|
|
{
|
|
vec4 Color;
|
|
vec2 TexCoord;
|
|
vec3 Normal;
|
|
vec3 ViewPos;
|
|
};
|
|
|
|
layout (location = 0) in VertexOutput Input;
|
|
layout (location = 4) in flat int v_EntityID;
|
|
layout (location = 5) in vec4 v_Pos;
|
|
|
|
void main()
|
|
{
|
|
vec3 lightPos = vec3(0.0f, 1.0f, 0.0f);
|
|
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
|
|
|
|
// Ambiant lighting
|
|
float ambientStrength = 0.8;
|
|
vec3 ambient = ambientStrength * lightColor;
|
|
|
|
// Diffuse lighting
|
|
vec3 norm = normalize(Input.Normal);
|
|
vec3 lightDir = normalize(lightPos - v_Pos.xyz);
|
|
|
|
float diff = max(dot(norm, lightDir), 0.0);
|
|
vec3 diffuse = diff * lightColor;
|
|
|
|
// Specular highlight
|
|
float specularStrength = 0.5;
|
|
vec3 viewDir = normalize(Input.ViewPos - v_Pos.xyz); // .xyz here too
|
|
vec3 reflectDir = reflect(-lightDir, norm);
|
|
|
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
|
vec3 specular = specularStrength * spec * lightColor;
|
|
|
|
vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
|
|
|
|
// Output
|
|
color = vec4(result, 1.0); // vec3 → vec4
|
|
color2 = v_EntityID;
|
|
}
|