forked from lumalabs/luma-web-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoCustomShaders.ts
109 lines (88 loc) · 2.59 KB
/
DemoCustomShaders.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { LumaSplatsLoader, LumaSplatsThree } from "@lumaai/luma-web";
import { FogExp2, Uniform } from "three";
import { DemoProps } from '.';
import { downloadArtifacts } from "./util/DownloadArtifacts";
export function DemoCustomShaders(props: DemoProps) {
let { renderer, camera, scene, gui } = props;
let uniformTime = new Uniform(0);
let splatLoader = new LumaSplatsLoader({ captureUrl: '' });
let splats = new LumaSplatsThree({
// Chateau de Menthon - Annecy @Yannick_Cerrutti
source: `https://lumalabs.ai/capture/da82625c-9c8d-4d05-a9f7-3367ecab438c`,
enableThreeShaderIntegration: true,
onBeforeRender: () => {
uniformTime.value = performance.now() / 1000;
}
});
scene.add(splats);
gui.add(splats, 'enableThreeShaderIntegration').name("Use Three Pipeline");
splats.setShaderHooks({
vertexShaderHooks: {
additionalUniforms: {
time_s: ['float', uniformTime],
},
// additionalGlobals: /*glsl*/``,
// onMainEnd: /*glsl*/`
// (vec4 p) {
// return p;
// }
// `,
// returns a mat4
getSplatTransform: /*glsl*/`
(vec3 position, uint layersBitmask) {
// sin wave on x-axis
float x = 0.;
float z = 0.;
float y = sin(position.x * 1.0 + time_s) * 0.1;
return mat4(
1., 0., 0., 0,
0., 1., 0., 0,
0., 0., 1., 0,
x, y, z, 1.
);
}
`,
// getSplatColor: `
// (vec4 rgba, vec3 position, uint layersBitmask) {
// return rgba * vec4(abs(normalize(position)), 1.0);
// }
// `
}
});
splats.onInitialCameraTransform = transform => {
camera.matrix.copy(transform);
camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
camera.updateMatrixWorld();
};
let layersEnabled = {
background: true,
foreground: true,
}
function updateSemanticMask() {
splats.semanticsMask =
(layersEnabled.background ? 1 : 0) |
(layersEnabled.foreground ? 2 : 0);
}
updateSemanticMask();
let layersFolder = gui.addFolder('layers');
layersFolder.add(layersEnabled, 'background').onChange(updateSemanticMask);
layersFolder.add(layersEnabled, 'foreground').onChange(updateSemanticMask);
layersFolder.hide();
splatLoader.semanticsReady.then(value => {
if (value != null) {
layersFolder.show();
}
});
// fog
scene.fog = new FogExp2(0xEEEEEE, 0.05);
scene.background = scene.fog.color;
// gui for fog
gui.add(scene.fog, 'density', 0, 0.3).name('fog density');
gui.addColor(scene.fog, 'color').name('fog color');
gui.add({downloadArtifacts: () => downloadArtifacts(splatLoader)}, 'downloadArtifacts');
return {
dispose: () => {
splats.dispose();
}
}
}