More refactors around assets. Trust me, we need them
This commit is contained in:
106
src/shaders.zig
Normal file
106
src/shaders.zig
Normal file
@@ -0,0 +1,106 @@
|
||||
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 main_vert_spv align(4) = @embedFile("shaders/main_vert.spv").*;
|
||||
pub const main_frag_spv align(4) = @embedFile("shaders/main_frag.spv").*;
|
||||
Reference in New Issue
Block a user