Fixed normal transformation
This commit is contained in:
parent
defdf051ec
commit
8b5f33ee3f
4 changed files with 9 additions and 7 deletions
|
|
@ -32,6 +32,7 @@ void main() {
|
||||||
vec3 reflectDir = reflect(-lightDir, norm);
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
|
||||||
vec3 specular = lightSpecular * spec * vec3(texture(diffuseSampler, TexCoords));
|
vec3 specular = lightSpecular * spec * vec3(texture(diffuseSampler, TexCoords));
|
||||||
|
//vec3 specular = lightSpecular * spec * vec3(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
vec3 result = (ambient + diffuse + specular);
|
vec3 result = (ambient + diffuse + specular);
|
||||||
outColor = vec4(result, 1.0);
|
outColor = vec4(result, 1.0);
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ layout(location = 4) out vec2 TexCoords;
|
||||||
void main() {
|
void main() {
|
||||||
mat4 transformation = transform.translation * transform.scale * transform.rotation;
|
mat4 transformation = transform.translation * transform.scale * transform.rotation;
|
||||||
vec4 out_vec = proj.proj * view.view * transformation * vec4(vertPos, 1.0);
|
vec4 out_vec = proj.proj * view.view * transformation * vec4(vertPos, 1.0);
|
||||||
FragPos = vec3(vec4(vertPos, 1.0));
|
FragPos = vec3(transformation * vec4(vertPos, 1.0));
|
||||||
Normal = normal;
|
|
||||||
|
Normal = mat3(transpose(inverse(transformation))) * normal;
|
||||||
TexCoords = uv;
|
TexCoords = uv;
|
||||||
gl_Position = vec4(out_vec.x, out_vec.y, out_vec.z, out_vec.w);
|
gl_Position = out_vec;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
|
||||||
|
|
||||||
_ = try graphics_pipeline.addTexture(device, texture, diffuse);
|
_ = try graphics_pipeline.addTexture(device, texture, diffuse);
|
||||||
|
|
||||||
graphics_pipeline.light_pos[0] = 0.0;
|
graphics_pipeline.light_pos[0] = -10.0;
|
||||||
graphics_pipeline.light_pos[1] = 2.0;
|
graphics_pipeline.light_pos[1] = 0.0;
|
||||||
graphics_pipeline.light_pos[2] = 0.0;
|
graphics_pipeline.light_pos[2] = 0.0;
|
||||||
|
|
||||||
return Renderer{
|
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?
|
// TODO: Why are we storing the buffer and not the Mesh?
|
||||||
.vertex_buffer = triangle.vertex_buffer,
|
.vertex_buffer = triangle.vertex_buffer,
|
||||||
.index_buffer = triangle.index_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(),
|
.previous_time = try std.time.Instant.now(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ fn init_mods() void {
|
||||||
export fn sideros_init(init: api.GameInit) callconv(.c) void {
|
export fn sideros_init(init: api.GameInit) callconv(.c) void {
|
||||||
resources = .{
|
resources = .{
|
||||||
.camera = .{
|
.camera = .{
|
||||||
.position = .{ 5.0, 5.0, 5.0 },
|
.position = .{ -5.0, 5.0, -5.0 },
|
||||||
.target = .{ 0.0, 0.0, 0.0 },
|
.target = .{ 0.0, 0.0, 0.0 },
|
||||||
},
|
},
|
||||||
.renderer = undefined,
|
.renderer = undefined,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue