Minor fixes and adjustments
This commit is contained in:
@@ -197,7 +197,7 @@ void main() {
|
|||||||
for (int i = 0; i < _DirectionalLightCount; i++) {
|
for (int i = 0; i < _DirectionalLightCount; i++) {
|
||||||
Directional_Light light = _DirectionalLights[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;
|
vec3 incomingRadiance = light.color;
|
||||||
|
|
||||||
outgoingRadiance += lightOutgoingRadiance(
|
outgoingRadiance += lightOutgoingRadiance(
|
||||||
|
|||||||
BIN
assets/textures/OcclusionRoughnessMetallic.png
(Stored with Git LFS)
BIN
assets/textures/OcclusionRoughnessMetallic.png
(Stored with Git LFS)
Binary file not shown.
37
src/game.zig
37
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_half_vertical_fov_rad = 0.5 * camera_vertical_fov_deg * std.math.rad_per_deg;
|
||||||
const camera_mouse_sensitivity = 0.0015;
|
const camera_mouse_sensitivity = 0.0015;
|
||||||
|
|
||||||
|
const max_point_lights = 100;
|
||||||
|
const max_directional_lights = 4;
|
||||||
|
|
||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
point_light_buffer = sg.makeBuffer(.{
|
point_light_buffer = sg.makeBuffer(.{
|
||||||
.size = @sizeOf([4]shaders.PointLight),
|
.size = @sizeOf([max_point_lights]shaders.PointLight),
|
||||||
.usage = .{
|
.usage = .{
|
||||||
.stream_update = true,
|
.stream_update = true,
|
||||||
.storage_buffer = true,
|
.storage_buffer = true,
|
||||||
@@ -50,7 +53,7 @@ pub fn init() void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
directional_light_buffer = sg.makeBuffer(.{
|
directional_light_buffer = sg.makeBuffer(.{
|
||||||
.size = @sizeOf([4]shaders.DirectionalLight),
|
.size = @sizeOf([max_directional_lights]shaders.DirectionalLight),
|
||||||
.usage = .{
|
.usage = .{
|
||||||
.stream_update = true,
|
.stream_update = true,
|
||||||
.storage_buffer = true,
|
.storage_buffer = true,
|
||||||
@@ -135,7 +138,7 @@ pub fn update(dt: f32) void {
|
|||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
);
|
);
|
||||||
// zig fmt: on
|
// 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{
|
sg.applyUniforms(shaders.UB_Global_Uniforms_Vertex, sg.asRange(&shaders.GlobalUniformsVertex{
|
||||||
._MatrixWStoVS = matrix_ws_to_vs.asArray(),
|
._MatrixWStoVS = matrix_ws_to_vs.asArray(),
|
||||||
@@ -144,33 +147,45 @@ pub fn update(dt: f32) void {
|
|||||||
|
|
||||||
const point_lights: []const shaders.PointLight = &.{
|
const point_lights: []const shaders.PointLight = &.{
|
||||||
.{
|
.{
|
||||||
.positionWS = .{ 0, 0, 1.62 },
|
.positionWS = .{ 0, 0, 1 },
|
||||||
.color = .{ 11, 11, 10 },
|
.color = .{ 10, 10, 10 },
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.positionWS = .{ -10, 10, 1.62 },
|
.positionWS = .{ -10, 10, 1 },
|
||||||
.color = .{ 5, 0, 0 },
|
.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 },
|
.color = .{ 0, 5, 0 },
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.positionWS = .{ 10, 10, 1.62 },
|
.positionWS = .{ 10, -10, 1 },
|
||||||
.color = .{ 0, 0, 5 },
|
.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(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{
|
sg.applyUniforms(shaders.UB_Global_Uniforms_Fragment, sg.asRange(&shaders.GlobalUniformsFragment{
|
||||||
._MatrixWStoVS = matrix_ws_to_vs.asArray(),
|
._MatrixWStoVS = matrix_ws_to_vs.asArray(),
|
||||||
._AmbientLight = ambient_light.asArray(),
|
._AmbientLight = ambient_light.asArray(),
|
||||||
._PointLightCount = @intCast(point_lights.len),
|
._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;
|
var tile_index: u32 = 0;
|
||||||
while (it.next()) |pos| : (tile_index = (tile_index + 1) % 16) {
|
while (it.next()) |pos| : (tile_index = (tile_index + 1) % 16) {
|
||||||
tiles.draw(pos, .identity, tile_index);
|
tiles.draw(pos, .identity, tile_index);
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ pub fn next(self: *@This()) ?Vector3 {
|
|||||||
next_current = next_current.setZ(next_current.getZ() + self.step.getZ());
|
next_current = next_current.setZ(next_current.getZ() + self.step.getZ());
|
||||||
if (next_current.getZ() > self.max.getZ()) {
|
if (next_current.getZ() > self.max.getZ()) {
|
||||||
self.current = null;
|
self.current = null;
|
||||||
return null;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.current = next_current;
|
self.current = next_current;
|
||||||
return next_current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user