summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3d/renderer.cc13
-rw-r--r--src/gpu/effect.cc5
-rw-r--r--src/gpu/gpu.cc1
-rw-r--r--src/tests/test_3d_render.cc4
4 files changed, 9 insertions, 14 deletions
diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc
index 9f3f40c..215cd97 100644
--- a/src/3d/renderer.cc
+++ b/src/3d/renderer.cc
@@ -126,16 +126,16 @@ fn map_scene(p: vec3<f32>, skip_idx: u32) -> f32 {
fn calc_shadow(ro: vec3<f32>, rd: vec3<f32>, tmin: f32, tmax: f32, skip_idx: u32) -> f32 {
var res = 1.0;
var t = tmin;
- for (var i = 0; i < 30; i = i + 1) {
+ for (var i = 0; i < 32; i = i + 1) {
let h = map_scene(ro + rd * t, skip_idx);
if (h < 0.001) {
return 0.0;
}
- res = min(res, 8.0 * h / t); // Soft shadow k=8
+ res = min(res, 32.0 * h / t); // Sharper shadow k=32
t = t + h;
if (t > tmax) { break; }
}
- return res;
+ return clamp(res, 0.0, 1.0);
}
fn get_normal(p: vec3<f32>, obj_type: f32) -> vec3<f32> {
@@ -156,7 +156,8 @@ 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));
+ // Slanted light for better shadow visibility
+ let light_dir = normalize(vec3<f32>(0.5, 1.0, 0.5));
if (obj_type <= 0.0) { // Rasterized object
p = in.world_pos;
@@ -166,7 +167,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
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);
+ base_color = base_color * (0.4 + 0.6 * 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));
@@ -192,7 +193,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
normal = normalize(mat3 * get_normal(q_hit, obj_type));
}
- let shadow = calc_shadow(p + normal * 0.01, light_dir, 0.01, 20.0, in.instance_index);
+ let shadow = calc_shadow(p + normal * 0.02, light_dir, 0.02, 20.0, in.instance_index);
let lighting = (max(dot(normal, light_dir), 0.0) * shadow) + 0.1;
return vec4<f32>(base_color * lighting, 1.0);
}
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index f24fa96..0d4dde7 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -210,11 +210,6 @@ void MainSequence::resize(int width, int height) {
void MainSequence::render_frame(float global_time, float beat, float peak,
float aspect_ratio, WGPUSurface surface) {
- static bool first_frame = true;
- if (first_frame) {
- printf("MainSequence First Frame: %dx%d\n", width_, height_);
- first_frame = false;
- }
WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr);
std::vector<SequenceItem*> scene_effects;
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index 5537433..3e8981c 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -367,7 +367,6 @@ void gpu_init(PlatformState* platform_state) {
g_config.usage = WGPUTextureUsage_RenderAttachment;
g_config.width = platform_state->width;
g_config.height = platform_state->height;
- printf("WebGPU Init: %dx%d\n", g_config.width, g_config.height);
g_config.presentMode = WGPUPresentMode_Fifo;
g_config.alphaMode = WGPUCompositeAlphaMode_Opaque;
wgpuSurfaceConfigure(g_surface, &g_config);
diff --git a/src/tests/test_3d_render.cc b/src/tests/test_3d_render.cc
index f98ee7c..11cca46 100644
--- a/src/tests/test_3d_render.cc
+++ b/src/tests/test_3d_render.cc
@@ -147,7 +147,7 @@ void setup_scene() {
// Center object
Object3D center(ObjectType::TORUS);
- center.position = vec3(0, 0, 0);
+ center.position = vec3(0, 1.5f, 0); // Elevated
center.scale = vec3(1.5f, 1.5f, 1.5f);
center.color = vec4(1, 0, 0, 1);
g_scene.add_object(center);
@@ -164,7 +164,7 @@ void setup_scene() {
Object3D obj(type);
float angle = (rand() % 360) * 0.01745f;
float dist = 4.0f + (rand() % 100) * 0.05f;
- float height = -1.0f + (rand() % 100) * 0.04f;
+ float height = 0.5f + (rand() % 100) * 0.04f; // Elevated
obj.position = vec3(std::cos(angle) * dist, height, std::sin(angle) * dist);