summaryrefslogtreecommitdiff
path: root/src/3d/renderer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/3d/renderer.cc')
-rw-r--r--src/3d/renderer.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc
index 6de7fee..14c05f7 100644
--- a/src/3d/renderer.cc
+++ b/src/3d/renderer.cc
@@ -151,6 +151,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
var p: vec3<f32>;
var normal: vec3<f32>;
+ var base_color = in.color.rgb;
let light_dir = normalize(vec3<f32>(0.2, 1.0, 0.2)); // More vertical light for easier shadow debugging
if (obj_type == 0.0) { // Rasterized object
@@ -160,6 +161,11 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
// Correct normal transformation using inverse transpose
let mat3_it = mat3x3<f32>(obj.model_inv_tr[0].xyz, obj.model_inv_tr[1].xyz, obj.model_inv_tr[2].xyz);
normal = normalize(mat3_it * local_normal);
+
+ // Apply grid texture for color to floor
+ let uv = p.xz * 0.1;
+ let grid_val = textureSample(noise_tex, noise_sampler, uv).r;
+ base_color = base_color * (0.3 + 0.7 * grid_val);
} else { // SDF object
let center = vec3<f32>(obj.model[3].x, obj.model[3].y, obj.model[3].z);
let scale = length(vec3<f32>(obj.model[0].x, obj.model[0].y, obj.model[0].z));
@@ -224,8 +230,9 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let shadow = calc_shadow(p + normal * 0.01, light_dir, 0.0, 20.0);
let lighting = (max(dot(normal, light_dir), 0.0) * shadow) + 0.1;
- return vec4<f32>(in.color.rgb * lighting, 1.0);
+ return vec4<f32>(base_color * lighting, 1.0);
}
+
)";
void Renderer3D::init(WGPUDevice device, WGPUQueue queue,