File tree Expand file tree Collapse file tree 3 files changed +40
-5
lines changed
Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Original file line number Diff line number Diff 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
2020project, and we will not be able to grade you without a good README.
Original file line number Diff line number Diff line change @@ -42,10 +42,14 @@ export const constants = {
4242
4343function 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
6771export const moveLightsComputeSrc : string = processShaderRaw ( moveLightsComputeRaw ) ;
6872export const clusteringComputeSrc : string = processShaderRaw ( clusteringComputeRaw ) ;
73+
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments