@@ -32,20 +32,20 @@ import {
32
32
MeshPhongMaterial
33
33
} from "../../libs/three/three.module.min.js" ;
34
34
35
- import { RoomEnvironment , pxlShaders , pxlEffects } from "../../pxlNav.esm.js" ;
35
+ import { RoomEnvironment , pxlEffects } from "../../pxlNav.esm.js" ;
36
36
37
37
import { rabbitDruidVert , rabbitDruidFrag ,
38
38
campfireLogVert , campfireLogFrag ,
39
39
campfireVert , campfireFrag ,
40
40
instPlantsVert , instPlantsFrag ,
41
41
grassClusterVert , grassClusterFrag ,
42
42
envGroundVert , envGroundFrag ,
43
- rgbaMapVert , rgbaMapFrag } from "./Shaders.js" ;
43
+ fireflyVert , fireflyFrag } from "./Shaders.js" ;
44
44
45
45
const BillowSmoke = pxlEffects . pxlParticles . BillowSmoke ;
46
46
const EmberWisps = pxlEffects . pxlParticles . EmberWisps ;
47
47
const FloatingDust = pxlEffects . pxlParticles . FloatingDust ;
48
- const DefaultVert = pxlShaders . core . defaultVert ;
48
+ const ParticleBase = pxlEffects . pxlParticles . ParticleBase ;
49
49
50
50
export class CampfireEnvironment extends RoomEnvironment {
51
51
constructor ( roomName = 'CampfireEnvironment' , assetPath = null , msRunner = null , camera = null , scene = null , cloud3dTexture = null ) {
@@ -64,13 +64,9 @@ export class CampfireEnvironment extends RoomEnvironment{
64
64
this . animInitCycle = "Sit_Idle" ;
65
65
66
66
this . animMixer = null ;
67
-
68
- this . materialList = { } ;
69
- this . particleList = { } ;
70
67
71
68
this . campfireLight = null ;
72
69
73
-
74
70
this . pxlCamFOV = { 'PC' :60 , 'MOBILE' :80 } ;
75
71
this . pxlCamZoom = 1 ;
76
72
this . pxlCamAspect = 1 ;
@@ -347,13 +343,57 @@ export class CampfireEnvironment extends RoomEnvironment{
347
343
// -- -- --
348
344
349
345
// Generate geometry and load texture resources
350
- dustSystem . build ( dustSystemSettings ) ;
346
+ // dustSystem.build( dustSystemSettings );
351
347
352
348
this . particleList [ systemName ] = dustSystem ;
353
349
}
354
350
355
351
356
352
353
+ // Build a mesh-to-particle system for the fireflies
354
+ // Using the `fireflies_vfx` geometry from the CampfireEnvironment.fbx
355
+ // Marked with the custom property `pSystem = true`
356
+ buildFireflies ( ) {
357
+ //if( this.mobile ) return;
358
+
359
+ let nameOfSystem = "fireflies_vfx" ;
360
+ if ( this . particleList ?. hasOwnProperty ( nameOfSystem ) && this . particleList [ nameOfSystem ] . type == "BufferGeometry" ) {
361
+ let fireflyUniforms = {
362
+ 'atlasTexture' : { type :'t' , value : null } ,
363
+ 'atlasAlphaTexture' : { type :'t' , value : null } ,
364
+ 'noiseTexture' : { type :"t" , value : null } ,
365
+ 'pointScale' : { type : "v" , value : new Vector2 ( 5.0 , 0.0 ) } ,
366
+ 'tint' : { type : "c" , value : new Color ( 1.5 , 1.4 , 0.6 ) } ,
367
+ 'fogColor' : { type : "c" , value : this . fogColor } ,
368
+ 'rate' : { type :"f" , value :.035 }
369
+ } ;
370
+ fireflyUniforms . atlasTexture . value = this . pxlUtils . loadTexture ( "sprite_dustAtlas_rgb.jpg" , null , { 'encoding' :SRGBColorSpace } ) ;
371
+ fireflyUniforms . atlasAlphaTexture . value = this . pxlUtils . loadTexture ( "sprite_dustAtlas_alpha.jpg" ) ;
372
+
373
+ // -- -- --
374
+
375
+ // Make the firefly system itself
376
+ let fireflySystem = new ParticleBase ( this , "fireflySystem" ) ;
377
+
378
+ // Build settings using the ParticleBase class's `getSettings()` method
379
+ let fireflySettings = fireflySystem . getSettings ( ) ;
380
+ fireflySettings [ "atlasPicks" ] = [
381
+ ...fireflySystem . dupeArray ( [ 0.0 , 0.50 ] , 4 ) , ...fireflySystem . dupeArray ( [ 0.25 , 0.50 ] , 4 ) ,
382
+ ...fireflySystem . dupeArray ( [ 0.0 , 0.75 ] , 4 ) , ...fireflySystem . dupeArray ( [ 0.25 , 0.75 ] , 4 )
383
+ ] ;
384
+ fireflySettings [ "additiveBlend" ] = true ;
385
+
386
+ // Assign your `userData.pSystem = true` geometry to the particle system to use
387
+ fireflySystem . setGeometry ( this . particleList [ nameOfSystem ] ) ;
388
+
389
+ // Build + Add the particle system to the scene using `ParticleBase.build( settings, uniforms, vertex shader, fragment shader )`
390
+ fireflySystem . build ( fireflySettings , fireflyUniforms , fireflyVert ( ) , fireflyFrag ( ) ) ;
391
+
392
+ // Optional, overwrite the `pSystem` geometry with the built particle system
393
+ this . particleList [ nameOfSystem ] = fireflySystem ;
394
+ }
395
+ }
396
+
357
397
358
398
359
399
// -- -- --
@@ -366,7 +406,6 @@ export class CampfireEnvironment extends RoomEnvironment{
366
406
let particleSource = this . geoList [ 'Scripted' ] [ 'ParticleSource_loc' ] ;
367
407
let particleSourcePos = particleSource . position ;
368
408
369
-
370
409
var ambientLight = new AmbientLight ( 0x101010 ) ; // soft white light
371
410
this . scene . add ( ambientLight ) ;
372
411
@@ -404,18 +443,15 @@ export class CampfireEnvironment extends RoomEnvironment{
404
443
// Add Billowing Smoke
405
444
this . buildBillowSmoke ( particleSourcePos ) ;
406
445
407
-
408
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
409
-
410
-
411
446
// Quick buggers zippin out of the flame-ola
412
447
this . buildEmberWisps ( particleSourcePos ) ;
413
-
414
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
415
448
416
449
// Floating debris in the air
417
450
this . buildDust ( ) ;
418
451
452
+ // Add lightning bugs to the background
453
+ this . buildFireflies ( ) ;
454
+
419
455
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
420
456
421
457
// Lets load in our rabbit bugger
@@ -508,7 +544,7 @@ export class CampfireEnvironment extends RoomEnvironment{
508
544
}
509
545
510
546
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
511
-
547
+
512
548
}
513
549
514
550
@@ -634,7 +670,7 @@ export class CampfireEnvironment extends RoomEnvironment{
634
670
envGroundUniforms . dataDiffuse . value = this . pxlUtils . loadTexture ( this . assetPath + "EnvGround_dataMask.webp" , null , { 'encoding' :SRGBColorSpace } ) ;
635
671
636
672
envGroundUniforms . noiseTexture . value = this . cloud3dTexture ;
637
- envGroundUniforms . uniformNoise . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_UniformWebbing.jpg" , null , { 'encoding' :LinearSRGBColorSpace } ) ;
673
+ envGroundUniforms . uniformNoise . value = this . pxlUtils . loadTexture ( "Noise_UniformWebbing.jpg" , null , { 'encoding' :LinearSRGBColorSpace } ) ;
638
674
639
675
var defines = {
640
676
'USE_MAP' : "" ,
@@ -689,8 +725,8 @@ export class CampfireEnvironment extends RoomEnvironment{
689
725
690
726
691
727
campfireUniforms . noiseTexture . value = this . cloud3dTexture ;
692
- campfireUniforms . smoothNoiseTexture . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_UniformWebbing.jpg" ) ;
693
- campfireUniforms . webNoise . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_NCross.jpg" ) ;
728
+ campfireUniforms . smoothNoiseTexture . value = this . pxlUtils . loadTexture ( "Noise_UniformWebbing.jpg" ) ;
729
+ campfireUniforms . webNoise . value = this . pxlUtils . loadTexture ( "Noise_NCross.jpg" ) ;
694
730
695
731
696
732
let campfireMtl = this . pxlFile . pxlShaderBuilder ( campfireUniforms , campfireVert ( ) , campfireFrag ( ) ) ;
@@ -749,18 +785,20 @@ export class CampfireEnvironment extends RoomEnvironment{
749
785
UniformsLib [ "lights" ] ,
750
786
shadowMapUniforms ,
751
787
{
788
+ 'cloudTexture' : { type :'t' , value : null } ,
752
789
'noiseTexture' : { type :'t' , value : null } ,
753
790
'intensity' : { type : "f" , value : 1.25 } ,
754
791
'fogColor' : { type : "c" , value : this . fogColor } ,
755
792
} ]
756
793
)
757
794
758
795
grassClusterUniforms . intensity . value = this . mobile ? 1.0 : 1.3 ; // Lower intensity for mobile devices
759
- grassClusterUniforms . noiseTexture . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_UniformWebbing.jpg" , null , { 'encoding' :SRGBColorSpace } ) ;
796
+ grassClusterUniforms . cloudTexture . value = this . cloud3dTexture ;
797
+ grassClusterUniforms . noiseTexture . value = this . pxlUtils . loadTexture ( "Noise_UniformWebbing.jpg" , null , { 'encoding' :SRGBColorSpace } ) ;
760
798
761
799
762
800
let grassMat = this . pxlFile . pxlShaderBuilder ( grassClusterUniforms , grassClusterVert ( hasShadowSettings ) , grassClusterFrag ( hasShadowSettings ) ) ;
763
- grassMat . side = FrontSide ;
801
+ grassMat . side = DoubleSide ;
764
802
grassMat . lights = true ;
765
803
grassMat . transparent = false ;
766
804
@@ -781,13 +819,15 @@ export class CampfireEnvironment extends RoomEnvironment{
781
819
{
782
820
'diffuse' : { type :'t' , value : null } ,
783
821
'alphaMap' : { type :'t' , value : null } ,
822
+ 'cloudTexture' : { type :'t' , value : null } ,
784
823
'noiseTexture' : { type :'t' , value : null } ,
785
824
'intensity' : { type : "f" , value : 2.25 } ,
786
825
'fogColor' : { type : "c" , value : this . fogColor }
787
826
} ]
788
827
)
789
828
grassClusterUniforms . intensity . value = this . mobile ? 2.25 : 2.0 ; // Lower intensity for mobile devices
790
- grassCardsAUniforms . noiseTexture . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_UniformWebbing.jpg" ) ;
829
+ grassCardsAUniforms . cloudTexture . value = this . cloud3dTexture ;
830
+ grassCardsAUniforms . noiseTexture . value = this . pxlUtils . loadTexture ( "Noise_UniformWebbing.jpg" ) ;
791
831
grassCardsAUniforms . diffuse . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_diffuse.webp" ) ;
792
832
grassCardsAUniforms . alphaMap . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_mask.jpg" ) ;
793
833
@@ -811,49 +851,20 @@ export class CampfireEnvironment extends RoomEnvironment{
811
851
grassCardsFarMat . side = DoubleSide ;
812
852
grassCardsFarMat . lights = true ;
813
853
grassCardsFarMat . transparent = false ;
814
-
815
854
816
855
// -- -- --
817
856
818
- // -- -- -- -- -- -- -- -- -- -- -- -- --
819
- // -- Grass Cluster Instances Material -- --
820
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
821
857
822
- let grassClusterCardsUniforms = UniformsUtils . merge (
823
- [
824
- UniformsLib [ "lights" ] ,
825
- /*UniformsLib[ "shadowmap" ],*/
826
- {
827
- 'rgbMap' : { type :'t' , value : null } ,
828
- 'alphaMap' : { type :'t' , value : null } ,
829
- 'intensity' : { type : "f" , value : 0.85 } ,
830
- 'noiseTexture' : { type :'t' , value : null } ,
831
- 'fogColor' : { type : "c" , value : this . fogColor }
832
- } ]
833
- )
834
- grassClusterCardsUniforms . noiseTexture . value = this . pxlUtils . loadTexture ( this . assetPath + "Noise_UniformWebbing.jpg" ) ;
835
- grassClusterCardsUniforms . rgbMap . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_diffuse.webp" , null , { 'encoding' :SRGBColorSpace } ) ;
836
- grassClusterCardsUniforms . alphaMap . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_mask.jpg" ) ;
837
-
838
- let grassLODSettings = {
839
- 'depthScalar' : 0.004 ,
840
- }
858
+ // -- -- -- -- -- -- -- -- -- -- -- -- --
859
+ // -- -- -- -- -- -- -- -- -- -- -- -- --
860
+ // -- -- -- -- -- -- -- -- -- -- -- -- --
841
861
842
- let grassFlatMat = this . pxlFile . pxlShaderBuilder ( grassClusterCardsUniforms , rgbaMapVert ( ) , rgbaMapFrag ( grassLODSettings ) ) ;
843
- grassFlatMat . side = DoubleSide ;
844
- grassFlatMat . lights = true ;
845
- grassFlatMat . transparent = false ;
846
- //grassFlatMat.alphaTest = .5;
847
- //grassFlatMat.blending = ;
848
-
849
-
850
- // -- -- --
851
862
852
863
this . materialList [ "EnvironmentGround_geo" ] = environmentGroundMat ;
853
864
this . materialList [ "CampfireFlame_geo" ] = campfireMtl ;
854
865
this . materialList [ "grassClusterA_lod0_geo" ] = grassMat ;
855
866
this . materialList [ "grassClusterA_lod1_geo" ] = grassMat ;
856
- this . materialList [ "grassClusterA_lod2_geo" ] = grassFlatMat ;
867
+ this . materialList [ "grassClusterA_lod2_geo" ] = grassCardsMat ;
857
868
//this.materialList[ "mushroomA_lod0_geo" ] = grassMat;
858
869
//this.materialList[ "mushroomA_lod1_geo" ] = grassMat;
859
870
this . materialList [ "grassCardsA_lod0_geo" ] = grassCardsMat ;
0 commit comments