forked from webgpu/webgpu-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfragmentForwardRendering.wgsl
More file actions
37 lines (31 loc) · 985 Bytes
/
Copy pathfragmentForwardRendering.wgsl
File metadata and controls
37 lines (31 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
enable primitive_index;
struct Frame {
viewProjectionMatrix : mat4x4f,
invViewProjectionMatrix : mat4x4f,
pickCoord: vec2f,
pickedPrimitive: u32,
}
@group(0) @binding(1) var<uniform> frame : Frame;
struct PassOutput {
@location(0) color : vec4f,
@location(1) primitive : u32,
}
@fragment
fn main(
@location(0) fragNormal: vec3f,
@builtin(primitive_index) primIndex: u32
) -> PassOutput {
let lightDirection = normalize(vec3f(4, 10, 6));
let light = dot(normalize(fragNormal), lightDirection) * 0.5 + 0.5;
let surfaceColor = vec4f(0.8, 0.8, 0.8, 1.0);
var output : PassOutput;
// Highlight the primitive if it's the selected one, otherwise shade normally.
if (primIndex+1 == frame.pickedPrimitive) {
output.color = vec4f(1.0, 1.0, 0.0, 1.0);
} else {
output.color = vec4f(surfaceColor.xyz * light, surfaceColor.a);
}
// Adding one to each primitive so that 0 can mean "nothing picked"
output.primitive = primIndex+1;
return output;
}