|
When a plane has non-uniform scaling (e.g., floor with scale 20,0.01,20),
transforming points to local space distorts SDF distances. For a horizontal
plane with Y-scale of 0.01, distances become 100x too large in local space.
Fix: Multiply plane distances by the scale factor along the normal direction
(Y component for horizontal planes). This corrects shadow calculations while
maintaining the large floor area needed for visualization.
Reverted incorrect uniform scale fix (c23f3b9) that made floor too small.
|
|
Fixed incorrect mesh shadow rendering caused by applying scale factor to
mesh AABBs which already have correct local-space extents.
ROOT CAUSE:
The 's' scale factor (line 44) is meant for UNIT primitives (sphere,
box, torus) that are scaled by the model matrix. Meshes (type 5.0)
already store their correct AABB extents in obj_params.yzw, so applying
's' caused incorrect shadow sizes.
ISSUE:
let s = min(length(obj.model[0].xyz), ...);
if (obj.params.x != 4.0) { // Excluded planes only
d = min(d, get_dist(q, obj.params) * s); // ❌ WRONG for meshes!
}
FIX:
if (obj.params.x != 4.0 && obj.params.x != 5.0) { // Exclude planes AND meshes
d = min(d, get_dist(q, obj.params) * s);
} else {
d = min(d, get_dist(q, obj.params)); // No scaling
}
EXPLANATION:
- Type 1.0 (Sphere): Unit sphere, scaled by 's' ✓
- Type 2.0 (Box): Unit box, scaled by 's' ✓
- Type 3.0 (Torus): Unit torus, scaled by 's' ✓
- Type 4.0 (Plane): Special case, no scaling ✓
- Type 5.0 (Mesh): AABB already has correct size, no scaling needed ✓
FILES FIXED:
- assets/final/shaders/render/scene_query_linear.wgsl
- assets/final/shaders/render/scene_query_bvh.wgsl
PARTIAL FIX:
This fixes mesh shadow sizing issues. Shadow rotation limitation remains
(AABBs are axis-aligned, don't rotate with mesh - this is a fundamental
AABB limitation, not a bug).
handoff(Claude): Mesh shadows now correctly sized. Investigating floor
shadow stretching issue next (likely related to plane scaling).
|