add basic edge shading
This commit is contained in:
parent
c600c82e8f
commit
c19a19166b
5 changed files with 73 additions and 182 deletions
|
|
@ -3,6 +3,7 @@ const raylib_helper = @import("../lib_helpers/raylib_helper.zig");
|
|||
const raylib = raylib_helper.raylib;
|
||||
const v3 = raylib_helper.v3;
|
||||
const A7r = std.mem.Allocator;
|
||||
const comptimePrint = std.fmt.comptimePrint;
|
||||
|
||||
const RawQuad = struct {
|
||||
tile: u32,
|
||||
|
|
@ -15,6 +16,24 @@ const RawQuad = struct {
|
|||
height: f32,
|
||||
};
|
||||
|
||||
const Metadata1 = packed struct {
|
||||
ambient_occlusion_1: u32,
|
||||
ambient_occlusion_2: u32,
|
||||
ambient_occlusion_corner1: bool,
|
||||
ambient_occlusion_corner2: bool,
|
||||
ambient_occlusion_corner3: bool,
|
||||
quad_height: u6,
|
||||
quad_width: u6,
|
||||
unused: u17 = 0,
|
||||
unused_2: u32 = 0,
|
||||
};
|
||||
|
||||
comptime {
|
||||
if (@bitSizeOf(Metadata1) != 128) {
|
||||
@compileError(comptimePrint("Metadata 1 has wrong size. Expected 128 bits, found {}", .{@bitSizeOf(Metadata1)}));
|
||||
}
|
||||
}
|
||||
|
||||
pub const Chunk = struct {
|
||||
tiles: []u32,
|
||||
a7r: A7r,
|
||||
|
|
@ -151,6 +170,7 @@ pub const Chunk = struct {
|
|||
const texcoords: [*]f32 = @ptrCast(@alignCast(raylib.MemAlloc(arr_size * 2)));
|
||||
const texcoords2: [*]f32 = @ptrCast(@alignCast(raylib.MemAlloc(arr_size * 2)));
|
||||
const normals: [*]f32 = @ptrCast(@alignCast(raylib.MemAlloc(arr_size * 3)));
|
||||
const metadata1_packed: [*]f32 = @ptrCast(@alignCast(raylib.MemAlloc(arr_size * 4)));
|
||||
|
||||
for (raw_quads.items, 0..) |raw_quad, i| {
|
||||
if (raw_quad.tile <= 0) continue;
|
||||
|
|
@ -214,6 +234,22 @@ pub const Chunk = struct {
|
|||
texcoords[12 * i + 11] = bottom_uv;
|
||||
texcoords2[12 * i + 10] = 0.0;
|
||||
texcoords2[12 * i + 11] = raw_quad.height;
|
||||
|
||||
for (0..6) |j| {
|
||||
const metadata1 = Metadata1{
|
||||
.ambient_occlusion_1 = 0xffffffff,
|
||||
.ambient_occlusion_2 = 0xffffffff,
|
||||
.ambient_occlusion_corner1 = true,
|
||||
.ambient_occlusion_corner2 = true,
|
||||
.ambient_occlusion_corner3 = true,
|
||||
.quad_height = @intFromFloat(raw_quad.height),
|
||||
.quad_width = @intFromFloat(raw_quad.width),
|
||||
};
|
||||
const metadata1_baked: [4]f32 = @bitCast(metadata1);
|
||||
for (0..4) |k| {
|
||||
metadata1_packed[24 * i + 4 * j + k] = @bitCast(@as(f32, metadata1_baked[k]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mesh = raylib.Mesh{
|
||||
|
|
@ -224,6 +260,7 @@ pub const Chunk = struct {
|
|||
.texcoords = texcoords,
|
||||
.texcoords2 = texcoords2,
|
||||
.normals = normals,
|
||||
.tangents = metadata1_packed,
|
||||
|
||||
.vaoId = 0,
|
||||
.vboId = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue