improved model loading and added model component

This commit is contained in:
Erris
2026-03-09 16:37:30 +01:00
parent ac18bb6f00
commit a0c900166f
15 changed files with 486 additions and 146 deletions

View File

@@ -2,10 +2,8 @@
#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(location = 1) in vec3 a_Normal;
layout(location = 2) in vec2 a_TexCoord;
layout(std140, binding = 0) uniform Camera
{
@@ -20,25 +18,20 @@ layout(std140, binding = 1) uniform 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;
}
@@ -49,9 +42,22 @@ void main()
layout (location = 0) out vec4 color;
layout (location = 1) out int color2;
layout (std140, binding = 2) uniform Material
{
vec4 u_Albedo;
float u_Roughness;
float u_Metallic;
float u_AmbientStrength;
float u_SpecularStrength;
};
layout(std140, binding = 3) uniform EditorID
{
int u_EntityID;
};
struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
vec3 Normal;
vec3 ViewPos;
@@ -67,8 +73,7 @@ void main()
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
// Ambiant lighting
float ambientStrength = 0.8;
vec3 ambient = ambientStrength * lightColor;
vec3 ambient = lightColor * u_AmbientStrength;
// Diffuse lighting
vec3 norm = normalize(Input.Normal);
@@ -78,16 +83,19 @@ void main()
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;
float shininess = mix(2.0, 256.0, 1.0 - u_Roughness);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
vec3 specularColor = mix(vec3(1.0), u_Albedo.rgb, u_Metallic);
vec3 specular = u_SpecularStrength * spec * lightColor * specularColor;
vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
// Total
//vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
vec3 result = (ambient + diffuse + specular) * u_Albedo.rgb; // objectColor → Input.Color.rgb
// Output
color = vec4(result, 1.0); // vec3 → vec4
color2 = v_EntityID;
color = vec4(result, u_Albedo.w); // vec3 → vec4
color2 = u_EntityID;
}