diff --git a/src/foundations/assets/Obj.zig b/src/foundations/assets/Obj.zig index 43796cc..b6f29bf 100644 --- a/src/foundations/assets/Obj.zig +++ b/src/foundations/assets/Obj.zig @@ -2,7 +2,7 @@ data: []u8 = undefined, file_name: []const u8 = undefined, vertices: [max_vertices][3]f32 = undefined, texture_coordinates: [max_vertices][2]f32 = undefined, -normals: [max_vertices][3]f32 = undefined, +normal: [max_vertices][3]f32 = undefined, num_vertices: usize = 0, indicies: [max_indicies][3][3]usize = undefined, num_indicies: usize = 0, @@ -39,7 +39,7 @@ pub fn init(self: *Obj, _: std.mem.Allocator, data: []u8, file_name: []const u8) const x: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); const y: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); const z: f32 = std.fmt.parseFloat(f32, nit.next() orelse "") catch @panic("invalid float"); - self.normals[n_index] = .{ x, y, z }; + self.normal[n_index] = .{ x, y, z }; n_index += 1; }, else => { @@ -80,7 +80,7 @@ pub fn toObject(self: *Obj, prog: u32, i_datas: []rhi.instanceData) object.objec const p = self.vertices[index_data[j][0]]; attribute_data[current_index] = .{ .position = p, - .normals = self.normals[index_data[j][2]], + .normal = self.normal[index_data[j][2]], .texture_coords = self.texture_coordinates[index_data[j][1]], }; indices[current_index] = @intCast(current_index); diff --git a/src/foundations/assets/loader.zig b/src/foundations/assets/loader.zig index eaa2714..8a493bf 100644 --- a/src/foundations/assets/loader.zig +++ b/src/foundations/assets/loader.zig @@ -1,5 +1,5 @@ const app_name: []const u8 = "foundations_game_engine"; -pub const max_file_size: usize = 4096 << 11; +pub const max_file_size: usize = 4096 << 12; pub const LoaderError = error{ FileNotFound, diff --git a/src/foundations/object/ObjectCircle.zig b/src/foundations/object/ObjectCircle.zig index d4fba62..f6198e4 100644 --- a/src/foundations/object/ObjectCircle.zig +++ b/src/foundations/object/ObjectCircle.zig @@ -18,7 +18,7 @@ pub fn init( rhi_data[i] = .{ .position = d.positions[i], .color = .{ 1, 0, 1, 1 }, - .normals = .{ 1, 0, 0 }, + .normal = .{ 1, 0, 0 }, }; } const vao_buf = rhi.attachInstancedBuffer(rhi_data[0..], instance_data); diff --git a/src/foundations/object/ObjectCone.zig b/src/foundations/object/ObjectCone.zig index aedd0c4..9213940 100644 --- a/src/foundations/object/ObjectCone.zig +++ b/src/foundations/object/ObjectCone.zig @@ -50,17 +50,17 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu const tri = math.geometry.Triangle.init(p0, p1, p2); attribute_data[offset + 0] = .{ .position = tri.p0, - .normals = tri.normal, + .normal = tri.normal, }; indices[offset + 0] = uoffset + 0; attribute_data[uoffset + 1] = .{ .position = tri.p1, - .normals = tri.normal, + .normal = tri.normal, }; indices[offset + 1] = uoffset + 1; attribute_data[uoffset + 2] = .{ .position = tri.p2, - .normals = tri.normal, + .normal = tri.normal, }; indices[offset + 2] = uoffset + 2; offset += 3; diff --git a/src/foundations/object/ObjectCube.zig b/src/foundations/object/ObjectCube.zig index dbee37c..40c947e 100644 --- a/src/foundations/object/ObjectCube.zig +++ b/src/foundations/object/ObjectCube.zig @@ -59,7 +59,7 @@ pub const default_positions: [36][3]f32 = .{ .{ -1, 1, -1 }, }; -pub const normals: [36][3]f32 = .{ +pub const normal: [36][3]f32 = .{ // z pos .{ 0, 0, 1 }, .{ 0, 0, 1 }, @@ -120,7 +120,7 @@ pub fn init( data[i] = .{ .position = positions[i], .color = color, - .normals = normals[i], + .normal = normal[i], }; } const vao_buf = rhi.attachBuffer(data[0..]); diff --git a/src/foundations/object/ObjectCylinder.zig b/src/foundations/object/ObjectCylinder.zig index 2c028d9..ee8c7ab 100644 --- a/src/foundations/object/ObjectCylinder.zig +++ b/src/foundations/object/ObjectCylinder.zig @@ -6,7 +6,7 @@ const Cylinder = @This(); const num_sides = 160; const num_vertices: usize = 4 * num_sides; -const num_indices: usize = 6 * num_sides; // because normals +const num_indices: usize = 6 * num_sides; // because normal pub fn init( program: u32, @@ -114,22 +114,22 @@ fn addSurface( s_data[offset] = .{ .position = sp0, .color = color.debug_color, - .normals = n, + .normal = n, }; s_data[offset + 1] = .{ .position = sp1, .color = color.debug_color, - .normals = n, + .normal = n, }; s_data[offset + 2] = .{ .position = sp2, .color = color.debug_color, - .normals = n, + .normal = n, }; s_data[offset + 3] = .{ .position = sp3, .color = color.debug_color, - .normals = n, + .normal = n, }; return offset + 4; } diff --git a/src/foundations/object/ObjectInstancedTriangle.zig b/src/foundations/object/ObjectInstancedTriangle.zig index 3af26be..7d00f13 100644 --- a/src/foundations/object/ObjectInstancedTriangle.zig +++ b/src/foundations/object/ObjectInstancedTriangle.zig @@ -18,15 +18,15 @@ pub fn init( const triangle = math.geometry.Triangle.init(p0, p1, p2); attribute_data[0] = .{ .position = triangle.p0, - .normals = triangle.normal, + .normal = triangle.normal, }; attribute_data[1] = .{ .position = triangle.p1, - .normals = triangle.normal, + .normal = triangle.normal, }; attribute_data[2] = .{ .position = triangle.p2, - .normals = triangle.normal, + .normal = triangle.normal, }; const indices: [3]u32 = .{ 0, 1, 2 }; diff --git a/src/foundations/object/ObjectParallelepiped.zig b/src/foundations/object/ObjectParallelepiped.zig index 0e5a3d7..835bc81 100644 --- a/src/foundations/object/ObjectParallelepiped.zig +++ b/src/foundations/object/ObjectParallelepiped.zig @@ -7,7 +7,7 @@ indices: [num_indices]u32, const Parallelepied = @This(); const num_vertices: usize = 24; -const num_indices: usize = 36; // because normals +const num_indices: usize = 36; // because normal pub const pp: math.geometry.Parallelepiped = .{ .v0 = .{ 1, 0, 0 }, @@ -246,25 +246,25 @@ fn addSurface( s_data[offset] = .{ .position = sp0, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = tc1, }; s_data[offset + 1] = .{ .position = sp1, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = tc2, }; s_data[offset + 2] = .{ .position = sp2, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = tc3, }; s_data[offset + 3] = .{ .position = sp3, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = tc4, }; return offset + 4; diff --git a/src/foundations/object/ObjectPyramid.zig b/src/foundations/object/ObjectPyramid.zig index 978e473..b0a34f2 100644 --- a/src/foundations/object/ObjectPyramid.zig +++ b/src/foundations/object/ObjectPyramid.zig @@ -115,19 +115,19 @@ fn addSurface( s_data[offset] = .{ .position = sp0, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[0], }; s_data[offset + 1] = .{ .position = sp1, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[1], }; s_data[offset + 2] = .{ .position = sp2, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[2], }; return offset + 3; @@ -167,25 +167,25 @@ fn addBottomSurface( s_data[offset] = .{ .position = sp0, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[0], }; s_data[offset + 1] = .{ .position = sp1, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[1], }; s_data[offset + 2] = .{ .position = sp2, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[2], }; s_data[offset + 3] = .{ .position = sp3, .color = color.debug_color, - .normals = n, + .normal = n, .texture_coords = texture_coords[3], }; return offset + 4; diff --git a/src/foundations/object/ObjectQuad.zig b/src/foundations/object/ObjectQuad.zig index 5157919..02596d8 100644 --- a/src/foundations/object/ObjectQuad.zig +++ b/src/foundations/object/ObjectQuad.zig @@ -81,7 +81,7 @@ pub fn initInstanced( rhi_data[i] = .{ .position = positions[i], .color = .{ 1, 0, 1, 1 }, - .normals = .{ 1, 0, 0 }, + .normal = .{ 1, 0, 0 }, }; } const vao_buf = rhi.attachInstancedBuffer(rhi_data[0..], instance_data); diff --git a/src/foundations/object/ObjectSphere.zig b/src/foundations/object/ObjectSphere.zig index f00df47..6e297d7 100644 --- a/src/foundations/object/ObjectSphere.zig +++ b/src/foundations/object/ObjectSphere.zig @@ -3,20 +3,33 @@ vertex_data_size: usize, instance_data_stride: usize, const Sphere = @This(); -const precision: usize = 48; -const precision_f: f32 = @floatFromInt(precision); -const num_vertices = (precision + 1) * (precision + 1); -const num_indices = precision * precision * 6; +const default_precision: usize = 48; +const max_precision: usize = 250; +const max_num_vertices = (max_precision + 1) * (max_precision + 1); +const max_num_indices = max_precision * max_precision * 6; pub fn init( program: u32, instance_data: []rhi.instanceData, wireframe: bool, ) Sphere { - var d = data(); + return initWithPrecision(program, instance_data, wireframe, default_precision); +} - const vao_buf = rhi.attachInstancedBuffer(d.attribute_data[0..], instance_data); - const ebo = rhi.initEBO(@ptrCast(d.indices[0..]), vao_buf.vao); +pub fn initWithPrecision( + program: u32, + instance_data: []rhi.instanceData, + wireframe: bool, + precision: usize, +) Sphere { + const num_vertices = (precision + 1) * (precision + 1); + const num_indices = precision * precision * 6; + var attribute_data: [max_num_vertices]rhi.attributeData = undefined; + var indices: [max_num_indices]u32 = undefined; + data(&attribute_data, &indices, precision); + + const vao_buf = rhi.attachInstancedBuffer(attribute_data[0..num_vertices], instance_data); + const ebo = rhi.initEBO(@ptrCast(indices[0..num_indices]), vao_buf.vao); return .{ .mesh = .{ .program = program, @@ -42,11 +55,9 @@ pub fn updateInstanceAt(self: Sphere, index: usize, instance_data: rhi.instanceD rhi.updateInstanceData(self.mesh.buffer, self.vertex_data_size, self.instance_data_stride, index, instance_data); } -fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [num_indices]u32 } { - var attribute_data: [num_vertices]rhi.attributeData = undefined; - var indices: [num_indices]u32 = undefined; - +fn data(attribute_data: []rhi.attributeData, indices: []u32, precision: usize) void { const p_index: usize = precision + 1; + const precision_f: f32 = @floatFromInt(precision); for (0..p_index) |i| { const i_f: f32 = @floatFromInt(i); @@ -60,21 +71,24 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu const pos: [3]f32 = .{ x, y, z }; const index: usize = i * p_index + j; - //TODO: support tangents in vertex attributes - // calculate tangent vector - var tangent: [3]f32 = undefined; + const normal: math.vector.vec3 = .{ x, y, z }; + var tangent: [4]f32 = undefined; if ((math.float.equal_e(x, 1.0) and math.float.equal_e(y, 0.0) and math.float.equal_e(z, 0.0)) or (math.float.equal_e(x, -1.0) and math.float.equal_e(y, 0.0) and math.float.equal_e(z, 0.0))) { - tangent = .{ 0, -1, 0 }; + tangent = .{ 0, 1, 0, 1 }; } else { - tangent = .{ 1, 0, 0 }; + const up: math.vector.vec3 = .{ -1, 0, 0 }; + const t: math.vector.vec3 = math.vector.normalize(math.vector.crossProduct(up, normal)); + const w: f32 = if (math.vector.dotProduct(math.vector.crossProduct(normal, t), up) < 0) 1 else -1; + tangent = .{ t[0], t[1], t[2], w }; } attribute_data[index] = .{ .position = pos, - .normals = .{ x, y, z }, + .normal = math.vector.normalize(normal), .texture_coords = .{ 1.0 - j_f / precision_f, 1.0 - i_f / precision_f }, + .tangent = tangent, }; } } @@ -110,7 +124,7 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu } } - return .{ .attribute_data = attribute_data, .indices = indices }; + return; } const std = @import("std"); diff --git a/src/foundations/object/ObjectStrip.zig b/src/foundations/object/ObjectStrip.zig index e9ed402..43f404e 100644 --- a/src/foundations/object/ObjectStrip.zig +++ b/src/foundations/object/ObjectStrip.zig @@ -23,7 +23,7 @@ pub fn init( rhi_data[i] = .{ .position = positions[i], .color = .{ 1, 0, 1, 1 }, - .normals = .{ 1, 0, 0 }, + .normal = .{ 1, 0, 0 }, }; } const vao_buf = rhi.attachInstancedBuffer(rhi_data[0..], instance_data); diff --git a/src/foundations/object/ObjectTorus.zig b/src/foundations/object/ObjectTorus.zig index cca5612..fdc112f 100644 --- a/src/foundations/object/ObjectTorus.zig +++ b/src/foundations/object/ObjectTorus.zig @@ -68,10 +68,10 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu tv = math.matrix.transformVector(m, tv); const t_tangent: math.vector.vec3 = .{ tv[0], tv[1], tv[2] }; const s_tangent: math.vector.vec3 = .{ 0, 1, 0 }; - const normals = math.vector.normalize(math.vector.crossProduct(t_tangent, s_tangent)); + const normal = math.vector.normalize(math.vector.crossProduct(t_tangent, s_tangent)); attribute_data[i] = .{ .position = vertex, - .normals = normals, + .normal = normal, .texture_coords = texture_coords, }; } @@ -95,13 +95,13 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu // TODO: support tangents in vertex attributes // s and t tangents need to be created here - const n = ad.normals; + const n = ad.normal; var n1: math.vector.vec4 = .{ n[0], n[1], n[2], 0 }; n1 = math.matrix.transformVector(m, n1); - const normals: math.vector.vec3 = .{ n1[0], n1[1], n1[2] }; + const normal: math.vector.vec3 = .{ n1[0], n1[1], n1[2] }; attribute_data[index] = .{ .position = vertex, - .normals = math.vector.normalize(normals), + .normal = math.vector.normalize(normal), .texture_coords = texture_coords, }; } diff --git a/src/foundations/object/ObjectTriangle.zig b/src/foundations/object/ObjectTriangle.zig index 63d5ebc..b624500 100644 --- a/src/foundations/object/ObjectTriangle.zig +++ b/src/foundations/object/ObjectTriangle.zig @@ -26,7 +26,7 @@ pub fn init( frag_shader: rhi.Shader.fragment_shader_type, positions: [3][3]f32, colors: [3][4]f32, - normals: [3][3]f32, + normal: [3][3]f32, ) Triangle { const program = rhi.createProgram(); { @@ -37,14 +37,14 @@ pub fn init( }; s.attach(allocator, vertex_partials); } - return initWithProgram(program, positions, colors, normals); + return initWithProgram(program, positions, colors, normal); } pub fn initWithProgram( program: u32, positions: [3][3]f32, colors: [3][4]f32, - normals: [3][3]f32, + normal: [3][3]f32, ) Triangle { var data: [3]rhi.attributeData = undefined; var i: usize = 0; @@ -52,7 +52,7 @@ pub fn initWithProgram( data[i] = .{ .position = positions[i], .color = colors[i], - .normals = normals[i], + .normal = normal[i], }; } const vao_buf = rhi.attachBuffer(data[0..]); diff --git a/src/foundations/rhi/Shader.zig b/src/foundations/rhi/Shader.zig index 1b4d54e..63821ab 100644 --- a/src/foundations/rhi/Shader.zig +++ b/src/foundations/rhi/Shader.zig @@ -1,4 +1,4 @@ -fragment_shader: fragment_shader_type, +fragment_shader: fragment_shader_type = .custom, instance_data: bool, vertex_partials: [max_vertex_partials][]const u8 = undefined, num_vertex_partials: usize = 0, @@ -10,18 +10,20 @@ frag_body: ?[]const u8 = null, program: u32 = 0, shadowmaps: bool = false, cubemap: bool = false, +bindless_vertex: bool = false, -const max_frag_partials: usize = 10; -const max_vertex_partials: usize = 10; +const max_frag_partials: usize = 15; +const max_vertex_partials: usize = 15; const log_len: usize = 1024 * 2; pub const fragment_shader_type = enum(usize) { color, - normals, + normal, texture, bindless, lighting, shadow, + custom, }; pub const lighting_type = enum(usize) { @@ -42,6 +44,8 @@ pub inline fn single_vertex(vertex_shader: []const u8) [1][]const u8 { const Shader = @This(); +const vertex_header = @embedFile("../shaders/vertex_header.glsl"); +const vertex_bindless_header = @embedFile("../shaders/vertex_bindless_header.glsl"); const vertex_attrib_header = @embedFile("../shaders/vertex_attrib_header.glsl"); const vertex_attrib_i_data = @embedFile("../shaders/vertex_attrib_i_data.glsl"); const vertex_subheader = @embedFile("../shaders/vertex_subheader.glsl"); @@ -68,6 +72,14 @@ const frag_phong_lighting = @embedFile("../shaders/frag_phong_lighting.glsl"); const frag_blinn_phong_lighting = @embedFile("../shaders/frag_blinn_phong_lighting.glsl"); pub fn attach(self: *Shader, allocator: std.mem.Allocator, vertex_partials: []const []const u8) void { + { + self.vertex_partials[self.num_vertex_partials] = vertex_header; + self.num_vertex_partials += 1; + } + if (self.bindless_vertex) { + self.vertex_partials[self.num_vertex_partials] = vertex_bindless_header; + self.num_vertex_partials += 1; + } { self.vertex_partials[self.num_vertex_partials] = vertex_attrib_header; self.num_vertex_partials += 1; @@ -130,9 +142,9 @@ pub fn attach(self: *Shader, allocator: std.mem.Allocator, vertex_partials: []co self.frag_partials[self.num_frag_partials] = frag_body; self.num_frag_partials += 1; } else { - const frag_body = switch (self.fragment_shader) { + const frag_body: ?[]const u8 = switch (self.fragment_shader) { .color => frag_color, - .normals => frag_normals, + .normal => frag_normals, .texture => if (self.cubemap) frag_cubemap else frag_texture, .bindless => frag_bindless, .lighting => switch (self.lighting) { @@ -141,9 +153,12 @@ pub fn attach(self: *Shader, allocator: std.mem.Allocator, vertex_partials: []co else => frag_blinn_phong_lighting, }, .shadow => frag_shadow, + .custom => null, }; - self.frag_partials[self.num_frag_partials] = frag_body; - self.num_frag_partials += 1; + if (frag_body) |fb| { + self.frag_partials[self.num_frag_partials] = fb; + self.num_frag_partials += 1; + } } const frag = std.mem.concat(allocator, u8, self.frag_partials[0..self.num_frag_partials]) catch @panic("OOM"); defer allocator.free(frag); diff --git a/src/foundations/rhi/Uniform.zig b/src/foundations/rhi/Uniform.zig index df84891..8e940c3 100644 --- a/src/foundations/rhi/Uniform.zig +++ b/src/foundations/rhi/Uniform.zig @@ -12,9 +12,13 @@ pub const empty: Uniform = .{ .program = 0, .location = 0 }; pub fn init(prog: u32, name: []const u8) UniformError!Uniform { const loc: c.GLint = c.glGetUniformLocation(@intCast(prog), @ptrCast(name)); if (loc < 0) { - std.log.warn("Uniform creation failed for {s}\n", .{name}); - return UniformError.UniformErrorCreationFailed; + std.log.warn("Uniform creation failed for {s} {d}\n", .{ name, prog }); + // return UniformError.UniformErrorCreationFailed; } + return initWithLoc(prog, loc); +} + +pub fn initWithLoc(prog: u32, loc: c.GLint) UniformError!Uniform { return .{ .program = prog, .location = loc, diff --git a/src/foundations/rhi/rhi.zig b/src/foundations/rhi/rhi.zig index 555a769..9c15dd6 100644 --- a/src/foundations/rhi/rhi.zig +++ b/src/foundations/rhi/rhi.zig @@ -83,8 +83,9 @@ pub fn createVAO() u32 { pub const attributeData = struct { position: [3]f32, color: [4]f32 = .{ 1, 0, 1, 1 }, - normals: [3]f32 = .{ 1, 1, 1 }, + normal: [3]f32 = .{ 1, 1, 1 }, texture_coords: [2]f32 = .{ 0, 0 }, + tangent: [4]f32 = .{ 0, 0, 0, 0 }, }; pub const instanceData = struct { diff --git a/src/foundations/scenery/grid/grid_vertex.glsl b/src/foundations/scenery/grid/grid_vertex.glsl index ef225ba..a612462 100644 --- a/src/foundations/scenery/grid/grid_vertex.glsl +++ b/src/foundations/scenery/grid/grid_vertex.glsl @@ -10,5 +10,5 @@ void main() vec4 pos = f_mvp * f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = transpose(inverse(mat3(f_transform))) * f_normals; + fo_normal = transpose(inverse(mat3(f_transform))) * f_normal; } \ No newline at end of file diff --git a/src/foundations/scenery/pointer/Pointer.zig b/src/foundations/scenery/pointer/Pointer.zig index dc056ea..46e768c 100644 --- a/src/foundations/scenery/pointer/Pointer.zig +++ b/src/foundations/scenery/pointer/Pointer.zig @@ -45,7 +45,7 @@ pub fn renderCylinder(self: *Pointer) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(pointer_vertex_shader)[0..]); } @@ -78,7 +78,7 @@ pub fn renderCone(self: *Pointer) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(pointer_vertex_shader)[0..]); } diff --git a/src/foundations/scenery/pointer/pointer_vertex.glsl b/src/foundations/scenery/pointer/pointer_vertex.glsl index c0b2262..249915a 100644 --- a/src/foundations/scenery/pointer/pointer_vertex.glsl +++ b/src/foundations/scenery/pointer/pointer_vertex.glsl @@ -12,5 +12,5 @@ void main() vec4 pos = f_mvp * f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_pointer_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_pointer_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/cgpoc/cgpoc.zig b/src/foundations/scenes/cgpoc/cgpoc.zig index 4db06d4..6aa2687 100644 --- a/src/foundations/scenes/cgpoc/cgpoc.zig +++ b/src/foundations/scenes/cgpoc/cgpoc.zig @@ -6,3 +6,4 @@ pub const chapter5 = @import("chapter5/chapter5.zig"); pub const chapter6 = @import("chapter6/chapter6.zig"); pub const chapter7 = @import("chapter7/chapter7.zig"); pub const chapter8 = @import("chapter8/chapter8.zig"); +pub const chapter10 = @import("chapter10/chapter10.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter10/chapter10.zig b/src/foundations/scenes/cgpoc/chapter10/chapter10.zig new file mode 100644 index 0000000..65eff73 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/chapter10.zig @@ -0,0 +1 @@ +pub const SurfaceDetail = @import("surface_detail/SurfaceDetail.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetail.zig b/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetail.zig new file mode 100644 index 0000000..42d5814 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetail.zig @@ -0,0 +1,454 @@ +view_camera: *physics.camera.Camera(*SurfaceDetail, physics.Integrator(physics.SmoothDeceleration)), +ctx: scenes.SceneContext, +allocator: std.mem.Allocator, +ui_state: SurfaceDetailUI, +materials: rhi.Buffer, +lights: rhi.Buffer, +moon: object.object = .{ .norender = .{} }, +moon_normal_map: ?rhi.Texture = null, +moon_texture: ?rhi.Texture = null, +earth: object.object = .{ .norender = .{} }, +earth_height_map: ?rhi.Texture = null, +earth_normal_map: ?rhi.Texture = null, +earth_texture: ?rhi.Texture = null, +cubemap: object.object = .{ .norender = .{} }, +cubemap_texture: ?rhi.Texture = null, +cross: scenery.debug.Cross = undefined, +sphere: object.object = .{ .norender = .{} }, +sphere_matrix: rhi.Uniform = undefined, +moon_light_pos: rhi.Uniform = undefined, +earth_light_pos: rhi.Uniform = undefined, + +const SurfaceDetail = @This(); + +const mats = [_]lighting.Material{ + lighting.materials.Silver, +}; + +const moon_vertex_shader: []const u8 = @embedFile("moon_vert.glsl"); +const moon_frag_shader: []const u8 = @embedFile("moon_frag.glsl"); +const earth_vertex_shader: []const u8 = @embedFile("earth_vert.glsl"); +const earth_frag_shader: []const u8 = @embedFile("earth_frag.glsl"); +const cubemap_vert: []const u8 = @embedFile("../../../../shaders/cubemap_vert.glsl"); +const sphere_vertex_shader: []const u8 = @embedFile("sphere_vertex.glsl"); +const earth_texture_shader: []const u8 = @embedFile("earth_vert_texture.glsl"); +const earth_bindless_shader: []const u8 = @embedFile("earth_vert_bindless.glsl"); + +pub fn navType() ui.ui_state.scene_nav_info { + return .{ + .nav_type = .cgpoc, + .name = "SurfaceDetail", + }; +} + +pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *SurfaceDetail { + const sd = allocator.create(SurfaceDetail) catch @panic("OOM"); + errdefer allocator.destroy(sd); + const integrator = physics.Integrator(physics.SmoothDeceleration).init(.{}); + var max_texture_units: c.GLint = 0; + c.glGetIntegerv(c.GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units); + if (max_texture_units < 17) { + std.log.warn("not enough texture units: {d}, required: 17\n", .{max_texture_units}); + } + var cam = physics.camera.Camera(*SurfaceDetail, physics.Integrator(physics.SmoothDeceleration)).init( + allocator, + ctx.cfg, + sd, + integrator, + .{ 2, 4, -2 }, + std.math.pi, + ); + errdefer cam.deinit(allocator); + cam.global_ambient = .{ 0.025, 0.025, 0.025, 1.0 }; + cam.updateMVP(); + + const bd: rhi.Buffer.buffer_data = .{ .materials = mats[0..] }; + var mats_buf = rhi.Buffer.init(bd); + errdefer mats_buf.deinit(); + + const lights = [_]lighting.Light{ + .{ + .ambient = [4]f32{ 0.1, 0.1, 0.1, 1.0 }, + .diffuse = [4]f32{ 1.0, 1.0, 1.0, 1.0 }, + .specular = [4]f32{ 1.0, 1.0, 1.0, 1.0 }, + .location = [4]f32{ 0.0, 0.0, 0.0, 1.0 }, + .direction = [4]f32{ 0.0, 5.0, 0.0, 0.0 }, + .cutoff = 0.0, + .exponent = 0.0, + .attenuation_constant = 1.0, + .attenuation_linear = 0.0, + .attenuation_quadratic = 0.0, + .light_kind = .positional, + }, + }; + const ld: rhi.Buffer.buffer_data = .{ .lights = lights[0..] }; + var lights_buf = rhi.Buffer.init(ld); + errdefer lights_buf.deinit(); + + const ui_state: SurfaceDetailUI = .{}; + sd.* = .{ + .ui_state = ui_state, + .allocator = allocator, + .view_camera = cam, + .ctx = ctx, + .lights = lights_buf, + .materials = mats_buf, + }; + + sd.renderCubemap(); + errdefer sd.deleteCubemap(); + + sd.renderMoon(); + errdefer sd.deleteMoon(); + + sd.renderEarth(); + errdefer sd.deleteEarth(); + + sd.renderDebugCross(); + errdefer sd.deleteDebugCross(); + + sd.renderSphere(); + errdefer sd.deleteSphere(); + + return sd; +} + +pub fn deinit(self: *SurfaceDetail, allocator: std.mem.Allocator) void { + if (self.moon_normal_map) |et| { + et.deinit(); + } + self.view_camera.deinit(allocator); + self.view_camera = undefined; + self.materials.deinit(); + self.materials = undefined; + self.lights.deinit(); + self.lights = undefined; + self.deleteMoon(); + self.deleteEarth(); + self.deleteCubemap(); + self.deleteSphere(); + allocator.destroy(self); +} + +pub fn draw(self: *SurfaceDetail, dt: f64) void { + if (self.ui_state.light_updated) { + self.moon_light_pos.setUniform3fv(self.ui_state.light_position); + self.earth_light_pos.setUniform3fv(self.ui_state.light_position); + const lp = self.ui_state.light_position; + self.sphere_matrix.setUniformMatrix(math.matrix.translate(lp[0], lp[1], lp[2])); + self.ui_state.light_updated = false; + } + self.view_camera.update(dt); + if (self.cubemap_texture) |t| { + t.bind(); + } + { + const objects: [1]object.object = .{ + self.cubemap, + }; + c.glDisable(c.GL_DEPTH_TEST); + c.glFrontFace(c.GL_CCW); + rhi.drawObjects(objects[0..]); + c.glFrontFace(c.GL_CW); + c.glEnable(c.GL_DEPTH_TEST); + } + if (self.moon_normal_map) |t| { + t.bind(); + } + if (self.moon_texture) |t| { + t.bind(); + } + { + const objects: [1]object.object = .{ + self.moon, + }; + rhi.drawObjects(objects[0..]); + } + if (self.earth_normal_map) |t| { + t.bind(); + } + if (self.earth_texture) |t| { + t.bind(); + } + if (self.earth_height_map) |t| { + t.bind(); + } + { + const objects: [1]object.object = .{ + self.earth, + }; + rhi.drawObjects(objects[0..]); + } + { + const objects: [1]object.object = .{ + self.sphere, + }; + rhi.drawObjects(objects[0..]); + } + self.cross.draw(dt); + self.ui_state.draw(); +} + +pub fn updateCamera(_: *SurfaceDetail) void {} + +pub fn deleteCubemap(self: *SurfaceDetail) void { + const objects: [1]object.object = .{ + self.cubemap, + }; + rhi.deleteObjects(objects[0..]); +} + +pub fn renderCubemap(self: *SurfaceDetail) void { + const prog = rhi.createProgram(); + self.cubemap_texture = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + { + var s: rhi.Shader = .{ + .program = prog, + .cubemap = true, + .instance_data = true, + .fragment_shader = .texture, + }; + s.attach(self.allocator, rhi.Shader.single_vertex(cubemap_vert)[0..]); + } + var i_datas: [1]rhi.instanceData = undefined; + { + var cm = math.matrix.identity(); + cm = math.matrix.transformMatrix(cm, math.matrix.uniformScale(20)); + cm = math.matrix.transformMatrix(cm, math.matrix.translate(-0.5, -0.5, -0.5)); + const i_data: rhi.instanceData = .{ + .t_column0 = cm.columns[0], + .t_column1 = cm.columns[1], + .t_column2 = cm.columns[2], + .t_column3 = cm.columns[3], + .color = .{ 1, 0, 0, 1 }, + }; + i_datas[0] = i_data; + } + var parallelepiped: object.object = .{ + .parallelepiped = object.Parallelepiped.initCubemap( + prog, + i_datas[0..], + false, + ), + }; + parallelepiped.parallelepiped.mesh.linear_colorspace = false; + if (self.cubemap_texture) |*bt| { + var cm: assets.Cubemap = .{ + .path = "cgpoc\\cubemaps\\milkyway\\cubemap", + .textures_loader = self.ctx.textures_loader, + }; + cm.names[0] = "xp.png"; + cm.names[1] = "xn.png"; + cm.names[2] = "yp.png"; + cm.names[3] = "yn.png"; + cm.names[4] = "zp.png"; + cm.names[5] = "zn.png"; + var images: ?[6]*assets.Image = null; + if (cm.loadAll(self.allocator)) { + images = cm.images; + } else |_| { + std.debug.print("failed to load textures\n", .{}); + } + bt.setupCubemap(images, prog, "f_cubemap") catch { + self.cubemap_texture = null; + }; + } + self.cubemap = parallelepiped; +} + +pub fn deleteMoon(self: *SurfaceDetail) void { + const objects: [1]object.object = .{ + self.moon, + }; + rhi.deleteObjects(objects[0..]); +} + +pub fn renderMoon(self: *SurfaceDetail) void { + const prog = rhi.createProgram(); + self.moon_normal_map = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + self.moon_texture = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + self.moon_texture.?.texture_unit = 1; + { + var s: rhi.Shader = .{ + .program = prog, + .instance_data = true, + .lighting = .blinn_phong, + .fragment_shader = rhi.Texture.frag_shader(self.moon_normal_map), + .frag_body = moon_frag_shader, + }; + const partials = [_][]const u8{moon_vertex_shader}; + s.attach(self.allocator, @ptrCast(partials[0..])); + } + var i_datas: [1]rhi.instanceData = undefined; + { + var cm = math.matrix.identity(); + cm = math.matrix.transformMatrix(cm, math.matrix.translate(3, -4, -6)); + cm = math.matrix.transformMatrix(cm, math.matrix.uniformScale(0.5)); + const i_data: rhi.instanceData = .{ + .t_column0 = cm.columns[0], + .t_column1 = cm.columns[1], + .t_column2 = cm.columns[2], + .t_column3 = cm.columns[3], + .color = .{ 1, 0, 1, 1 }, + }; + i_datas[0] = i_data; + } + const sphere: object.object = .{ + .sphere = object.Sphere.initWithPrecision( + prog, + i_datas[0..], + false, + 250, + ), + }; + if (self.moon_normal_map) |*t| { + t.setup(self.ctx.textures_loader.loadAsset("cgpoc\\surface_details\\moonNORMAL.jpg") catch null, prog, "f_samp") catch { + self.moon_normal_map = null; + }; + } + if (self.moon_texture) |*t| { + t.setup(self.ctx.textures_loader.loadAsset("cgpoc\\PlanetPixelEmporium\\moonbump4kRGB.jpg") catch null, prog, "f_samp_1") catch { + self.moon_texture = null; + }; + } + self.moon_light_pos = rhi.Uniform.init(prog, "f_moon_light_pos") catch @panic("uniform failed"); + self.moon_light_pos.setUniform3fv(.{ 3, 2, 1 }); + self.moon = sphere; +} + +pub fn deleteEarth(self: *SurfaceDetail) void { + const objects: [1]object.object = .{ + self.earth, + }; + rhi.deleteObjects(objects[0..]); +} + +pub fn renderEarth(self: *SurfaceDetail) void { + const prog = rhi.createProgram(); + self.earth_normal_map = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + self.earth_normal_map.?.texture_unit = 2; + self.earth_texture = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + self.earth_texture.?.texture_unit = 3; + self.earth_height_map = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; + self.earth_height_map.?.texture_unit = 17; + var earth_height_map = earth_bindless_shader; + if (rhi.Texture.disableBindless(self.ctx.args.disable_bindless)) { + earth_height_map = earth_texture_shader; + } + { + var s: rhi.Shader = .{ + .program = prog, + .instance_data = true, + .lighting = .blinn_phong, + .frag_body = earth_frag_shader, + .bindless_vertex = true, + .fragment_shader = rhi.Texture.frag_shader(self.earth_texture), + }; + const vert_shaders = [_][]const u8{ earth_height_map, earth_vertex_shader }; + s.attach(self.allocator, vert_shaders[0..]); + } + var i_datas: [1]rhi.instanceData = undefined; + { + var cm = math.matrix.identity(); + cm = math.matrix.transformMatrix(cm, math.matrix.uniformScale(2)); + const i_data: rhi.instanceData = .{ + .t_column0 = cm.columns[0], + .t_column1 = cm.columns[1], + .t_column2 = cm.columns[2], + .t_column3 = cm.columns[3], + .color = .{ 1, 0, 1, 1 }, + }; + i_datas[0] = i_data; + } + const earth: object.object = .{ + .sphere = object.Sphere.initWithPrecision( + prog, + i_datas[0..], + false, + 250, + ), + }; + if (self.earth_normal_map) |*t| { + t.setup(self.ctx.textures_loader.loadAsset("cgpoc\\surface_details\\earthspec1kNORMAL.jpg") catch null, prog, "f_samp_2") catch { + self.earth_normal_map = null; + }; + } + if (self.earth_texture) |*t| { + t.setup(self.ctx.textures_loader.loadAsset("cgpoc\\PlanetPixelEmporium\\earthmap1k.jpg") catch null, prog, "f_samp_3") catch { + self.earth_texture = null; + }; + } + if (self.earth_height_map) |*t| { + t.setup(self.ctx.textures_loader.loadAsset("cgpoc\\surface_details\\earthspec1kNEG.jpg") catch null, prog, "f_earth_heightmap") catch { + self.earth_height_map = null; + }; + } + self.earth_light_pos = rhi.Uniform.init(prog, "f_earth_light_pos") catch @panic("failed to load earthlight uniform"); + self.earth_light_pos.setUniform3fv(.{ 1, 2, 3 }); + self.earth = earth; +} + +pub fn deleteCross(self: *SurfaceDetail) void { + self.cross.deinit(self.allocator); +} + +pub fn renderDebugCross(self: *SurfaceDetail) void { + self.cross = scenery.debug.Cross.init( + self.allocator, + math.matrix.translate(0, 0, 5), + 5, + ); +} + +pub fn deleteSphere(self: *SurfaceDetail) void { + const objects: [1]object.object = .{ + self.sphere, + }; + rhi.deleteObjects(objects[0..]); +} + +pub fn renderSphere(self: *SurfaceDetail) void { + const prog = rhi.createProgram(); + { + var s: rhi.Shader = .{ + .program = prog, + .instance_data = true, + .fragment_shader = .color, + }; + s.attach(self.allocator, rhi.Shader.single_vertex(sphere_vertex_shader)[0..]); + } + var i_datas: [1]rhi.instanceData = undefined; + const m = math.matrix.uniformScale(0.125); + i_datas[0] = .{ + .t_column0 = m.columns[0], + .t_column1 = m.columns[1], + .t_column2 = m.columns[2], + .t_column3 = m.columns[3], + .color = .{ 1, 1, 1, 1 }, + }; + const sphere: object.object = .{ + .sphere = object.Sphere.init( + prog, + i_datas[0..], + false, + ), + }; + const lp = self.ui_state.light_position; + var sm: rhi.Uniform = rhi.Uniform.init(prog, "f_sphere_matrix") catch @panic("uniform failed"); + sm.setUniformMatrix(math.matrix.translate(lp[0], lp[1], lp[2])); + self.sphere_matrix = sm; + self.sphere = sphere; +} + +const std = @import("std"); +const c = @import("../../../../c.zig").c; +const ui = @import("../../../../ui/ui.zig"); +const rhi = @import("../../../../rhi/rhi.zig"); +const math = @import("../../../../math/math.zig"); +const object = @import("../../../../object/object.zig"); +const scenes = @import("../../../scenes.zig"); +const physics = @import("../../../../physics/physics.zig"); +const scenery = @import("../../../../scenery/scenery.zig"); +const lighting = @import("../../../../lighting/lighting.zig"); +const assets = @import("../../../../assets/assets.zig"); +const SurfaceDetailUI = @import("SurfaceDetailUI.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetailUI.zig b/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetailUI.zig new file mode 100644 index 0000000..47623f7 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/SurfaceDetailUI.zig @@ -0,0 +1,43 @@ +light_position: math.vector.vec3 = .{ 1.784, -10.812, 0.057 }, +light_updated: bool = true, + +const ShadowsUI = @This(); + +pub fn draw(self: *ShadowsUI) void { + self.drawLight(); +} + +fn drawLight(self: *ShadowsUI) void { + var buf: [250]u8 = undefined; + const vp: *c.ImGuiViewport = c.igGetMainViewport(); + const pos = c.ImVec2_ImVec2_Float(vp.WorkPos.x + 50, vp.WorkPos.y + 50); + c.igSetNextWindowPos(pos.*, c.ImGuiCond_FirstUseEver, c.ImVec2_ImVec2_Float(0, 0).*); + const size = c.ImVec2_ImVec2_Float(550, 680); + c.igSetNextWindowSize(size.*, c.ImGuiCond_FirstUseEver); + _ = c.igBegin("Light", null, 0); + { + c.igNewLine(); + c.igText("Light"); + { + const txt = std.fmt.bufPrintZ(&buf, "Position: ({d:.3}, {d:.3}, {d:.3}", .{ + self.light_position[0], + self.light_position[1], + self.light_position[2], + }) catch @panic("bufsize too small"); + c.igText(@ptrCast(txt)); + } + { + c.igText("position"); + c.igPushItemWidth(-1); + if (c.igSliderFloat("##l1tx", &self.light_position[0], -25, 25, "%.3f", c.ImGuiSliderFlags_None)) self.light_updated = true; + if (c.igSliderFloat("##l1ty", &self.light_position[1], -25, 25, "%.3f", c.ImGuiSliderFlags_None)) self.light_updated = true; + if (c.igSliderFloat("##l1tz", &self.light_position[2], -25, 25, "%.3f", c.ImGuiSliderFlags_None)) self.light_updated = true; + } + } + c.igEnd(); +} + +const std = @import("std"); +const c = @import("../../../../c.zig").c; +const math = @import("../../../../math/math.zig"); +const ui = @import("../../../../ui/ui.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_frag.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_frag.glsl new file mode 100644 index 0000000..e29e709 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_frag.glsl @@ -0,0 +1,35 @@ + +vec3 f_calc_new_normal() { + vec3 f_n_normal = normalize(fo_normal); + vec3 f_n_tangent = normalize(fo_tangent.xyz); + vec3 f_n_bitangent = fo_tangent.w * normalize(cross(f_n_tangent, f_n_normal)); + mat3 f_n_tbn = mat3(f_n_tangent, f_n_bitangent, f_n_normal); + vec3 f_n_map_normal = (vec4(texture(f_samp_2, f_tc).xyz, 1.0)).xyz; + f_n_map_normal = f_n_map_normal * 2.0 - 1.0; + vec3 f_n_new_normal = f_n_tbn * f_n_map_normal; + f_n_new_normal = normalize(f_n_new_normal); + return f_n_new_normal; +} + +void main() +{ + + vec4 f_texture_color = texture(f_samp_3, f_tc); + vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); + vec3 f_N = f_calc_new_normal(); + Light f_light = f_lights[0]; + Material f_mat = f_materials[0]; + + vec3 f_L = normalize(fo_lightdir.xyz); + vec3 f_H = normalize(f_L + f_V).xyz; + + + float cosTheta = dot(f_L, f_N); + float cosPhi = dot(f_H, f_N); + + vec3 f_ambient = ((f_global_ambient * f_mat.ambient) + (f_light.ambient * f_mat.ambient)).xyz; + vec3 f_diffuse = f_light.diffuse.xyz * f_mat.diffuse.xyz * max(cosTheta, 0.0); + vec3 f_specular = f_mat.specular.xyz * f_light.specular.xyz * pow(max(cosPhi, 0.0), f_mat.shininess * 4.0); + + fo_frag_color = f_texture_color * vec4((f_ambient + f_diffuse + f_specular), 1.0); +} diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert.glsl new file mode 100644 index 0000000..106c893 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert.glsl @@ -0,0 +1,32 @@ + +uniform vec3 f_earth_light_pos; + +mat4 f_cubemap_xup = (mat4( + vec4(1, 0, 0, 0), + vec4(0, 1, 0, 0), + vec4(0, 0, 1, 0), + vec4(0, 0, 0, 1) +)); + +void main() +{ + mat4 m_matrix = mat4( + f_t_column0, + f_t_column1, + f_t_column2, + f_t_column3 + ); + mat3 f_norm_matrix = transpose(inverse(mat3(m_matrix * f_xup))); + float h_pos = texture(f_earth_heightmap, f_texture_coords).r * 0.025; + vec4 f_pos = vec4(f_position.xyz, 1.0) + vec4(f_normal * h_pos, 1.0); + vec4 f_main_pos = m_matrix * f_xup * f_pos; + + fo_vert = f_main_pos.xyz; + fo_normal = normalize(f_norm_matrix * f_normal); + f_tc = f_texture_coords; + f_frag_color = vec4(h_pos, 0.0, 0.0, 2.0); + fo_tangent = f_cubemap_xup * m_matrix * vec4(f_tangent.xyz, 0); + fo_tangent.w = f_tangent.w; + fo_lightdir = (f_cubemap_xup * vec4(f_earth_light_pos, 0)).xyz; + gl_Position = f_mvp * f_main_pos; +} diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_bindless.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_bindless.glsl new file mode 100644 index 0000000..4824c25 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_bindless.glsl @@ -0,0 +1,2 @@ + +layout(bindless_sampler) uniform sampler2D f_earth_heightmap; \ No newline at end of file diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_texture.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_texture.glsl new file mode 100644 index 0000000..fed31c2 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/earth_vert_texture.glsl @@ -0,0 +1,2 @@ + +layout(binding=17) uniform sampler2D f_earth_heightmap; \ No newline at end of file diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_frag.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_frag.glsl new file mode 100644 index 0000000..83a9e4a --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_frag.glsl @@ -0,0 +1,35 @@ +vec3 f_calc_new_normal() { + vec3 f_n_normal = normalize(fo_normal); + vec3 f_n_tangent = normalize(fo_tangent.xyz); + f_n_tangent = normalize(f_n_tangent - dot(f_n_tangent, f_n_normal) * f_n_normal); + vec3 f_n_bitangent = fo_tangent.w * cross(f_n_tangent, f_n_normal); + mat3 f_n_tbn = mat3(f_n_tangent, f_n_bitangent, f_n_normal); + vec3 f_n_map_normal = texture(f_samp, f_tc).xyz; + f_n_map_normal = f_n_map_normal * 2.0 - 1.0; + vec3 f_n_new_normal = f_n_tbn * f_n_map_normal; + f_n_new_normal = normalize(f_n_new_normal); + return f_n_new_normal; +} + +void main() +{ + + vec4 f_texture_color = texture(f_samp_1, f_tc); + vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); + vec3 f_N = f_calc_new_normal(); + Light f_light = f_lights[0]; + Material f_mat = f_materials[0]; + + vec3 f_L = normalize(fo_lightdir.xyz); + vec3 f_H = normalize(f_L + f_V).xyz; + + + float cosTheta = dot(f_L, f_N); + float cosPhi = dot(f_H, f_N); + + vec3 f_ambient = ((f_global_ambient * f_mat.ambient) + (f_light.ambient * f_mat.ambient)).xyz; + vec3 f_diffuse = f_light.diffuse.xyz * f_mat.diffuse.xyz * max(cosTheta, 0.0); + vec3 f_specular = f_mat.specular.xyz * f_light.specular.xyz * pow(max(cosPhi, 0.0), f_mat.shininess * 4.0); + + fo_frag_color = f_texture_color * 0.5 + vec4((f_ambient + f_diffuse + f_specular), 1.0); +} diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_vert.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_vert.glsl new file mode 100644 index 0000000..ad5166b --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/moon_vert.glsl @@ -0,0 +1,23 @@ + + +uniform vec3 f_moon_light_pos; + +void main() +{ + mat4 m_matrix = mat4( + f_t_column0, + f_t_column1, + f_t_column2, + f_t_column3 + ); + mat3 f_norm_matrix = transpose(inverse(mat3(m_matrix* f_xup))); + vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); + + fo_vert = f_main_pos.xyz; + fo_normal = normalize(f_norm_matrix * f_normal); + f_tc = f_texture_coords; + f_frag_color = vec4(f_moon_light_pos.xyz, 1.0); + fo_tangent = m_matrix * f_tangent; + fo_lightdir = f_moon_light_pos.xyz; + gl_Position = f_mvp * f_main_pos; +} diff --git a/src/foundations/scenes/cgpoc/chapter10/surface_detail/sphere_vertex.glsl b/src/foundations/scenes/cgpoc/chapter10/surface_detail/sphere_vertex.glsl new file mode 100644 index 0000000..0ca6ab8 --- /dev/null +++ b/src/foundations/scenes/cgpoc/chapter10/surface_detail/sphere_vertex.glsl @@ -0,0 +1,16 @@ + +uniform mat4 f_sphere_matrix; + +void main() +{ + mat4 f_transform = mat4( + f_t_column0, + f_t_column1, + f_t_column2, + f_t_column3 + ); + vec4 f_pos = f_mvp * f_sphere_matrix * f_transform * vec4(f_position.xyz, 1.0); + gl_Position = f_pos; + f_frag_color = f_i_color; + fo_normal = normalize(transpose(inverse(mat3(f_transform))) * f_normal); +} \ No newline at end of file diff --git a/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_texture_frag.glsl b/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_texture_frag.glsl index 21abed8..0441565 100644 --- a/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_texture_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_texture_frag.glsl @@ -4,7 +4,7 @@ vec4 f_blinn_phong_lighting_texture(vec4 f_tx_color, Light f_lights[10], uint nu num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_vert.glsl b/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_vert.glsl index e4f745c..d395359 100644 --- a/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter4/simple_solar_system/blinn_phong_vert.glsl @@ -13,7 +13,7 @@ void main() vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); fo_vert = f_main_pos.xyz; - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); fo_light_dir = vec3(0.0, 0.0, 0.0) - fo_vert; diff --git a/src/foundations/scenes/cgpoc/chapter6/chapter6.zig b/src/foundations/scenes/cgpoc/chapter6/chapter6.zig index 2cbc5d0..d983072 100644 --- a/src/foundations/scenes/cgpoc/chapter6/chapter6.zig +++ b/src/foundations/scenes/cgpoc/chapter6/chapter6.zig @@ -1,3 +1,2 @@ -pub const Earth = @import("earth/Earth.zig"); pub const TexturedTorus = @import("textured_torus/TexturedTorus.zig"); pub const Shuttle = @import("shuttle/Shuttle.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter6/earth/Earth.zig b/src/foundations/scenes/cgpoc/chapter6/earth/Earth.zig deleted file mode 100644 index 243be5d..0000000 --- a/src/foundations/scenes/cgpoc/chapter6/earth/Earth.zig +++ /dev/null @@ -1,114 +0,0 @@ -allocator: std.mem.Allocator, -sphere: object.object = .{ .norender = .{} }, -view_camera: *physics.camera.Camera(*Earth, physics.Integrator(physics.SmoothDeceleration)), -earth_texture: ?rhi.Texture = null, -ctx: scenes.SceneContext, - -const Earth = @This(); - -const vertex_shader: []const u8 = @embedFile("../../../../shaders/i_obj_vert.glsl"); - -pub fn navType() ui.ui_state.scene_nav_info { - return .{ - .nav_type = .cgpoc, - .name = "Earth", - }; -} - -pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *Earth { - const pd = allocator.create(Earth) catch @panic("OOM"); - errdefer allocator.destroy(pd); - const integrator = physics.Integrator(physics.SmoothDeceleration).init(.{}); - const cam = physics.camera.Camera(*Earth, physics.Integrator(physics.SmoothDeceleration)).init( - allocator, - ctx.cfg, - pd, - integrator, - .{ 3, -15, 0 }, - 0, - ); - errdefer cam.deinit(allocator); - - pd.* = .{ - .allocator = allocator, - .view_camera = cam, - .ctx = ctx, - }; - pd.renderSphere(); - return pd; -} - -pub fn deinit(self: *Earth, allocator: std.mem.Allocator) void { - if (self.earth_texture) |et| { - et.deinit(); - } - self.view_camera.deinit(allocator); - self.view_camera = undefined; - allocator.destroy(self); -} - -pub fn draw(self: *Earth, dt: f64) void { - self.view_camera.update(dt); - if (self.earth_texture) |et| { - et.bind(); - } - { - const objects: [1]object.object = .{ - self.sphere, - }; - rhi.drawObjects(objects[0..]); - } -} - -pub fn updateCamera(_: *Earth) void {} - -pub fn renderSphere(self: *Earth) void { - const prog = rhi.createProgram(); - self.earth_texture = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; - { - var s: rhi.Shader = .{ - .program = prog, - .instance_data = true, - .fragment_shader = rhi.Texture.frag_shader(self.earth_texture), - }; - const partials = [_][]const u8{vertex_shader}; - s.attach(self.allocator, @ptrCast(partials[0..])); - } - var i_datas: [1]rhi.instanceData = undefined; - { - var cm = math.matrix.identity(); - cm = math.matrix.transformMatrix(cm, math.matrix.translate(0, -1, -1)); - cm = math.matrix.transformMatrix(cm, math.matrix.uniformScale(2)); - const i_data: rhi.instanceData = .{ - .t_column0 = cm.columns[0], - .t_column1 = cm.columns[1], - .t_column2 = cm.columns[2], - .t_column3 = cm.columns[3], - .color = .{ 1, 0, 1, 1 }, - }; - i_datas[0] = i_data; - } - const sphere: object.object = .{ - .sphere = object.Sphere.init( - prog, - i_datas[0..], - false, - ), - }; - if (self.earth_texture) |*bt| { - bt.setup(self.ctx.textures_loader.loadAsset("cgpoc\\earth.jpg") catch null, prog, "f_samp") catch { - self.earth_texture = null; - }; - } - self.sphere = sphere; -} - -const std = @import("std"); -const c = @import("../../../../c.zig").c; -const ui = @import("../../../../ui/ui.zig"); -const rhi = @import("../../../../rhi/rhi.zig"); -const math = @import("../../../../math/math.zig"); -const object = @import("../../../../object/object.zig"); -const scenes = @import("../../../scenes.zig"); -const physics = @import("../../../../physics/physics.zig"); -const scenery = @import("../../../../scenery/scenery.zig"); diff --git a/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_frag.glsl b/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_frag.glsl index 934ac39..3fddee7 100644 --- a/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_frag.glsl @@ -10,7 +10,7 @@ mat4 f_cubemap_xup = (mat4( void main() { vec3 f_V = normalize((f_cubemap_xup * f_camera_pos).xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec3 f_R = -reflect(f_V, f_N); fo_frag_color = texture(f_cubemap, f_R); diff --git a/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_vert.glsl b/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_vert.glsl index 4586737..380b114 100644 --- a/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter6/textured_torus/torus_vert.glsl @@ -17,7 +17,7 @@ void main() vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); mat3 f_norm_matrix = transpose(inverse(mat3(f_cubemap_xup * m_matrix * f_xup))); - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); fo_vert = (f_cubemap_xup * f_main_pos).xyz; gl_Position = f_mvp * f_main_pos; diff --git a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag.glsl b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag.glsl index e4dfffe..fa348c2 100644 --- a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag.glsl @@ -3,7 +3,7 @@ vec4 f_blinn_phong_lighting_texture(vec4 f_tx_color, Light f_lights[10], uint nu num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag_matte.glsl b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag_matte.glsl index 29abeb9..6d72f0c 100644 --- a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag_matte.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_frag_matte.glsl @@ -19,7 +19,7 @@ void main() Light f_light = f_lights[0]; vec4 f_texture_color = texture(f_samp_1, f_tc); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec3 f_L = normalize(f_light.direction.xyz); @@ -37,7 +37,7 @@ void main() vec3 f_ambient = (f_global_ambient + f_light.ambient).xyz; vec3 f_diffuse = f_light.diffuse.xyz * max(cosTheta, 0.0); - if (fo_normals[0] < 0.01 && fo_normals[1] > 0.99) { + if (fo_normal[0] < 0.01 && fo_normal[1] > 0.99) { f_shadow_factor = 1.0; } diff --git a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_vert.glsl b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_vert.glsl index 9352b65..bbdc1b4 100644 --- a/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/dolphin/blinn_phong_vert.glsl @@ -14,7 +14,7 @@ void main() vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); fo_vert = f_main_pos.xyz; - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); gl_Position = f_mvp * f_main_pos; fo_shadow_coord = f_shadow_m * f_main_pos; diff --git a/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_frag.glsl b/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_frag.glsl index 62d5d04..0945085 100644 --- a/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_frag.glsl @@ -6,7 +6,7 @@ vec4 f_blinn_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_vert.glsl b/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_vert.glsl index e76f507..7d13a66 100644 --- a/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/lighting/blinn_phong_vert.glsl @@ -16,7 +16,7 @@ void main() vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); fo_vert = f_main_pos.xyz; - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); fo_light_1_dir = f_light_1_pos - fo_vert; fo_light_2_dir = f_light_2_pos - fo_vert; diff --git a/src/foundations/scenes/cgpoc/chapter7/lighting/gouraud_vert.glsl b/src/foundations/scenes/cgpoc/chapter7/lighting/gouraud_vert.glsl index 482cc15..a0522fd 100644 --- a/src/foundations/scenes/cgpoc/chapter7/lighting/gouraud_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/lighting/gouraud_vert.glsl @@ -15,7 +15,7 @@ void main() Material f_m = f_materials[f_material_selection]; vec4 f_P = m_matrix * f_xup * vec4(f_position.xyz, 1.0); - vec3 f_N = normalize(f_norm_matrix * f_normals); + vec3 f_N = normalize(f_norm_matrix * f_normal); vec3 f_l_dirs[2] = vec3[2](f_light_1_pos, f_light_2_pos); @@ -36,7 +36,7 @@ void main() gl_Position = f_mvp * f_P; f_tc = f_texture_coords; - fo_normals = f_N; + fo_normal = f_N; f_frag_color = f_frag_color + vec4((f_ambient + f_diffuse + f_specular), 0.0); i += 1; diff --git a/src/foundations/scenes/cgpoc/chapter7/lighting/phong_frag.glsl b/src/foundations/scenes/cgpoc/chapter7/lighting/phong_frag.glsl index 3668fa7..e0c5eff 100644 --- a/src/foundations/scenes/cgpoc/chapter7/lighting/phong_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/lighting/phong_frag.glsl @@ -7,7 +7,7 @@ vec4 f_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, vec4 num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter7/lighting/sphere_vertex.glsl b/src/foundations/scenes/cgpoc/chapter7/lighting/sphere_vertex.glsl index 55a0a0c..0ca6ab8 100644 --- a/src/foundations/scenes/cgpoc/chapter7/lighting/sphere_vertex.glsl +++ b/src/foundations/scenes/cgpoc/chapter7/lighting/sphere_vertex.glsl @@ -12,5 +12,5 @@ void main() vec4 f_pos = f_mvp * f_sphere_matrix * f_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_frag.glsl b/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_frag.glsl index 8f22bdf..46e2632 100644 --- a/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_frag.glsl @@ -22,7 +22,7 @@ vec4 f_blinn_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_vert.glsl b/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_vert.glsl index c0e4e1d..f87093d 100644 --- a/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter8/shadows/blinn_phong_vert.glsl @@ -47,7 +47,7 @@ void main() vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); fo_vert = f_main_pos.xyz; - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); fo_light_1_dir = f_light_1_pos - fo_vert; fo_light_2_dir = f_light_2_pos - fo_vert; diff --git a/src/foundations/scenes/cgpoc/chapter8/shadows/gouraud_vert.glsl b/src/foundations/scenes/cgpoc/chapter8/shadows/gouraud_vert.glsl index 486f90a..beed3bd 100644 --- a/src/foundations/scenes/cgpoc/chapter8/shadows/gouraud_vert.glsl +++ b/src/foundations/scenes/cgpoc/chapter8/shadows/gouraud_vert.glsl @@ -48,7 +48,7 @@ void main() Material f_m = f_materials[f_material_selection]; vec4 f_P = m_matrix * f_xup * vec4(f_position.xyz, 1.0); - vec3 f_N = normalize(f_norm_matrix * f_normals); + vec3 f_N = normalize(f_norm_matrix * f_normal); vec3 f_l_dirs[2] = vec3[2](f_light_1_pos, f_light_2_pos); @@ -76,7 +76,7 @@ void main() gl_Position = f_mvp * f_P; f_tc = f_texture_coords; - fo_normals = f_N; + fo_normal = f_N; f_frag_color = f_frag_color + vec4((f_ambient + f_diffuse + f_specular), 0.0); i += 1; } while (i < num_lights); diff --git a/src/foundations/scenes/cgpoc/chapter8/shadows/phong_frag.glsl b/src/foundations/scenes/cgpoc/chapter8/shadows/phong_frag.glsl index 1907f8d..0c8cd43 100644 --- a/src/foundations/scenes/cgpoc/chapter8/shadows/phong_frag.glsl +++ b/src/foundations/scenes/cgpoc/chapter8/shadows/phong_frag.glsl @@ -23,7 +23,7 @@ vec4 f_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, vec4 num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/scenes/cgpoc/chapter8/shadows/sphere_vertex.glsl b/src/foundations/scenes/cgpoc/chapter8/shadows/sphere_vertex.glsl index 55a0a0c..0ca6ab8 100644 --- a/src/foundations/scenes/cgpoc/chapter8/shadows/sphere_vertex.glsl +++ b/src/foundations/scenes/cgpoc/chapter8/shadows/sphere_vertex.glsl @@ -12,5 +12,5 @@ void main() vec4 f_pos = f_mvp * f_sphere_matrix * f_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/graphics/polygon_offset/PolygonOffset.zig b/src/foundations/scenes/graphics/polygon_offset/PolygonOffset.zig index f99b900..a1c11c5 100644 --- a/src/foundations/scenes/graphics/polygon_offset/PolygonOffset.zig +++ b/src/foundations/scenes/graphics/polygon_offset/PolygonOffset.zig @@ -147,7 +147,7 @@ pub fn renderObject(self: *PolygonOffset, obj_setting: ShadowsUI.objectSetting, var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/graphics/polygon_offset/po_vertex.glsl b/src/foundations/scenes/graphics/polygon_offset/po_vertex.glsl index 3f825bc..2f675b7 100644 --- a/src/foundations/scenes/graphics/polygon_offset/po_vertex.glsl +++ b/src/foundations/scenes/graphics/polygon_offset/po_vertex.glsl @@ -10,6 +10,6 @@ void main() ); mat3 f_norm_matrix = transpose(inverse(mat3(m_matrix* f_xup))); vec4 f_main_pos = m_matrix * f_xup * vec4(f_position.xyz, 1.0); - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); gl_Position = f_mvp * f_main_pos; } \ No newline at end of file diff --git a/src/foundations/scenes/math/barycentric_coordinates/bc_vertex.glsl b/src/foundations/scenes/math/barycentric_coordinates/bc_vertex.glsl index 2ada661..2178eb2 100644 --- a/src/foundations/scenes/math/barycentric_coordinates/bc_vertex.glsl +++ b/src/foundations/scenes/math/barycentric_coordinates/bc_vertex.glsl @@ -11,5 +11,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/math/frustum_planes/FrustumPlanes.zig b/src/foundations/scenes/math/frustum_planes/FrustumPlanes.zig index 7ae3bb5..52ddb83 100644 --- a/src/foundations/scenes/math/frustum_planes/FrustumPlanes.zig +++ b/src/foundations/scenes/math/frustum_planes/FrustumPlanes.zig @@ -234,7 +234,7 @@ pub fn renderSphere(self: *FrustumPlanes) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(sphere_vertex_shader)[0..]); } @@ -269,7 +269,7 @@ pub fn renderParallepiped(self: *FrustumPlanes) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(voxel_vertex_shader)[0..]); } diff --git a/src/foundations/scenes/math/frustum_planes/sphere_vertex.glsl b/src/foundations/scenes/math/frustum_planes/sphere_vertex.glsl index 480d095..2a15948 100644 --- a/src/foundations/scenes/math/frustum_planes/sphere_vertex.glsl +++ b/src/foundations/scenes/math/frustum_planes/sphere_vertex.glsl @@ -11,5 +11,5 @@ void main() vec4 f_pos = f_mvp * f_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/math/frustum_planes/voxel_vertex.glsl b/src/foundations/scenes/math/frustum_planes/voxel_vertex.glsl index 0728484..2ecc5eb 100644 --- a/src/foundations/scenes/math/frustum_planes/voxel_vertex.glsl +++ b/src/foundations/scenes/math/frustum_planes/voxel_vertex.glsl @@ -13,5 +13,5 @@ void main() vec4 f_pos = f_mvp * f_world_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_cube_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_cube_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/math/line/line_vertex.glsl b/src/foundations/scenes/math/line/line_vertex.glsl index d36c0cc..3e89ac6 100644 --- a/src/foundations/scenes/math/line/line_vertex.glsl +++ b/src/foundations/scenes/math/line/line_vertex.glsl @@ -10,5 +10,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/math/line_distance/line_distance_vertex.glsl b/src/foundations/scenes/math/line_distance/line_distance_vertex.glsl index 2ada661..2178eb2 100644 --- a/src/foundations/scenes/math/line_distance/line_distance_vertex.glsl +++ b/src/foundations/scenes/math/line_distance/line_distance_vertex.glsl @@ -11,5 +11,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/math/look_at/LookAt.zig b/src/foundations/scenes/math/look_at/LookAt.zig index 56aedd0..4097cf0 100644 --- a/src/foundations/scenes/math/look_at/LookAt.zig +++ b/src/foundations/scenes/math/look_at/LookAt.zig @@ -90,7 +90,7 @@ pub fn renderCube(self: *LookAt) void { var s: rhi.Shader = .{ .program = prog, .instance_data = false, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(cube_vertex_shader)[0..]); } diff --git a/src/foundations/scenes/math/look_at/look_at_camera_vertex.glsl b/src/foundations/scenes/math/look_at/look_at_camera_vertex.glsl index 2cf4b98..efe14a7 100644 --- a/src/foundations/scenes/math/look_at/look_at_camera_vertex.glsl +++ b/src/foundations/scenes/math/look_at/look_at_camera_vertex.glsl @@ -6,5 +6,5 @@ void main() vec4 pos = f_mvp * f_camera_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/math/look_at/look_at_cube_vertex.glsl b/src/foundations/scenes/math/look_at/look_at_cube_vertex.glsl index 17882eb..d1dc8ee 100644 --- a/src/foundations/scenes/math/look_at/look_at_cube_vertex.glsl +++ b/src/foundations/scenes/math/look_at/look_at_cube_vertex.glsl @@ -6,5 +6,5 @@ void main() vec4 pos = f_mvp * f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/math/plane_distance/PlaneDistance.zig b/src/foundations/scenes/math/plane_distance/PlaneDistance.zig index a58f4f9..7f51b76 100644 --- a/src/foundations/scenes/math/plane_distance/PlaneDistance.zig +++ b/src/foundations/scenes/math/plane_distance/PlaneDistance.zig @@ -57,7 +57,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *PlaneDistan var s: rhi.Shader = .{ .program = reflection_program, .instance_data = false, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(reflection_vertex_shader)[0..]); } @@ -254,7 +254,7 @@ pub fn renderPlane(self: *PlaneDistance) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, .frag_body = plane_frag_shader, }; s.attach(self.allocator, rhi.Shader.single_vertex(plane_vertex_shader)[0..]); @@ -288,7 +288,7 @@ pub fn renderSphere(self: *PlaneDistance) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(sphere_vertex_shader)[0..]); } @@ -340,7 +340,7 @@ pub fn renderParallepiped(self: *PlaneDistance) void { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(self.allocator, rhi.Shader.single_vertex(cube_vertex_shader)[0..]); } @@ -407,19 +407,19 @@ fn triangleFromCubeSurfacePartial(self: *PlaneDistance, program: u32, vindex0: u n0 = math.vector.normalize(math.vector.vec4ToVec3(math.matrix.transformVector( rmi, math.vector.vec3ToVec4Vector( - self.parallelepiped.parallelepiped.attribute_data[index0].normals, + self.parallelepiped.parallelepiped.attribute_data[index0].normal, ), ))); n1 = math.vector.normalize(math.vector.vec4ToVec3(math.matrix.transformVector( rmi, math.vector.vec3ToVec4Vector( - self.parallelepiped.parallelepiped.attribute_data[index1].normals, + self.parallelepiped.parallelepiped.attribute_data[index1].normal, ), ))); n2 = math.vector.normalize(math.vector.vec4ToVec3(math.matrix.transformVector( rmi, math.vector.vec3ToVec4Vector( - self.parallelepiped.parallelepiped.attribute_data[index2].normals, + self.parallelepiped.parallelepiped.attribute_data[index2].normal, ), ))); } diff --git a/src/foundations/scenes/math/plane_distance/cube_vertex.glsl b/src/foundations/scenes/math/plane_distance/cube_vertex.glsl index 0728484..2ecc5eb 100644 --- a/src/foundations/scenes/math/plane_distance/cube_vertex.glsl +++ b/src/foundations/scenes/math/plane_distance/cube_vertex.glsl @@ -13,5 +13,5 @@ void main() vec4 f_pos = f_mvp * f_world_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_cube_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_cube_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/math/plane_distance/plane_frag.glsl b/src/foundations/scenes/math/plane_distance/plane_frag.glsl index b074c6c..9df0cbe 100644 --- a/src/foundations/scenes/math/plane_distance/plane_frag.glsl +++ b/src/foundations/scenes/math/plane_distance/plane_frag.glsl @@ -1,5 +1,5 @@ void main() { - fo_frag_color = vec4(fo_normals.xyz, 0.1) * 0.5 + 0.5; + fo_frag_color = vec4(fo_normal.xyz, 0.1) * 0.5 + 0.5; } diff --git a/src/foundations/scenes/math/plane_distance/plane_vertex.glsl b/src/foundations/scenes/math/plane_distance/plane_vertex.glsl index 3e2ba2f..eb72a6a 100644 --- a/src/foundations/scenes/math/plane_distance/plane_vertex.glsl +++ b/src/foundations/scenes/math/plane_distance/plane_vertex.glsl @@ -13,5 +13,5 @@ void main() vec4 f_pos = f_mvp * f_world_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_plane_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_plane_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/math/plane_distance/reflection_vertex.glsl b/src/foundations/scenes/math/plane_distance/reflection_vertex.glsl index 99d2e62..63e191b 100644 --- a/src/foundations/scenes/math/plane_distance/reflection_vertex.glsl +++ b/src/foundations/scenes/math/plane_distance/reflection_vertex.glsl @@ -7,5 +7,5 @@ void main() vec4 f_pos = f_mvp * f_world_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/math/plane_distance/sphere_vertex.glsl b/src/foundations/scenes/math/plane_distance/sphere_vertex.glsl index 520cf46..bf5dc89 100644 --- a/src/foundations/scenes/math/plane_distance/sphere_vertex.glsl +++ b/src/foundations/scenes/math/plane_distance/sphere_vertex.glsl @@ -10,5 +10,5 @@ void main() vec4 f_pos = f_mvp * f_transform * vec4(f_position.xyz, 1.0); gl_Position = f_pos; f_frag_color = f_i_color; - fo_normals = normalize(transpose(inverse(mat3(f_transform))) * f_normals); + fo_normal = normalize(transpose(inverse(mat3(f_transform))) * f_normal); } \ No newline at end of file diff --git a/src/foundations/scenes/math/unit_circle/unit_circle_vertex.glsl b/src/foundations/scenes/math/unit_circle/unit_circle_vertex.glsl index d36c0cc..3e89ac6 100644 --- a/src/foundations/scenes/math/unit_circle/unit_circle_vertex.glsl +++ b/src/foundations/scenes/math/unit_circle/unit_circle_vertex.glsl @@ -10,5 +10,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/scenes.zig b/src/foundations/scenes/scenes.zig index 1f5d215..5609254 100644 --- a/src/foundations/scenes/scenes.zig +++ b/src/foundations/scenes/scenes.zig @@ -20,7 +20,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: SceneContext) *Scenes { .allocator = allocator, .context = ctx, }; - scenes.initScene(ui.ui_state.scene_type.six_textured_torus); + scenes.initScene(ui.ui_state.scene_type.ten_surface_detail); return scenes; } diff --git a/src/foundations/scenes/shapes/circle/circle_vertex.glsl b/src/foundations/scenes/shapes/circle/circle_vertex.glsl index d36c0cc..3e89ac6 100644 --- a/src/foundations/scenes/shapes/circle/circle_vertex.glsl +++ b/src/foundations/scenes/shapes/circle/circle_vertex.glsl @@ -10,5 +10,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } \ No newline at end of file diff --git a/src/foundations/scenes/shapes/cone_animated/ConeAnimated.zig b/src/foundations/scenes/shapes/cone_animated/ConeAnimated.zig index 481f405..8844f44 100644 --- a/src/foundations/scenes/shapes/cone_animated/ConeAnimated.zig +++ b/src/foundations/scenes/shapes/cone_animated/ConeAnimated.zig @@ -65,7 +65,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *ConeAnimate var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/shapes/cone_animated/ca_vertex.glsl b/src/foundations/scenes/shapes/cone_animated/ca_vertex.glsl index 1168db0..276c77d 100644 --- a/src/foundations/scenes/shapes/cone_animated/ca_vertex.glsl +++ b/src/foundations/scenes/shapes/cone_animated/ca_vertex.glsl @@ -5,5 +5,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/shapes/cube_animated/CubeAnimated.zig b/src/foundations/scenes/shapes/cube_animated/CubeAnimated.zig index f5c38c4..624654a 100644 --- a/src/foundations/scenes/shapes/cube_animated/CubeAnimated.zig +++ b/src/foundations/scenes/shapes/cube_animated/CubeAnimated.zig @@ -54,7 +54,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *CubeAnimate var s: rhi.Shader = .{ .program = prog, .instance_data = false, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/shapes/cube_animated/ca_vertex.glsl b/src/foundations/scenes/shapes/cube_animated/ca_vertex.glsl index 1168db0..276c77d 100644 --- a/src/foundations/scenes/shapes/cube_animated/ca_vertex.glsl +++ b/src/foundations/scenes/shapes/cube_animated/ca_vertex.glsl @@ -5,5 +5,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/shapes/cylinder_animated/CylinderAnimated.zig b/src/foundations/scenes/shapes/cylinder_animated/CylinderAnimated.zig index 52e531c..dac68a3 100644 --- a/src/foundations/scenes/shapes/cylinder_animated/CylinderAnimated.zig +++ b/src/foundations/scenes/shapes/cylinder_animated/CylinderAnimated.zig @@ -54,7 +54,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *CylinderAni var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/shapes/cylinder_animated/ca_vertex.glsl b/src/foundations/scenes/shapes/cylinder_animated/ca_vertex.glsl index 795f64e..20f951a 100644 --- a/src/foundations/scenes/shapes/cylinder_animated/ca_vertex.glsl +++ b/src/foundations/scenes/shapes/cylinder_animated/ca_vertex.glsl @@ -4,5 +4,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/shapes/pyramid/Pyramid.zig b/src/foundations/scenes/shapes/pyramid/Pyramid.zig index 6749218..82dc994 100644 --- a/src/foundations/scenes/shapes/pyramid/Pyramid.zig +++ b/src/foundations/scenes/shapes/pyramid/Pyramid.zig @@ -54,7 +54,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *Pyramid { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/shapes/sphere/Sphere.zig b/src/foundations/scenes/shapes/sphere/Sphere.zig index 3e39cc0..538f472 100644 --- a/src/foundations/scenes/shapes/sphere/Sphere.zig +++ b/src/foundations/scenes/shapes/sphere/Sphere.zig @@ -24,7 +24,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *Sphere { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/scenes/shapes/sphere/sphere_vertex.glsl b/src/foundations/scenes/shapes/sphere/sphere_vertex.glsl index 1168db0..276c77d 100644 --- a/src/foundations/scenes/shapes/sphere/sphere_vertex.glsl +++ b/src/foundations/scenes/shapes/sphere/sphere_vertex.glsl @@ -5,5 +5,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals * 0.5 + 0.5; + fo_normal = f_normal * 0.5 + 0.5; } \ No newline at end of file diff --git a/src/foundations/scenes/shapes/torus/Torus.zig b/src/foundations/scenes/shapes/torus/Torus.zig index 3923291..2fa5013 100644 --- a/src/foundations/scenes/shapes/torus/Torus.zig +++ b/src/foundations/scenes/shapes/torus/Torus.zig @@ -54,7 +54,7 @@ pub fn init(allocator: std.mem.Allocator, ctx: scenes.SceneContext) *Torus { var s: rhi.Shader = .{ .program = prog, .instance_data = true, - .fragment_shader = .normals, + .fragment_shader = .normal, }; s.attach(allocator, rhi.Shader.single_vertex(vertex_shader)[0..]); } diff --git a/src/foundations/shaders/cubemap_vert.glsl b/src/foundations/shaders/cubemap_vert.glsl index 7f6b275..bf8635c 100644 --- a/src/foundations/shaders/cubemap_vert.glsl +++ b/src/foundations/shaders/cubemap_vert.glsl @@ -26,5 +26,5 @@ void main() f_cubemap_f_tc = (f_transform * f_cubemap_xup * vec4(f_position.xyz, 1.0)).xyz; f_tc = f_texture_coords; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } diff --git a/src/foundations/shaders/frag_blinn_phong_lighting.glsl b/src/foundations/shaders/frag_blinn_phong_lighting.glsl index 905c186..47e4c60 100644 --- a/src/foundations/shaders/frag_blinn_phong_lighting.glsl +++ b/src/foundations/shaders/frag_blinn_phong_lighting.glsl @@ -3,7 +3,7 @@ vec4 f_blinn_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/shaders/frag_normals.glsl b/src/foundations/shaders/frag_normals.glsl index d1098c8..b9e4720 100644 --- a/src/foundations/shaders/frag_normals.glsl +++ b/src/foundations/shaders/frag_normals.glsl @@ -2,5 +2,5 @@ void main() { - fo_frag_color = vec4(fo_normals.xyz, 1.0) * 0.5 + 0.5; + fo_frag_color = vec4(fo_normal.xyz, 1.0) * 0.5 + 0.5; } diff --git a/src/foundations/shaders/frag_phong_lighting.glsl b/src/foundations/shaders/frag_phong_lighting.glsl index 987919f..92e6a0a 100644 --- a/src/foundations/shaders/frag_phong_lighting.glsl +++ b/src/foundations/shaders/frag_phong_lighting.glsl @@ -3,7 +3,7 @@ vec4 f_phong_lighting(Material f_mat, Light f_lights[10], uint num_lights, vec4 num_lights = min(num_lights, 10u); vec3 f_V = normalize(f_camera_pos.xyz - fo_vert); - vec3 f_N = normalize(fo_normals); + vec3 f_N = normalize(fo_normal); vec4 rv = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/foundations/shaders/frag_subheader.glsl b/src/foundations/shaders/frag_subheader.glsl index 9fd625b..0aafc23 100644 --- a/src/foundations/shaders/frag_subheader.glsl +++ b/src/foundations/shaders/frag_subheader.glsl @@ -9,6 +9,7 @@ out vec4 fo_frag_color; in vec2 f_tc; in vec4 f_frag_color; -in vec3 fo_normals; +in vec3 fo_normal; in vec3 fo_vert; in vec3 fo_lightdir; +in vec4 fo_tangent; diff --git a/src/foundations/shaders/i_obj_blinn_phong_light_vert.glsl b/src/foundations/shaders/i_obj_blinn_phong_light_vert.glsl index 2f03ab6..94b185d 100644 --- a/src/foundations/shaders/i_obj_blinn_phong_light_vert.glsl +++ b/src/foundations/shaders/i_obj_blinn_phong_light_vert.glsl @@ -13,7 +13,7 @@ void main() vec4 f_main_pos = m_matrix * vec4(f_position.xyz, 1.0); fo_vert = f_main_pos.xyz; - fo_normals = normalize(f_norm_matrix * f_normals); + fo_normal = normalize(f_norm_matrix * f_normal); fo_lightdir = f_light_pos - fo_vert; gl_Position = f_mvp * f_main_pos; diff --git a/src/foundations/shaders/i_obj_gouraud_light_vert.glsl b/src/foundations/shaders/i_obj_gouraud_light_vert.glsl index b565d84..cba8a45 100644 --- a/src/foundations/shaders/i_obj_gouraud_light_vert.glsl +++ b/src/foundations/shaders/i_obj_gouraud_light_vert.glsl @@ -15,7 +15,7 @@ void main() Light f_l = f_lights[0]; vec4 f_P = m_matrix * vec4(f_position.xyz, 1.0); - vec3 f_N = normalize(f_norm_matrix * f_normals); + vec3 f_N = normalize(f_norm_matrix * f_normal); vec3 f_L = normalize(f_light_pos - f_P.xyz); vec3 f_V = normalize(-v_matrix[3].xyz - f_P.xyz); @@ -28,6 +28,6 @@ void main() gl_Position = f_mvp * f_P; f_tc = f_texture_coords; - fo_normals = f_N; + fo_normal = f_N; f_frag_color = vec4((f_ambient + f_diffuse + f_specular), 1.0); } diff --git a/src/foundations/shaders/i_obj_vert.glsl b/src/foundations/shaders/i_obj_vert.glsl index 928800b..19e1e8b 100644 --- a/src/foundations/shaders/i_obj_vert.glsl +++ b/src/foundations/shaders/i_obj_vert.glsl @@ -11,5 +11,5 @@ void main() gl_Position = f_pos; f_tc = f_texture_coords; f_frag_color = f_i_color; - fo_normals = f_normals; + fo_normal = f_normal; } diff --git a/src/foundations/shaders/vertex_attrib_header.glsl b/src/foundations/shaders/vertex_attrib_header.glsl index f3264a0..8ea3de9 100644 --- a/src/foundations/shaders/vertex_attrib_header.glsl +++ b/src/foundations/shaders/vertex_attrib_header.glsl @@ -1,5 +1,5 @@ -#version 460 core layout (location = 0) in vec3 f_position; layout (location = 1) in vec4 f_color; -layout (location = 2) in vec3 f_normals; +layout (location = 2) in vec3 f_normal; layout (location = 3) in vec2 f_texture_coords; +layout (location = 4) in vec4 f_tangent; diff --git a/src/foundations/shaders/vertex_attrib_i_data.glsl b/src/foundations/shaders/vertex_attrib_i_data.glsl index 9d2925c..f690bad 100644 --- a/src/foundations/shaders/vertex_attrib_i_data.glsl +++ b/src/foundations/shaders/vertex_attrib_i_data.glsl @@ -1,5 +1,5 @@ -layout (location = 4) in vec4 f_t_column0; -layout (location = 5) in vec4 f_t_column1; -layout (location = 6) in vec4 f_t_column2; -layout (location = 7) in vec4 f_t_column3; -layout (location = 8) in vec4 f_i_color; +layout (location = 5) in vec4 f_t_column0; +layout (location = 6) in vec4 f_t_column1; +layout (location = 7) in vec4 f_t_column2; +layout (location = 8) in vec4 f_t_column3; +layout (location = 9) in vec4 f_i_color; diff --git a/src/foundations/shaders/vertex_bindless_header.glsl b/src/foundations/shaders/vertex_bindless_header.glsl new file mode 100644 index 0000000..f841f83 --- /dev/null +++ b/src/foundations/shaders/vertex_bindless_header.glsl @@ -0,0 +1 @@ +#extension GL_ARB_bindless_texture : require diff --git a/src/foundations/shaders/vertex_header.glsl b/src/foundations/shaders/vertex_header.glsl new file mode 100644 index 0000000..4ebd0de --- /dev/null +++ b/src/foundations/shaders/vertex_header.glsl @@ -0,0 +1 @@ +#version 460 core diff --git a/src/foundations/shaders/vertex_no_camera.glsl b/src/foundations/shaders/vertex_no_camera.glsl index c226670..cfc2b06 100644 --- a/src/foundations/shaders/vertex_no_camera.glsl +++ b/src/foundations/shaders/vertex_no_camera.glsl @@ -5,5 +5,5 @@ void main() vec4 pos = f_transform * vec4(f_position.xyz, 1.0); gl_Position = pos; f_frag_color = f_color; - fo_normals = f_normals; + fo_normal = f_normal; } diff --git a/src/foundations/shaders/vertex_subheader.glsl b/src/foundations/shaders/vertex_subheader.glsl index b7d713f..a749585 100644 --- a/src/foundations/shaders/vertex_subheader.glsl +++ b/src/foundations/shaders/vertex_subheader.glsl @@ -10,6 +10,7 @@ uniform mat4 f_model_transform; out vec2 f_tc; out vec4 f_frag_color; -out vec3 fo_normals; +out vec3 fo_normal; out vec3 fo_vert; out vec3 fo_lightdir; +out vec4 fo_tangent; diff --git a/src/foundations/ui/ui_state.zig b/src/foundations/ui/ui_state.zig index c093f55..343c593 100644 --- a/src/foundations/ui/ui_state.zig +++ b/src/foundations/ui/ui_state.zig @@ -29,12 +29,12 @@ pub const scene_type = enum(usize) { four_cube_and_pyramid, four_simple_solar_system, five_textured_pyramid, - six_earth, six_textured_torus, six_shuttle, seven_lighting, seven_dolphin, eight_shadows, + ten_surface_detail, }; pub const scenes = union(scene_type) { @@ -68,12 +68,12 @@ pub const scenes = union(scene_type) { four_cube_and_pyramid: *scenes_list.cgpoc.chapter4.CubeAndPyramid, four_simple_solar_system: *scenes_list.cgpoc.chapter4.SimpleSolarSystem, five_textured_pyramid: *scenes_list.cgpoc.chapter5.TexturedPyramid, - six_earth: *scenes_list.cgpoc.chapter6.Earth, six_textured_torus: *scenes_list.cgpoc.chapter6.TexturedTorus, six_shuttle: *scenes_list.cgpoc.chapter6.Shuttle, seven_lighting: *scenes_list.cgpoc.chapter7.Lighting, seven_dolphin: *scenes_list.cgpoc.chapter7.Dolphin, eight_shadows: *scenes_list.cgpoc.chapter8.Shadows, + ten_surface_detail: *scenes_list.cgpoc.chapter10.SurfaceDetail, }; pub const scene_nav_type = enum {