Move and change shader module name; in preparation for asset pipeline
This commit is contained in:
@@ -205,4 +205,4 @@ void main() {
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@program program vertex fragment
|
@program main vertex fragment
|
||||||
@@ -30,10 +30,10 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const sokol_mod = sokol_dep.module("sokol");
|
const sokol_mod = sokol_dep.module("sokol");
|
||||||
const shdc_dep = sokol_dep.builder.dependency("shdc", .{});
|
const shdc_dep = sokol_dep.builder.dependency("shdc", .{});
|
||||||
|
|
||||||
const shader_mod = try sokol.shdc.createModule(b, "shader", sokol_mod, .{
|
const shaders_mod = try sokol.shdc.createModule(b, "shaders", sokol_mod, .{
|
||||||
.shdc_dep = shdc_dep,
|
.shdc_dep = shdc_dep,
|
||||||
.input = "src/shader.glsl",
|
.input = "assets/shaders.glsl",
|
||||||
.output = "shader.zig",
|
.output = "shaders.zig",
|
||||||
.slang = .{
|
.slang = .{
|
||||||
.glsl430 = true,
|
.glsl430 = true,
|
||||||
.hlsl5 = true,
|
.hlsl5 = true,
|
||||||
@@ -42,7 +42,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
exe_mod.addImport("cimgui", cimgui_dep.module(cimgui_conf.module_name));
|
exe_mod.addImport("cimgui", cimgui_dep.module(cimgui_conf.module_name));
|
||||||
exe_mod.addImport("shader", shader_mod);
|
exe_mod.addImport("shaders", shaders_mod);
|
||||||
exe_mod.addImport("sokol", sokol_mod);
|
exe_mod.addImport("sokol", sokol_mod);
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
|
|||||||
34
src/game.zig
34
src/game.zig
@@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const ig = @import("cimgui");
|
const ig = @import("cimgui");
|
||||||
const shader = @import("shader");
|
const shaders = @import("shaders");
|
||||||
const sokol = @import("sokol");
|
const sokol = @import("sokol");
|
||||||
|
|
||||||
const sapp = sokol.app;
|
const sapp = sokol.app;
|
||||||
@@ -52,13 +52,13 @@ pub fn init() void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
pipeline = sg.makePipeline(.{
|
pipeline = sg.makePipeline(.{
|
||||||
.shader = sg.makeShader(shader.programShaderDesc(sg.queryBackend())),
|
.shader = sg.makeShader(shaders.mainShaderDesc(sg.queryBackend())),
|
||||||
.layout = blk: {
|
.layout = blk: {
|
||||||
var ret: sg.VertexLayoutState = .{};
|
var ret: sg.VertexLayoutState = .{};
|
||||||
ret.attrs[shader.ATTR_program_positionOS].format = .FLOAT3;
|
ret.attrs[shaders.ATTR_main_positionOS].format = .FLOAT3;
|
||||||
ret.attrs[shader.ATTR_program_texCoord].format = .FLOAT2;
|
ret.attrs[shaders.ATTR_main_texCoord].format = .FLOAT2;
|
||||||
ret.attrs[shader.ATTR_program_normalOS].format = .FLOAT3;
|
ret.attrs[shaders.ATTR_main_normalOS].format = .FLOAT3;
|
||||||
ret.attrs[shader.ATTR_program_tangentOS].format = .FLOAT4;
|
ret.attrs[shaders.ATTR_main_tangentOS].format = .FLOAT4;
|
||||||
break :blk ret;
|
break :blk ret;
|
||||||
},
|
},
|
||||||
.primitive_type = .TRIANGLES,
|
.primitive_type = .TRIANGLES,
|
||||||
@@ -68,7 +68,7 @@ pub fn init() void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
point_light_buffer = sg.makeBuffer(.{
|
point_light_buffer = sg.makeBuffer(.{
|
||||||
.size = @sizeOf([4]shader.PointLight),
|
.size = @sizeOf([4]shaders.PointLight),
|
||||||
.usage = .{
|
.usage = .{
|
||||||
.stream_update = true,
|
.stream_update = true,
|
||||||
.storage_buffer = true,
|
.storage_buffer = true,
|
||||||
@@ -76,7 +76,7 @@ pub fn init() void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
directional_light_buffer = sg.makeBuffer(.{
|
directional_light_buffer = sg.makeBuffer(.{
|
||||||
.size = @sizeOf([4]shader.DirectionalLight),
|
.size = @sizeOf([4]shaders.DirectionalLight),
|
||||||
.usage = .{
|
.usage = .{
|
||||||
.stream_update = true,
|
.stream_update = true,
|
||||||
.storage_buffer = true,
|
.storage_buffer = true,
|
||||||
@@ -139,19 +139,19 @@ pub fn init() void {
|
|||||||
bindings.vertex_buffers[0] = vertex_buffer;
|
bindings.vertex_buffers[0] = vertex_buffer;
|
||||||
bindings.index_buffer = index_buffer;
|
bindings.index_buffer = index_buffer;
|
||||||
|
|
||||||
bindings.views[shader.VIEW_Point_Lights] = sg.makeView(.{
|
bindings.views[shaders.VIEW_Point_Lights] = sg.makeView(.{
|
||||||
.storage_buffer = .{ .buffer = point_light_buffer },
|
.storage_buffer = .{ .buffer = point_light_buffer },
|
||||||
});
|
});
|
||||||
bindings.views[shader.VIEW_Directional_Lights] = sg.makeView(.{
|
bindings.views[shaders.VIEW_Directional_Lights] = sg.makeView(.{
|
||||||
.storage_buffer = .{ .buffer = directional_light_buffer },
|
.storage_buffer = .{ .buffer = directional_light_buffer },
|
||||||
});
|
});
|
||||||
bindings.views[shader.VIEW__BaseColorTexture] = sg.makeView(.{
|
bindings.views[shaders.VIEW__BaseColorTexture] = sg.makeView(.{
|
||||||
.texture = .{ .image = base_color_texture },
|
.texture = .{ .image = base_color_texture },
|
||||||
});
|
});
|
||||||
bindings.views[shader.VIEW__OcclusionRoughnessMetallicTexture] = sg.makeView(.{
|
bindings.views[shaders.VIEW__OcclusionRoughnessMetallicTexture] = sg.makeView(.{
|
||||||
.texture = .{ .image = occlusion_roughness_metallic_texture },
|
.texture = .{ .image = occlusion_roughness_metallic_texture },
|
||||||
});
|
});
|
||||||
bindings.views[shader.VIEW__NormalTexture] = sg.makeView(.{
|
bindings.views[shaders.VIEW__NormalTexture] = sg.makeView(.{
|
||||||
.texture = .{ .image = normal_texture },
|
.texture = .{ .image = normal_texture },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,24 +195,24 @@ pub fn update(dt: f64) void {
|
|||||||
sg.applyPipeline(pipeline);
|
sg.applyPipeline(pipeline);
|
||||||
sg.applyBindings(bindings);
|
sg.applyBindings(bindings);
|
||||||
|
|
||||||
sg.applyUniforms(shader.UB_Global_Uniforms_Vertex, sg.asRange(&shader.GlobalUniformsVertex{
|
sg.applyUniforms(shaders.UB_Global_Uniforms_Vertex, sg.asRange(&shaders.GlobalUniformsVertex{
|
||||||
._MatrixVStoCS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
._MatrixVStoCS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||||
._MatrixWStoVS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
._MatrixWStoVS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
sg.applyUniforms(shader.UB_Object_Uniforms, sg.asRange(&shader.ObjectUniforms{
|
sg.applyUniforms(shaders.UB_Object_Uniforms, sg.asRange(&shaders.ObjectUniforms{
|
||||||
._MatrixOStoWS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
._MatrixOStoWS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||||
._MatrixOStoWSNormal = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
._MatrixOStoWSNormal = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
sg.applyUniforms(shader.UB_Global_Uniforms_Fragment, sg.asRange(&shader.GlobalUniformsFragment{
|
sg.applyUniforms(shaders.UB_Global_Uniforms_Fragment, sg.asRange(&shaders.GlobalUniformsFragment{
|
||||||
._MatrixWStoVS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
._MatrixWStoVS = .{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||||
._AmbientLight = .{ 0.1, 0.1, 0.1 },
|
._AmbientLight = .{ 0.1, 0.1, 0.1 },
|
||||||
._PointLightCount = 0,
|
._PointLightCount = 0,
|
||||||
._DirectionalLightCount = 0,
|
._DirectionalLightCount = 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
sg.applyUniforms(shader.UB_Material_Uniforms, sg.asRange(&shader.MaterialUniforms{
|
sg.applyUniforms(shaders.UB_Material_Uniforms, sg.asRange(&shaders.MaterialUniforms{
|
||||||
._TextureIndex = 0,
|
._TextureIndex = 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const ig = @import("cimgui");
|
const ig = @import("cimgui");
|
||||||
const shader = @import("shader");
|
|
||||||
const sokol = @import("sokol");
|
const sokol = @import("sokol");
|
||||||
|
|
||||||
const sapp = sokol.app;
|
const sapp = sokol.app;
|
||||||
|
|||||||
Reference in New Issue
Block a user