diff --git a/assets/shaders.glsl b/assets/shaders.glsl index 3e778c8..1d0b153 100644 --- a/assets/shaders.glsl +++ b/assets/shaders.glsl @@ -197,7 +197,7 @@ void main() { for (int i = 0; i < _DirectionalLightCount; i++) { Directional_Light light = _DirectionalLights[i]; - vec3 lightDirectionVS = normalize((_MatrixWStoVS * vec4(light.directionWS, 0.0)).xyz); + vec3 lightDirectionVS = normalize((_MatrixWStoVS * vec4(-light.directionWS, 0.0)).xyz); vec3 incomingRadiance = light.color; outgoingRadiance += lightOutgoingRadiance( diff --git a/assets/textures/OcclusionRoughnessMetallic.png b/assets/textures/OcclusionRoughnessMetallic.png index 07cdc0e..9cc2b05 100644 --- a/assets/textures/OcclusionRoughnessMetallic.png +++ b/assets/textures/OcclusionRoughnessMetallic.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8005badc07c0e9cfb93071d6a5dd6291f8b00210a86fdbf8434490b0ed90cf82 -size 370 +oid sha256:a2efc715c451e398ac820800040d0edd4a704dda68c0592583c1d839516fe4a5 +size 120 diff --git a/src/game.zig b/src/game.zig index c101523..62e70f9 100644 --- a/src/game.zig +++ b/src/game.zig @@ -37,9 +37,12 @@ const camera_vertical_fov_deg = 90.0; const camera_half_vertical_fov_rad = 0.5 * camera_vertical_fov_deg * std.math.rad_per_deg; const camera_mouse_sensitivity = 0.0015; +const max_point_lights = 100; +const max_directional_lights = 4; + pub fn init() void { point_light_buffer = sg.makeBuffer(.{ - .size = @sizeOf([4]shaders.PointLight), + .size = @sizeOf([max_point_lights]shaders.PointLight), .usage = .{ .stream_update = true, .storage_buffer = true, @@ -50,7 +53,7 @@ pub fn init() void { }); directional_light_buffer = sg.makeBuffer(.{ - .size = @sizeOf([4]shaders.DirectionalLight), + .size = @sizeOf([max_directional_lights]shaders.DirectionalLight), .usage = .{ .stream_update = true, .storage_buffer = true, @@ -135,7 +138,7 @@ pub fn update(dt: f32) void { 0, 0, 0, 0, ); // zig fmt: on - const ambient_light = Vector3.init(0, 0, 0); + const ambient_light = Vector3.init(0.3, 0.3, 0.3); sg.applyUniforms(shaders.UB_Global_Uniforms_Vertex, sg.asRange(&shaders.GlobalUniformsVertex{ ._MatrixWStoVS = matrix_ws_to_vs.asArray(), @@ -144,33 +147,45 @@ pub fn update(dt: f32) void { const point_lights: []const shaders.PointLight = &.{ .{ - .positionWS = .{ 0, 0, 1.62 }, - .color = .{ 11, 11, 10 }, + .positionWS = .{ 0, 0, 1 }, + .color = .{ 10, 10, 10 }, }, .{ - .positionWS = .{ -10, 10, 1.62 }, + .positionWS = .{ -10, 10, 1 }, .color = .{ 5, 0, 0 }, }, .{ - .positionWS = .{ 0, 10, 1.62 }, + .positionWS = .{ 10, 10, 1 }, + .color = .{ 0, 0, 5 }, + }, + .{ + .positionWS = .{ -10, -10, 1 }, .color = .{ 0, 5, 0 }, }, .{ - .positionWS = .{ 10, 10, 1.62 }, - .color = .{ 0, 0, 5 }, + .positionWS = .{ 10, -10, 1 }, + .color = .{ 5, 5, 0 }, + }, + }; + + const directional_lights: []const shaders.DirectionalLight = &.{ + .{ + .directionWS = .{ 0, 0, -1 }, + .color = .{ 0.2, 0.2, 0.2 }, }, }; sg.updateBuffer(point_light_buffer, sg.asRange(point_lights)); + sg.updateBuffer(directional_light_buffer, sg.asRange(directional_lights)); sg.applyUniforms(shaders.UB_Global_Uniforms_Fragment, sg.asRange(&shaders.GlobalUniformsFragment{ ._MatrixWStoVS = matrix_ws_to_vs.asArray(), ._AmbientLight = ambient_light.asArray(), ._PointLightCount = @intCast(point_lights.len), - ._DirectionalLightCount = 0, + ._DirectionalLightCount = @intCast(directional_lights.len), })); - var it = Iterator3.init(.init(-10, -10, 0), .init(10, 10, 0), .one); + var it = Iterator3.init(.init(-8, -8, 0), .init(8, 8, 0), .one); var tile_index: u32 = 0; while (it.next()) |pos| : (tile_index = (tile_index + 1) % 16) { tiles.draw(pos, .identity, tile_index); diff --git a/src/math/Iterator3.zig b/src/math/Iterator3.zig index 0a51f14..fbc5975 100644 --- a/src/math/Iterator3.zig +++ b/src/math/Iterator3.zig @@ -28,11 +28,11 @@ pub fn next(self: *@This()) ?Vector3 { next_current = next_current.setZ(next_current.getZ() + self.step.getZ()); if (next_current.getZ() > self.max.getZ()) { self.current = null; - return null; + return current; } } } self.current = next_current; - return next_current; + return current; }