Skip to content

Commit

Permalink
ambient
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Sep 23, 2024
1 parent 0c5058d commit 2630246
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ wasm build.
- [x] [minimal](https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_003_MinimalGltfFile.html)
- [x] [glb](https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/CesiumMilkTruck/glTF-Binary)
- [x] node
- [ ] texture
- [x] texture
- [ ] animation
- [ ] draco
- [ ] basisu
Expand Down
8 changes: 7 additions & 1 deletion deps/sokol_samples/sample_framework/Scene.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const Quat = rowmath.Quat;
const Mesh = @import("Mesh.zig");
pub const Scene = @This();

const light_pos = [3]f32{ -10, -10, -10 };
const light_color = [3]f32{ 1,1,1 };
const ambient = [3]f32{ 0.2, 0.2, 0.2 };

allocator: std.mem.Allocator = undefined,
meshes: []Mesh = &.{},
pip: sg.Pipeline = undefined,
Expand Down Expand Up @@ -261,7 +265,9 @@ fn draw_mesh(self: *@This(), mesh_index: u32, vp: Mat4, model: Mat4) void {
sg.applyUniforms(.VS, shader.SLOT_vs_params, sg.asRange(&vs_params));

const fs_params = shader.FsParams{
.lightPos = .{ 10, 10, 10 },
.lightPos = light_pos,
.lightColor = light_color,
.ambient = ambient,
};
sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&fs_params));

Expand Down
15 changes: 9 additions & 6 deletions deps/sokol_samples/sample_framework/gltf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ void main() {
@fs fs
uniform fs_params {
vec3 lightPos;
vec3 lightColor;
vec3 ambient;
};
uniform submesh_params {
vec4 material_rgba;
Expand All @@ -40,14 +42,15 @@ out vec4 frag_color;
void main() {
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
float diffuse = max(dot(norm, lightDir), 0.0);

vec4 texel = texture(colorTexture, TexCoord);
// vec3 diffuse = diff * lightColor;
frag_color = texel * vec4(
material_rgba.r * diff,
material_rgba.g * diff,
material_rgba.b * diff,
material_rgba.a);
material_rgba.r * diffuse * lightColor.r + ambient.r,
material_rgba.g * diffuse * lightColor.r + ambient.g,
material_rgba.b * diffuse * lightColor.r + ambient.b,
material_rgba.a
);
}
@end

Expand Down

0 comments on commit 2630246

Please sign in to comment.