Skip to content

Commit 2337468

Browse files
committed
Light and selection fixes
1 parent 9e8459c commit 2337468

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

webgpu/labels.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class Labels(Renderer):
1111
vertex_entry_point: str = "vertexText"
1212
fragment_entry_point: str = "fragmentFont"
13+
select_entry_point: str = ""
1314
n_vertices: int = 6
1415

1516
"""Render a list of strings on screen

webgpu/scene.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ def select(self, x: int, y: int):
206206

207207
ev = SelectEvent(x, y, read_buffer(buffer))
208208
if ev.obj_id > 0:
209-
p = ev.calculate_position(self.options.camera)
210209
for parent in objects:
211210
for obj in parent.all_renderer():
212211
if obj._id == ev.obj_id:

webgpu/shaders/camera.wgsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ fn cameraMapNormal(n: vec3f) -> vec4f {
2020
return u_camera.normal_mat * vec4(n, 1.0);
2121
}
2222

23-
24-
@fragment fn fragment_select_default(
23+
#ifdef SELECT_PIPELINE
24+
@fragment fn fragment_select_no_clipping(
2525
@builtin(position) p: vec4f,
2626
) -> @location(0) vec4<u32> {
2727
return vec4<u32>(@RENDER_OBJECT_ID@, bitcast<u32>(p.z), 0, 0);
2828
}
29+
#endif SELECT_PIPELINE

webgpu/shaders/clipping.wgsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ fn checkClipping(p: vec3<f32>) {
3333
}
3434
}
3535

36+
#ifdef SELECT_PIPELINE
37+
@fragment fn fragment_select_default(
38+
@builtin(position) p: vec4f,
39+
@location(0) p3: vec3f,
40+
) -> @location(0) vec4<u32> {
41+
checkClipping(p3);
42+
return vec4<u32>(@RENDER_OBJECT_ID@, bitcast<u32>(p.z), 0, 0);
43+
}
44+
#endif SELECT_PIPELINE

webgpu/shaders/light.wgsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ fn lightCalcBrightness(p: vec3f, normal: vec3f) -> vec2f {
2020

2121
let dim = 1.0;
2222
var spec = pow( max( dot(r,view) , 0.0 ), u_light.shininess );
23-
let sDotN = max( dot( normalize(u_light.direction), n ), 0.0 );
23+
var sDotN = dot( normalize(u_light.direction), n );
24+
if (sDotN < 0.0) {
25+
sDotN = -0.5*sDotN;
26+
}
2427
let diffuse = u_light.diffuse * sDotN;
2528
if(diffuse==0.0 || u_light.shininess ==0.0) {
2629
spec = 0.0;

0 commit comments

Comments
 (0)