Fixed normal transformation

This commit is contained in:
Lorenzo Torres 2025-08-06 17:51:03 +02:00
parent defdf051ec
commit 8b5f33ee3f
4 changed files with 9 additions and 7 deletions

View file

@ -32,6 +32,7 @@ void main() {
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
vec3 specular = lightSpecular * spec * vec3(texture(diffuseSampler, TexCoords));
//vec3 specular = lightSpecular * spec * vec3(1.0, 1.0, 1.0);
vec3 result = (ambient + diffuse + specular);
outColor = vec4(result, 1.0);

View file

@ -25,8 +25,9 @@ layout(location = 4) out vec2 TexCoords;
void main() {
mat4 transformation = transform.translation * transform.scale * transform.rotation;
vec4 out_vec = proj.proj * view.view * transformation * vec4(vertPos, 1.0);
FragPos = vec3(vec4(vertPos, 1.0));
Normal = normal;
FragPos = vec3(transformation * vec4(vertPos, 1.0));
Normal = mat3(transpose(inverse(transformation))) * normal;
TexCoords = uv;
gl_Position = vec4(out_vec.x, out_vec.y, out_vec.z, out_vec.w);
gl_Position = out_vec;
}

View file

@ -53,8 +53,8 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
_ = try graphics_pipeline.addTexture(device, texture, diffuse);
graphics_pipeline.light_pos[0] = 0.0;
graphics_pipeline.light_pos[1] = 2.0;
graphics_pipeline.light_pos[0] = -10.0;
graphics_pipeline.light_pos[1] = 0.0;
graphics_pipeline.light_pos[2] = 0.0;
return Renderer{
@ -69,7 +69,7 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
// TODO: Why are we storing the buffer and not the Mesh?
.vertex_buffer = triangle.vertex_buffer,
.index_buffer = triangle.index_buffer,
.transform = math.Transform.init(.{0.0, 0.0, 0.0}, .{1.0, 1.0, 1.0}, .{0.0, math.rad(45.0), 0.0}),
.transform = math.Transform.init(.{0.0, 0.0, 0.0}, .{1.0, 1.0, 1.0}, .{0.0, 0.0, 0.0}),
.previous_time = try std.time.Instant.now(),
};
}

View file

@ -46,7 +46,7 @@ fn init_mods() void {
export fn sideros_init(init: api.GameInit) callconv(.c) void {
resources = .{
.camera = .{
.position = .{ 5.0, 5.0, 5.0 },
.position = .{ -5.0, 5.0, -5.0 },
.target = .{ 0.0, 0.0, 0.0 },
},
.renderer = undefined,