Fancy bunny texture, use color if texture is not bound
This commit is contained in:
parent
406c40280c
commit
9c441c067a
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -6,6 +6,8 @@
|
||||
*.wav filter=lfs diff=lfs merge=lfs -text
|
||||
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpg filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||
*.tiff filter=lfs diff=lfs merge=lfs -text
|
||||
*.bmp filter=lfs diff=lfs merge=lfs -text
|
||||
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||
|
BIN
assets/bunny_tex1.jpg
(Stored with Git LFS)
Normal file
BIN
assets/bunny_tex1.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -52,7 +52,7 @@ void main() {
|
||||
out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
vec3 diffuseColor = texture(diffuse, VertexOut.uv).rgb;
|
||||
vec3 diffuseColor = textureSize(diffuse, 0) == ivec2(0) ? color : texture(diffuse, VertexOut.uv).rgb;
|
||||
vec3 finalColor = vec3(0);
|
||||
|
||||
for (int i = 0; i < lights_count; i++) {
|
||||
|
@ -273,7 +273,7 @@ fn buildAssets(b: *std.Build, step: *Step, assetc: *Step.Compile, path: []const
|
||||
}
|
||||
}
|
||||
|
||||
if (std.mem.endsWith(u8, entry.basename, ".png")) {
|
||||
if (std.mem.endsWith(u8, entry.basename, ".png") or std.mem.endsWith(u8, entry.basename, ".jpg")) {
|
||||
const run_assetc = b.addRunArtifact(assetc);
|
||||
run_assetc.addFileArg(.{ .path = b.pathJoin(&.{ path, entry.path }) });
|
||||
const out_name = try std.mem.concat(
|
||||
|
@ -104,6 +104,7 @@ pub fn resolveMesh(self: *AssetManager, handle: Handle.Mesh) *const LoadedMesh {
|
||||
}
|
||||
|
||||
pub fn resolveTexture(self: *AssetManager, handle: Handle.Texture) *const LoadedTexture {
|
||||
if (handle.id == 0) return &NullTexture;
|
||||
if (self.loaded_assets.getPtr(handle.id)) |asset| {
|
||||
switch (asset.*) {
|
||||
.texture => |*texture| {
|
||||
|
@ -65,6 +65,10 @@ pub const InitMemory = struct {
|
||||
syswm_info: c.SDL_SysWMinfo = .{},
|
||||
};
|
||||
|
||||
pub const Material = struct {
|
||||
diffuse: AssetManager.Handle.Texture = .{},
|
||||
};
|
||||
|
||||
pub const Entity = struct {
|
||||
pub const Flags = packed struct {
|
||||
active: bool = false,
|
||||
@ -87,6 +91,7 @@ pub const Entity = struct {
|
||||
pub const Mesh = struct {
|
||||
handle: AssetManager.Handle.Mesh = .{},
|
||||
color: Vec3 = Vec3.one(),
|
||||
material: Material = .{},
|
||||
};
|
||||
pub const PointLight = struct {
|
||||
radius: f32 = std.math.floatEps(f32), // should never be 0 or bad things happen
|
||||
@ -469,7 +474,7 @@ export fn game_init(global_allocator: *std.mem.Allocator) void {
|
||||
.transform = .{ .pos = Vec3.new(@as(f32, @floatFromInt(i)) * 0.3, 0, 0) },
|
||||
|
||||
.flags = .{ .mesh = true },
|
||||
.mesh = .{ .handle = a.Meshes.bunny },
|
||||
.mesh = .{ .handle = a.Meshes.bunny, .material = .{ .diffuse = a.Textures.bunny_tex1 } },
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -738,7 +743,7 @@ export fn game_update() bool {
|
||||
gl.uniform3fv(2, 1, @ptrCast(&color.data));
|
||||
gl.GL_ARB_bindless_texture.uniformHandleui64ARB(
|
||||
3,
|
||||
g_assetman.resolveTexture(a.Textures.@"test").handle,
|
||||
g_assetman.resolveTexture(ent.mesh.material.diffuse).handle,
|
||||
);
|
||||
|
||||
const mesh_handle = if (ent.flags.mesh) ent.mesh.handle else a.Meshes.sphere;
|
||||
|
@ -32,7 +32,7 @@ pub fn resolveAssetTypeByExtension(path: []const u8) ?AssetType {
|
||||
if (std.mem.endsWith(u8, path, ".glsl")) {
|
||||
return .Shader;
|
||||
}
|
||||
if (std.mem.endsWith(u8, path, ".png")) {
|
||||
if (std.mem.endsWith(u8, path, ".png") or std.mem.endsWith(u8, path, ".jpg")) {
|
||||
return .Texture;
|
||||
}
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user