@@ -163,12 +163,12 @@ export class SeveranceMaterials {
163
163
async _loadTextures ( ) {
164
164
const textureLoader = new THREE . TextureLoader ( ) ;
165
165
const texturePaths = {
166
- wall : getAssetPath ( "/assets/ textures/wall.jpg" ) ,
167
- floor : getAssetPath ( "/assets/ textures/floor.jpg" ) ,
168
- ceiling : getAssetPath ( "/assets/ textures/ceiling.jpg" ) ,
169
- trim : getAssetPath ( "/assets/ textures/trim.jpg" ) ,
170
- door : getAssetPath ( "/assets/ textures/door.jpg" ) ,
171
- outsideGround : getAssetPath ( "/assets/ textures/wall.jpg" ) ,
166
+ wall : getAssetPath ( "/textures/wall.jpg" ) ,
167
+ floor : getAssetPath ( "/textures/floor.jpg" ) ,
168
+ ceiling : getAssetPath ( "/textures/ceiling.jpg" ) ,
169
+ trim : getAssetPath ( "/textures/trim.jpg" ) ,
170
+ door : getAssetPath ( "/textures/door.jpg" ) ,
171
+ outsideGround : getAssetPath ( "/textures/wall.jpg" ) ,
172
172
} ;
173
173
174
174
const loadTexture = ( path ) => {
@@ -227,7 +227,7 @@ export class SeveranceMaterials {
227
227
*/
228
228
async _loadShaders ( ) {
229
229
try {
230
- console . log ( "Loading shaders from src/shaders directory ..." ) ;
230
+ console . log ( "Loading shaders..." ) ;
231
231
232
232
// Create a default vertex shader if we can't load the file
233
233
const defaultVertexShader = `
@@ -247,14 +247,12 @@ export class SeveranceMaterials {
247
247
}
248
248
` ;
249
249
250
- // Try to load common vertex shader explicitly from src/shaders/common/vertex.glsl
250
+ // Try to load common vertex shader
251
251
let commonVertexShader ;
252
252
try {
253
- console . log (
254
- "Attempting to load vertex shader from src/shaders/common/vertex.glsl"
255
- ) ;
253
+ console . log ( "Attempting to load vertex shader" ) ;
256
254
commonVertexShader = await this . _loadShaderFile (
257
- getAssetPath ( "/assets/ shaders/common/vertex.glsl" )
255
+ getAssetPath ( "/shaders/common/vertex.glsl" )
258
256
) ;
259
257
console . log ( "Successfully loaded vertex shader" ) ;
260
258
} catch ( e ) {
@@ -265,62 +263,30 @@ export class SeveranceMaterials {
265
263
// Initialize a default environment map
266
264
const defaultEnvMap = this . _createDefaultEnvMap ( ) ;
267
265
268
- // Load wall shader from src/shaders/wall.glsl - this is our primary wall shader
266
+ // Load wall shader
269
267
let wallFragmentShader ;
270
268
try {
271
- console . log (
272
- "Attempting to load wall shader from src/shaders/wall.glsl"
273
- ) ;
269
+ console . log ( "Attempting to load wall shader" ) ;
274
270
wallFragmentShader = await this . _loadShaderFile (
275
- getAssetPath ( "/assets/ shaders/wall.glsl" )
271
+ getAssetPath ( "/shaders/wall.glsl" )
276
272
) ;
277
273
console . log ( "Successfully loaded wall shader" ) ;
278
- console . log (
279
- "Wall shader content:" ,
280
- wallFragmentShader . substring ( 0 , 50 ) + "..."
281
- ) ;
282
274
} catch ( e ) {
283
275
console . error ( "Could not load wall shader from file" , e ) ;
284
-
285
- // Second attempt from public path
286
- try {
287
- console . log (
288
- "Attempting to load wall shader from public/src/shaders/wall.glsl"
289
- ) ;
290
- wallFragmentShader = await this . _loadShaderFile (
291
- getAssetPath ( "/assets/shaders/wall.glsl" )
292
- ) ;
293
- console . log ( "Successfully loaded wall shader from public path" ) ;
294
- } catch ( e2 ) {
295
- console . error ( "All attempts to load wall shader failed" , e2 ) ;
296
- wallFragmentShader = null ;
297
- }
276
+ wallFragmentShader = null ;
298
277
}
299
278
300
- // Load corridor shader from src/shaders/corridor.glsl
279
+ // Load corridor shader
301
280
let corridorFragmentShader ;
302
281
try {
303
- console . log (
304
- "Attempting to load corridor shader from src/shaders/corridor.glsl"
305
- ) ;
282
+ console . log ( "Attempting to load corridor shader" ) ;
306
283
corridorFragmentShader = await this . _loadShaderFile (
307
- getAssetPath ( "/assets/ shaders/corridor.glsl" )
284
+ getAssetPath ( "/shaders/corridor.glsl" )
308
285
) ;
309
286
console . log ( "Successfully loaded corridor shader" ) ;
310
287
} catch ( e ) {
311
- console . warn (
312
- "Could not load corridor shader from primary location, trying alternatives" ,
313
- e
314
- ) ;
315
-
316
- // Try fallback from /shaders/corridor.glsl (without src prefix)
317
- try {
318
- corridorFragmentShader = await this . _loadShaderFile (
319
- getAssetPath ( "/assets/shaders/corridor.glsl" )
320
- ) ;
321
- } catch ( e2 ) {
322
- console . warn ( "Could not load corridor shader from any location" ) ;
323
- }
288
+ console . warn ( "Could not load corridor shader" , e ) ;
289
+ corridorFragmentShader = null ;
324
290
}
325
291
326
292
// Create corridor wall shader if corridor shader was loaded
@@ -338,51 +304,7 @@ export class SeveranceMaterials {
338
304
this . shaders . set ( "corridorWall" , corridorWallShader ) ;
339
305
}
340
306
341
- // Load corridor wall shaders
342
- let corridorWallVertexShader ;
343
- let corridorWallFragmentShader ;
344
-
345
- try {
346
- corridorWallVertexShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/common/vertex.glsl' ) ) ;
347
- corridorWallFragmentShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/corridor_wall.glsl' ) ) ;
348
- console . log ( 'Successfully loaded corridor wall shaders' ) ;
349
-
350
- // Create corridor wall material with uniforms
351
- const corridorWallMaterial = new THREE . ShaderMaterial ( {
352
- uniforms : {
353
- u_time : { value : 0.0 } ,
354
- u_resolution : { value : new THREE . Vector2 ( window . innerWidth , window . innerHeight ) } ,
355
- u_mouse : { value : new THREE . Vector2 ( 0.5 , 0.5 ) } ,
356
- u_depth : { value : 1.0 } ,
357
- playerPos : { value : new THREE . Vector3 ( 0 , 0 , 0 ) } ,
358
- wallScale : { value : new THREE . Vector2 ( 1 , 1 ) } ,
359
- uPrevFrame : { value : null }
360
- } ,
361
- vertexShader : corridorWallVertexShader ,
362
- fragmentShader : corridorWallFragmentShader ,
363
- side : THREE . DoubleSide ,
364
- transparent : false
365
- } ) ;
366
-
367
- // Validate corridor wall shader compilation
368
- if ( ! this . _checkShaderCompilation ( corridorWallMaterial , 'CorridorWall' ) ) {
369
- throw new Error ( 'CorridorWall shader compilation failed' ) ;
370
- }
371
-
372
- this . materials . set ( 'corridorWall' , corridorWallMaterial ) ;
373
- console . log ( 'CorridorWall shader material created successfully' ) ;
374
-
375
- } catch ( error ) {
376
- console . warn ( 'Failed to load corridor wall shaders, using fallback material:' , error ) ;
377
- this . materials . set ( 'corridorWall' , new THREE . MeshStandardMaterial ( {
378
- color : 0xe10600 ,
379
- roughness : 0.5 ,
380
- metalness : 0.2 ,
381
- side : THREE . DoubleSide
382
- } ) ) ;
383
- }
384
-
385
- await this . _createShaderMaterials ( ) ;
307
+ await this . _createShaderMaterials ( commonVertexShader ) ;
386
308
387
309
console . log ( "Shader loading complete" ) ;
388
310
} catch ( error ) {
@@ -438,11 +360,15 @@ export class SeveranceMaterials {
438
360
*/
439
361
async _loadShaderFile ( path ) {
440
362
try {
363
+ console . log ( `Attempting to load shader from: ${ path } ` ) ;
441
364
const response = await fetch ( path ) ;
442
365
if ( ! response . ok ) {
366
+ console . error ( `Failed to load shader at ${ path } . Status: ${ response . status } ` ) ;
443
367
throw new Error ( `Failed to load shader at ${ path } ` ) ;
444
368
}
445
- return await response . text ( ) ;
369
+ const text = await response . text ( ) ;
370
+ console . log ( `Successfully loaded shader from: ${ path } (${ text . length } bytes)` ) ;
371
+ return text ;
446
372
} catch ( error ) {
447
373
console . error ( `Error loading shader from ${ path } :` , error ) ;
448
374
throw error ;
@@ -453,15 +379,14 @@ export class SeveranceMaterials {
453
379
* Creates shader materials for walls and corridors
454
380
* @private
455
381
*/
456
- async _createShaderMaterials ( ) {
382
+ async _createShaderMaterials ( commonVertexShader ) {
457
383
try {
458
384
// Load wall shaders
459
- let wallVertexShader ;
385
+ let wallVertexShader = commonVertexShader ;
460
386
let wallFragmentShader ;
461
387
462
388
try {
463
- wallVertexShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/common/vertex.glsl' ) ) ;
464
- wallFragmentShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/wall.glsl' ) ) ;
389
+ wallFragmentShader = await this . _loadShaderFile ( getAssetPath ( '/shaders/wall.glsl' ) ) ;
465
390
console . log ( 'Successfully loaded wall shaders' ) ;
466
391
467
392
// Create wall material with uniforms
@@ -496,12 +421,11 @@ export class SeveranceMaterials {
496
421
}
497
422
498
423
// Load corridor shaders
499
- let corridorVertexShader ;
424
+ let corridorVertexShader = commonVertexShader ;
500
425
let corridorFragmentShader ;
501
426
502
427
try {
503
- corridorVertexShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/common/vertex.glsl' ) ) ;
504
- corridorFragmentShader = await this . _loadShaderFile ( getAssetPath ( './src/shaders/corridor.glsl' ) ) ;
428
+ corridorFragmentShader = await this . _loadShaderFile ( getAssetPath ( '/shaders/corridor.glsl' ) ) ;
505
429
console . log ( 'Successfully loaded corridor shaders' ) ;
506
430
507
431
// Create corridor material with uniforms
@@ -536,46 +460,48 @@ export class SeveranceMaterials {
536
460
} ) ) ;
537
461
}
538
462
539
- // Create corridor wall shader if corridor shader was loaded
540
- if ( corridorFragmentShader ) {
541
- console . log ( "Creating corridor wall shader with loaded fragment shader" ) ;
542
- const corridorWallShader = {
543
- vertexShader : commonVertexShader ,
544
- fragmentShader : corridorFragmentShader ,
463
+ // Load corridor wall shaders
464
+ let corridorWallFragmentShader ;
465
+
466
+ try {
467
+ corridorWallFragmentShader = await this . _loadShaderFile ( getAssetPath ( '/shaders/corridor_wall.glsl' ) ) ;
468
+ console . log ( 'Successfully loaded corridor wall shaders' ) ;
469
+
470
+ // Create corridor wall material with uniforms
471
+ const corridorWallMaterial = new THREE . ShaderMaterial ( {
545
472
uniforms : {
546
- lightColor : { value : new THREE . Color ( 0xffffff ) } ,
547
- intensity : { value : 1.0 } ,
548
- time : { value : 0 } ,
473
+ u_time : { value : 0.0 } ,
474
+ u_resolution : { value : new THREE . Vector2 ( window . innerWidth , window . innerHeight ) } ,
475
+ u_mouse : { value : new THREE . Vector2 ( 0.5 , 0.5 ) } ,
476
+ u_depth : { value : 1.0 } ,
477
+ playerPos : { value : new THREE . Vector3 ( 0 , 0 , 0 ) } ,
478
+ wallScale : { value : new THREE . Vector2 ( 1 , 1 ) }
549
479
} ,
550
- } ;
551
- this . shaders . set ( "corridorWall" , corridorWallShader ) ;
552
- }
480
+ vertexShader : commonVertexShader ,
481
+ fragmentShader : corridorWallFragmentShader ,
482
+ side : THREE . DoubleSide ,
483
+ transparent : false
484
+ } ) ;
553
485
554
- // Create fallback materials for shaders that don't exist
555
- console . log ( 'Creating fallback materials for missing shaders...' ) ;
556
-
557
- // Floor material (Twin Peaks-inspired)
558
- this . materials . set ( 'floor' , new THREE . MeshStandardMaterial ( {
559
- color : 0xf0f0f0 ,
560
- roughness : 0.3 ,
561
- metalness : 0.4 ,
562
- side : THREE . FrontSide
563
- } ) ) ;
564
- console . log ( 'Created fallback floor material' ) ;
565
-
566
- // Sky material
567
- this . materials . set ( 'sky' , new THREE . MeshStandardMaterial ( {
568
- color : 0x7ec0ee ,
569
- metalness : 0.0 ,
570
- roughness : 1.0 ,
571
- side : THREE . DoubleSide
572
- } ) ) ;
573
- console . log ( 'Created fallback sky material' ) ;
574
-
575
- console . log ( 'Shader material creation complete' ) ;
576
-
486
+ // Validate corridor wall shader compilation
487
+ if ( ! this . _checkShaderCompilation ( corridorWallMaterial , 'CorridorWall' ) ) {
488
+ throw new Error ( 'CorridorWall shader compilation failed' ) ;
489
+ }
490
+
491
+ this . materials . set ( 'corridorWall' , corridorWallMaterial ) ;
492
+ console . log ( 'CorridorWall shader material created successfully' ) ;
493
+
494
+ } catch ( error ) {
495
+ console . warn ( 'Failed to load corridor wall shaders, using fallback material:' , error ) ;
496
+ this . materials . set ( 'corridorWall' , new THREE . MeshStandardMaterial ( {
497
+ color : 0xe10600 ,
498
+ roughness : 0.5 ,
499
+ metalness : 0.2 ,
500
+ side : THREE . DoubleSide
501
+ } ) ) ;
502
+ }
577
503
} catch ( error ) {
578
- console . error ( ' Error creating shader materials:' , error ) ;
504
+ console . error ( " Error creating shader materials:" , error ) ;
579
505
throw error ;
580
506
}
581
507
}
0 commit comments