Skip to content

Commit 35984d2

Browse files
mvaligurskyMartin Valigurskywilleastcott
authored
WGSL support for picker pass (#7594)
* WGSL support for picker pass * Update src/scene/shader-lib/chunks-wgsl/common/frag/pick.js Co-authored-by: Will Eastcott <[email protected]> --------- Co-authored-by: Martin Valigursky <[email protected]> Co-authored-by: Will Eastcott <[email protected]>
1 parent 57eaa10 commit 35984d2

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import litForwardMainPS from './lit/frag/pass-forward/litForwardMain.js';
7878
import litForwardPostCodePS from './lit/frag/pass-forward/litForwardPostCode.js';
7979
import litForwardPreCodePS from './lit/frag/pass-forward/litForwardPreCode.js';
8080
import litMainVS from './lit/vert/litMain.js';
81-
// import litOtherMainPS from './lit/frag/pass-other/litOtherMain.js';
81+
import litOtherMainPS from './lit/frag/pass-other/litOtherMain.js';
8282
import litShaderArgsPS from './standard/frag/litShaderArgs.js';
8383
import litShaderCorePS from './standard/frag/litShaderCore.js';
8484
import litShadowMainPS from './lit/frag/pass-shadow/litShadowMain.js';
@@ -143,7 +143,7 @@ import parallaxPS from './standard/frag/parallax.js';
143143
// import particle_stretchVS from './particle/vert/particle_stretch.js';
144144
// import particle_TBNVS from './particle/vert/particle_TBN.js';
145145
// import particle_wrapVS from './particle/vert/particle_wrap.js';
146-
// import pickPS from './common/frag/pick.js';
146+
import pickPS from './common/frag/pick.js';
147147
import reflDirPS from './lit/frag/reflDir.js';
148148
import reflDirAnisoPS from './lit/frag/reflDirAniso.js';
149149
import reflectionCCPS from './lit/frag/reflectionCC.js';
@@ -289,7 +289,7 @@ const shaderChunksWGSL = {
289289
litForwardPostCodePS,
290290
litForwardPreCodePS,
291291
litMainVS,
292-
// litOtherMainPS,
292+
litOtherMainPS,
293293
litShaderArgsPS,
294294
litShaderCorePS,
295295
litShadowMainPS,
@@ -354,7 +354,7 @@ const shaderChunksWGSL = {
354354
// particle_stretchVS,
355355
// particle_TBNVS,
356356
// particle_wrapVS,
357-
// pickPS,
357+
pickPS,
358358
reflDirPS,
359359
reflDirAnisoPS,
360360
reflectionCCPS,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default /* wgsl */`
2+
uniform meshInstanceId: u32;
3+
4+
fn getPickOutput() -> vec4f {
5+
let inv: vec4f = vec4f(1.0 / 255.0);
6+
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
7+
let col: vec4u = (vec4u(uniform.meshInstanceId) >> shifts) & vec4u(0xffu);
8+
return vec4f(col) * inv;
9+
}`;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// main shader entry point for the lit material for other render passes
2+
export default /* wgsl */`
3+
4+
#ifdef PICK_PASS
5+
#include "pickPS"
6+
#endif
7+
8+
#ifdef PREPASS_PASS
9+
#include "floatAsUintPS"
10+
#endif
11+
12+
@fragment
13+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
14+
var output: FragmentOutput;
15+
16+
evaluateFrontend();
17+
18+
#ifdef PICK_PASS
19+
output.color = getPickOutput();
20+
#endif
21+
22+
#ifdef DEPTH_PASS
23+
output.color = vec4(1.0, 1.0, 1.0, 1.0);
24+
#endif
25+
26+
#ifdef PREPASS_PASS
27+
output.color = float2vec4(vLinearDepth);
28+
#endif
29+
30+
return output;
31+
}
32+
`;

src/scene/shader-lib/chunks/common/frag/pick.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default /* glsl */`
22
uniform uint meshInstanceId;
33
44
vec4 getPickOutput() {
5-
const vec4 inv = vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
5+
const vec4 inv = vec4(1.0 / 255.0);
66
const uvec4 shifts = uvec4(16, 8, 0, 24);
77
uvec4 col = (uvec4(meshInstanceId) >> shifts) & uvec4(0xff);
88
return vec4(col) * inv;

0 commit comments

Comments
 (0)