File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
packages/ranim-render/src/pipelines/shaders Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,14 @@ struct FragmentOutput {
3030}
3131
3232fn compute_lighting (world_pos : vec3 <f32 >, world_normal : vec3 <f32 >, base_color : vec4 <f32 >) -> vec4 <f32 > {
33- var normal : vec3 <f32 >;
34- // If the interpolated normal is near-zero, fall back to flat shading via screen-space derivatives
35- if (dot (world_normal , world_normal ) < 0 .0001 ) {
36- normal = normalize (cross (dpdx (world_pos ), dpdy (world_pos )));
37- } else {
38- normal = normalize (world_normal );
39- }
33+ // Compute both normals unconditionally (derivatives require uniform control flow)
34+ let flat_normal = normalize (cross (dpdx (world_pos ), dpdy (world_pos )));
35+ let smooth_normal = normalize (world_normal );
36+
37+ // Select which normal to use based on whether world_normal is near-zero
38+ let use_flat = dot (world_normal , world_normal ) < 0 .0001 ;
39+ let normal = select (smooth_normal , flat_normal , use_flat );
40+
4041 let light_dir = normalize (vec3 <f32 >(0 .3 , 1 .0 , 0 .5 ));
4142 let ambient = 0 .35 ;
4243 let diffuse = abs (dot (normal , light_dir ));
@@ -71,6 +72,7 @@ fn fs_color(
7172 }
7273
7374 discard ;
75+ return vec4 <f32 >(0 .0 ); // To make wasm happy
7476}
7577
7678@fragment
You can’t perform that action at this time.
0 commit comments