Skip to content

Commit 52593e6

Browse files
committed
feat: updated readme
1 parent fe4b0f0 commit 52593e6

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WebGL Forward+ and Clustered Deferred Shading
1414

1515
[![](img/video.mp4)](TODO)
1616

17-
### (TODO: Your README)
17+
## Forward+
1818

1919
*DO NOT* leave the README to the last minute! It is a crucial part of the
2020
project, and we will not be able to grade you without a good README.

src/shaders/shaders.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ export const constants = {
4242

4343
function evalShaderRaw(raw: string) {
4444
let processed = raw;
45-
for (const [key, value] of Object.entries(constants)) {
46-
const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
47-
processed = processed.replace(regex, String(value));
45+
46+
const sortedEntries = Object.entries(constants).sort((a, b) => b[0].length - a[0].length);
47+
48+
for (const [key, value] of sortedEntries) {
49+
const placeholder = '${' + key + '}';
50+
processed = processed.replaceAll(placeholder, String(value));
4851
}
52+
4953
return processed;
5054
}
5155

@@ -66,3 +70,4 @@ export const clusteredDeferredFullscreenFragSrc: string = processShaderRaw(clust
6670

6771
export const moveLightsComputeSrc: string = processShaderRaw(moveLightsComputeRaw);
6872
export const clusteringComputeSrc: string = processShaderRaw(clusteringComputeRaw);
73+

vite.config.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,35 @@ export default defineConfig({
44
build: {
55
target: 'esnext'
66
},
7-
base: process.env.GITHUB_ACTIONS_BASE || undefined
7+
base: process.env.GITHUB_ACTIONS_BASE || undefined,
8+
plugins: [{
9+
name: 'wgsl-shader-preprocessor',
10+
transform(code, id) {
11+
if (id.includes('.wgsl') && id.includes('?raw')) {
12+
const constants = {
13+
bindGroup_scene: 0,
14+
bindGroup_model: 1,
15+
bindGroup_material: 2,
16+
moveLightsWorkgroupSize: 128,
17+
lightRadius: 2,
18+
clusterSizeX: 16,
19+
clusterSizeY: 9,
20+
clusterSizeZ: 24,
21+
clusteringWorkgroupSize: 64,
22+
maxLightsPerCluster: 500
23+
};
24+
25+
let processed = code;
26+
for (const [key, value] of Object.entries(constants)) {
27+
const placeholder = '${' + key + '}';
28+
processed = processed.replaceAll(placeholder, String(value));
29+
}
30+
31+
return {
32+
code: processed,
33+
map: null
34+
};
35+
}
36+
}
37+
}]
838
})

0 commit comments

Comments
 (0)