@@ -32,20 +32,20 @@ import {
3232 MeshPhongMaterial
3333} from "../../libs/three/three.module.min.js" ;
3434
35- import { RoomEnvironment , pxlShaders , pxlEffects } from "../../pxlNav.esm.js" ;
35+ import { RoomEnvironment , pxlEffects } from "../../pxlNav.esm.js" ;
3636
3737import { rabbitDruidVert , rabbitDruidFrag ,
3838 campfireLogVert , campfireLogFrag ,
3939 campfireVert , campfireFrag ,
4040 instPlantsVert , instPlantsFrag ,
4141 grassClusterVert , grassClusterFrag ,
4242 envGroundVert , envGroundFrag ,
43- rgbaMapVert , rgbaMapFrag } from "./Shaders.js" ;
43+ fireflyVert , fireflyFrag } from "./Shaders.js" ;
4444
4545const BillowSmoke = pxlEffects . pxlParticles . BillowSmoke ;
4646const EmberWisps = pxlEffects . pxlParticles . EmberWisps ;
4747const FloatingDust = pxlEffects . pxlParticles . FloatingDust ;
48- const DefaultVert = pxlShaders . core . defaultVert ;
48+ const ParticleBase = pxlEffects . pxlParticles . ParticleBase ;
4949
5050export class CampfireEnvironment extends RoomEnvironment {
5151 constructor ( roomName = 'CampfireEnvironment' , assetPath = null , msRunner = null , camera = null , scene = null , cloud3dTexture = null ) {
@@ -64,13 +64,9 @@ export class CampfireEnvironment extends RoomEnvironment{
6464 this . animInitCycle = "Sit_Idle" ;
6565
6666 this . animMixer = null ;
67-
68- this . materialList = { } ;
69- this . particleList = { } ;
7067
7168 this . campfireLight = null ;
7269
73-
7470 this . pxlCamFOV = { 'PC' :60 , 'MOBILE' :80 } ;
7571 this . pxlCamZoom = 1 ;
7672 this . pxlCamAspect = 1 ;
@@ -347,13 +343,57 @@ export class CampfireEnvironment extends RoomEnvironment{
347343 // -- -- --
348344
349345 // Generate geometry and load texture resources
350- dustSystem . build ( dustSystemSettings ) ;
346+ // dustSystem.build( dustSystemSettings );
351347
352348 this . particleList [ systemName ] = dustSystem ;
353349 }
354350
355351
356352
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+
357397
358398
359399 // -- -- --
@@ -366,7 +406,6 @@ export class CampfireEnvironment extends RoomEnvironment{
366406 let particleSource = this . geoList [ 'Scripted' ] [ 'ParticleSource_loc' ] ;
367407 let particleSourcePos = particleSource . position ;
368408
369-
370409 var ambientLight = new AmbientLight ( 0x101010 ) ; // soft white light
371410 this . scene . add ( ambientLight ) ;
372411
@@ -404,18 +443,15 @@ export class CampfireEnvironment extends RoomEnvironment{
404443 // Add Billowing Smoke
405444 this . buildBillowSmoke ( particleSourcePos ) ;
406445
407-
408- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
409-
410-
411446 // Quick buggers zippin out of the flame-ola
412447 this . buildEmberWisps ( particleSourcePos ) ;
413-
414- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
415448
416449 // Floating debris in the air
417450 this . buildDust ( ) ;
418451
452+ // Add lightning bugs to the background
453+ this . buildFireflies ( ) ;
454+
419455 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
420456
421457 // Lets load in our rabbit bugger
@@ -508,7 +544,7 @@ export class CampfireEnvironment extends RoomEnvironment{
508544 }
509545
510546 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
511-
547+
512548 }
513549
514550
@@ -634,7 +670,7 @@ export class CampfireEnvironment extends RoomEnvironment{
634670 envGroundUniforms . dataDiffuse . value = this . pxlUtils . loadTexture ( this . assetPath + "EnvGround_dataMask.webp" , null , { 'encoding' :SRGBColorSpace } ) ;
635671
636672 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 } ) ;
638674
639675 var defines = {
640676 'USE_MAP' : "" ,
@@ -689,8 +725,8 @@ export class CampfireEnvironment extends RoomEnvironment{
689725
690726
691727 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" ) ;
694730
695731
696732 let campfireMtl = this . pxlFile . pxlShaderBuilder ( campfireUniforms , campfireVert ( ) , campfireFrag ( ) ) ;
@@ -749,18 +785,20 @@ export class CampfireEnvironment extends RoomEnvironment{
749785 UniformsLib [ "lights" ] ,
750786 shadowMapUniforms ,
751787 {
788+ 'cloudTexture' : { type :'t' , value : null } ,
752789 'noiseTexture' : { type :'t' , value : null } ,
753790 'intensity' : { type : "f" , value : 1.25 } ,
754791 'fogColor' : { type : "c" , value : this . fogColor } ,
755792 } ]
756793 )
757794
758795 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 } ) ;
760798
761799
762800 let grassMat = this . pxlFile . pxlShaderBuilder ( grassClusterUniforms , grassClusterVert ( hasShadowSettings ) , grassClusterFrag ( hasShadowSettings ) ) ;
763- grassMat . side = FrontSide ;
801+ grassMat . side = DoubleSide ;
764802 grassMat . lights = true ;
765803 grassMat . transparent = false ;
766804
@@ -781,13 +819,15 @@ export class CampfireEnvironment extends RoomEnvironment{
781819 {
782820 'diffuse' : { type :'t' , value : null } ,
783821 'alphaMap' : { type :'t' , value : null } ,
822+ 'cloudTexture' : { type :'t' , value : null } ,
784823 'noiseTexture' : { type :'t' , value : null } ,
785824 'intensity' : { type : "f" , value : 2.25 } ,
786825 'fogColor' : { type : "c" , value : this . fogColor }
787826 } ]
788827 )
789828 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" ) ;
791831 grassCardsAUniforms . diffuse . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_diffuse.webp" ) ;
792832 grassCardsAUniforms . alphaMap . value = this . pxlUtils . loadTexture ( this . assetPath + "grassCardsA_mask.jpg" ) ;
793833
@@ -811,49 +851,20 @@ export class CampfireEnvironment extends RoomEnvironment{
811851 grassCardsFarMat . side = DoubleSide ;
812852 grassCardsFarMat . lights = true ;
813853 grassCardsFarMat . transparent = false ;
814-
815854
816855 // -- -- --
817856
818- // -- -- -- -- -- -- -- -- -- -- -- -- --
819- // -- Grass Cluster Instances Material -- --
820- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
821857
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+ // -- -- -- -- -- -- -- -- -- -- -- -- --
841861
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- // -- -- --
851862
852863 this . materialList [ "EnvironmentGround_geo" ] = environmentGroundMat ;
853864 this . materialList [ "CampfireFlame_geo" ] = campfireMtl ;
854865 this . materialList [ "grassClusterA_lod0_geo" ] = grassMat ;
855866 this . materialList [ "grassClusterA_lod1_geo" ] = grassMat ;
856- this . materialList [ "grassClusterA_lod2_geo" ] = grassFlatMat ;
867+ this . materialList [ "grassClusterA_lod2_geo" ] = grassCardsMat ;
857868 //this.materialList[ "mushroomA_lod0_geo" ] = grassMat;
858869 //this.materialList[ "mushroomA_lod1_geo" ] = grassMat;
859870 this . materialList [ "grassCardsA_lod0_geo" ] = grassCardsMat ;
0 commit comments