110 lines
3.4 KiB
Zig
110 lines
3.4 KiB
Zig
const math = @import("math.zig");
|
|
|
|
const Materials = @import("assets/Materials.zig");
|
|
const Matrix4x4 = math.Matrix4x4;
|
|
const GenericBuffer = @import("engine/GenericBuffer.zig").GenericBuffer;
|
|
const Textures = @import("assets/Textures.zig");
|
|
const Vector2 = math.Vector2;
|
|
const Vector3 = math.Vector3;
|
|
const Vector4 = math.Vector4;
|
|
|
|
pub const VertexBuffer = GenericBuffer(void, Vertex);
|
|
pub const IndexBuffer = GenericBuffer(void, Index);
|
|
pub const GlobalUniformsBuffer = GenericBuffer(GlobalUniforms, void);
|
|
pub const PointLightBuffer = GenericBuffer(u32, PointLight);
|
|
pub const DirectionalLightBuffer = GenericBuffer(u32, DirectionalLight);
|
|
pub const MaterialBuffer = GenericBuffer(void, Material);
|
|
pub const ObjectUniformsBuffer = GenericBuffer(void, ObjectUniforms);
|
|
|
|
pub const Vertex = extern struct {
|
|
positionOS: [3]f32,
|
|
texCoord: [2]u16,
|
|
normalOS: [3]i8,
|
|
tangentOS: [4]i8,
|
|
|
|
pub fn init(position_os: Vector3, tex_coord: Vector2, normal_os: Vector3, tangent_os: Vector4) Vertex {
|
|
return .{
|
|
.positionOS = position_os.asArray(),
|
|
.texCoord = tex_coord.asArrayNorm(u16),
|
|
.normalOS = normal_os.asArrayNorm(i8),
|
|
.tangentOS = tangent_os.asArrayNorm(i8),
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const Index = u16;
|
|
|
|
pub const GlobalUniforms = extern struct {
|
|
matrixWStoVS: [16]f32,
|
|
matrixVStoCS: [16]f32,
|
|
ambientLight: [3]f32,
|
|
|
|
pub fn init(matrix_ws_to_vs: Matrix4x4, matrix_vs_to_cs: Matrix4x4, ambient_light: Vector3) GlobalUniforms {
|
|
return .{
|
|
.matrixWStoVS = matrix_ws_to_vs.asArray(),
|
|
.matrixVStoCS = matrix_vs_to_cs.asArray(),
|
|
.ambientLight = ambient_light.asArray(),
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const PointLight = extern struct {
|
|
positionWS: [3]f32,
|
|
color: [3]f32,
|
|
|
|
pub fn init(position_ws: Vector3, color: Vector3) PointLight {
|
|
return .{
|
|
.positionWS = position_ws.asArray(),
|
|
.color = color.asArray(),
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const DirectionalLight = extern struct {
|
|
directionWS: [3]f32,
|
|
color: [3]f32,
|
|
|
|
pub fn init(direction_ws: Vector3, color: Vector3) DirectionalLight {
|
|
return .{
|
|
.directionWS = direction_ws.asArray(),
|
|
.color = color.asArray(),
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const Material = extern struct {
|
|
base_color: [3]f32,
|
|
emissive: [3]f32,
|
|
ior: f32,
|
|
metallic: f32,
|
|
normal_scale: f32,
|
|
occlusion_texture_strength: f32,
|
|
roughness: f32,
|
|
|
|
base_color_texture: Textures.Id,
|
|
emissive_texture: Textures.Id,
|
|
normal_texture: Textures.Id,
|
|
occlusion_roughness_metallic_texture: Textures.Id,
|
|
};
|
|
|
|
pub const ObjectUniforms = extern struct {
|
|
matrixOStoWS: [16]f32,
|
|
matrixOStoWSNormal: [16]f32,
|
|
|
|
material: Materials.Id,
|
|
|
|
pub fn init(matrix_os_to_ws: Matrix4x4, matrix_ow_to_ws_normal: Matrix4x4, material: Materials.Id) ObjectUniforms {
|
|
return .{
|
|
.matrixOStoWS = matrix_os_to_ws.asArray(),
|
|
.matrixOStoWSNormal = matrix_ow_to_ws_normal.asArray(),
|
|
.material = material,
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const equirect_to_cube_comp_spv align(4) = @embedFile("shaders/equirect_to_cube_comp.spv").*;
|
|
pub const main_vert_spv align(4) = @embedFile("shaders/main_vert.spv").*;
|
|
pub const main_frag_spv align(4) = @embedFile("shaders/main_frag.spv").*;
|
|
pub const skybox_vert_spv align(4) = @embedFile("shaders/skybox_vert.spv").*;
|
|
pub const skybox_frag_spv align(4) = @embedFile("shaders/skybox_frag.spv").*;
|