Skip to content

Commit b75026d

Browse files
committed
Added Fireflies to CampefireEnv
_Added mesh-to-particle support to pxlNav v0.0.28-dev __This lets you assign a mesh to become a particle system from your CGI program ____Add `pSystem=true` to the object, then assign it with a `ParticleBase` pxlParticle system. _Added Fireflies to CampefireEnv using mesh-to-particle _Turned on dust for Mobile on OutletEnv Added some wavering shadow edges from the "fire"
1 parent a25ac8c commit b75026d

21 files changed

+349
-110
lines changed

docs/js/pxlNav.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Loading
Binary file not shown.
Loading

docs/js/pxlRooms/CampfireEnvironment/CampfireEnvironment.js

+66-55
Original file line numberDiff line numberDiff line change
@@ -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

3737
import { 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

4545
const BillowSmoke = pxlEffects.pxlParticles.BillowSmoke;
4646
const EmberWisps = pxlEffects.pxlParticles.EmberWisps;
4747
const FloatingDust = pxlEffects.pxlParticles.FloatingDust;
48-
const DefaultVert = pxlShaders.core.defaultVert;
48+
const ParticleBase = pxlEffects.pxlParticles.ParticleBase;
4949

5050
export 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;

docs/js/pxlRooms/CampfireEnvironment/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Room & Environment Requirements --
22

3-
You're main room javascript must be named how it is used in `pxlNav.js`
3+
You're main room javascript must be named how it is used in `pxlNav.esm.js`
44
<br/>To start you're development, use this premade room for an example structure.
55

66

77
Make a back-up of the `CampfireEnvironment.js` file,
88
<br/>&nbsp;&nbsp;Then start here for any modifications made in your testing.
99

1010
To stop pxlNav from loading this room environment,
11-
<br/>&nbsp;&nbsp;Change the `startingRoom` variable in `./Source/js/pxlNav.js`
11+
<br/>&nbsp;&nbsp;Change the `startingRoom` variable in `./src/js/pxlNav.js`
1212
<br/>&nbsp;&nbsp;&nbsp;&nbsp;To your desired room name -
1313
<br/>&nbsp;&nbsp;&nbsp;&nbsp;`const startingRoom = "CampfireEnvironment";`
1414

docs/js/pxlRooms/CampfireEnvironment/Shaders.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import { campfireLogVert, campfireLogFrag } from "./Shaders/campfireLog.js";
2828
// Shader for the Grass Cluster, using a noise texture to blend areas of different grass textures --
2929
import { grassClusterVert, grassClusterFrag } from "./Shaders/grassCluster.js";
3030

31+
// Add in some fireflies
32+
import { fireflyVert, fireflyFrag } from "./Shaders/fireflySystem.js";
33+
3134
// -- -- --
3235

3336
export {
@@ -37,5 +40,6 @@ export {
3740
envGroundVert, envGroundFrag,
3841
campfireVert, campfireFrag,
3942
campfireLogVert, campfireLogFrag,
40-
grassClusterVert, grassClusterFrag
43+
grassClusterVert, grassClusterFrag,
44+
fireflyVert, fireflyFrag
4145
};

docs/js/pxlRooms/CampfireEnvironment/Shaders/envGround.js

+41-17
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,18 @@ export function envGroundFrag(settings={}){
108108
};
109109
settings = Object.assign({}, defaultSettings, settings);
110110

111-
let ret=shaderHeader();
111+
let ret=`
112+
// Ground settings --
113+
const float ShadowFlickerRate = 0.250;
114+
115+
// -- -- --
116+
117+
`;
118+
ret += shaderHeader();
112119
ret+=`
120+
121+
// -- -- --
122+
113123
uniform sampler2D diffuse;
114124
uniform sampler2D dirtDiffuse;
115125
uniform sampler2D noiseTexture;
@@ -275,6 +285,9 @@ export function envGroundFrag(settings={}){
275285
animWarpUV = vec2(.45, length(animWarpUV)*.04 - timer );
276286
vec3 animWarpCd = texture2D(uniformNoise,animWarpUV).rgb*depthFade;
277287
288+
animWarpUV = ( vec2( vLocalPos.xz*.01 + vec2(.235,.39) * time.x * ShadowFlickerRate ) );
289+
vec3 animNoiseCd = texture2D(noiseTexture,animWarpUV).rgb ;
290+
278291
// -- -- --
279292
280293
// -- -- -- -- -- -- -- --
@@ -386,28 +399,14 @@ export function envGroundFrag(settings={}){
386399
#endif
387400
388401
// -- -- --
389-
390-
// -- -- -- -- -- -- -- --
391-
// -- Firepit Flicker - -- --
392-
// -- -- -- -- -- -- -- -- -- --
393-
394-
float animWarpFit = max( animWarpCd.r, max(animWarpCd.g,animWarpCd.b) )*.8 -.2;
395-
396-
// Main Pit
397-
Cd.rgb += (firePitColor + firePitColor*animWarpFit) * (campfireMask*1.1-.1) * vInnerPitMask * .5 * ashMask;
398-
399-
// Region around Pit and Druid Rabbit
400-
Cd.rgb += (fireGlowColor + fireGlowColor*animWarpFit) * vPitMask * vPitMask * .35 * ashMask;
401-
402-
// -- -- --
403402
404403
405404
`;
406405
if( settings.shadows ) {
407406
ret+=`
407+
float shadowInf = 0.0;
408408
#if NUM_POINT_LIGHT_SHADOWS > 0
409409
410-
float shadowInf = 0.0;
411410
float detailInf = 0.0;
412411
float lShadow = 0.0;
413412
@@ -416,17 +415,42 @@ export function envGroundFrag(settings={}){
416415
float shadowMixFit = max(0.0,min(1.0, shadowMix*shadowMix*.04)*1.4-.4);
417416
float shadowRadius = max(0.0, 1.0-shadowMixFit * ${settings.shadowReach});
418417
418+
float biasShift;
419419
for( int x = 0; x < NUM_POINT_LIGHT_SHADOWS; ++x ) {
420-
lShadow = getPointShadow( pointShadowMap[0], pointLightShadows[x].shadowMapSize, pointLightShadows[x].shadowIntensity * shadowRadius, pointLightShadows[x].shadowBias+shadowMixFit*.3, pointLightShadows[x].shadowRadius+shadowMixFit*30.0, vPointShadowCoord[x], pointLightShadows[x].shadowCameraNear, pointLightShadows[x].shadowCameraFar );
420+
biasShift = animNoiseCd.x + animNoiseCd.y*animNoiseCd.z + .2;
421+
biasShift = pointLightShadows[x].shadowRadius * ( animNoiseCd.x*animNoiseCd.y* biasShift + max(animNoiseCd.x,animNoiseCd.y) );
422+
biasShift += shadowMixFit*5.0;
423+
lShadow = getPointShadow( pointShadowMap[0], pointLightShadows[x].shadowMapSize, pointLightShadows[x].shadowIntensity * shadowRadius, pointLightShadows[x].shadowBias+shadowMixFit*.3, biasShift, vPointShadowCoord[x], pointLightShadows[x].shadowCameraNear, pointLightShadows[x].shadowCameraFar );
421424
shadowInf = max( lShadow, shadowInf);
422425
}
423426
shadowInf = shadowInf*.875+.125;
424427
Cd.rgb *= shadowInf;
425428
#endif
426429
`;
430+
}else{
431+
ret += `
432+
float shadowInf = 1.0;
433+
`;
427434
}
428435
ret += `
429436
437+
438+
// -- -- --
439+
440+
// -- -- -- -- -- -- -- --
441+
// -- Firepit Flicker - -- --
442+
// -- -- -- -- -- -- -- -- -- --
443+
444+
float animWarpFit = max( animWarpCd.r, max(animWarpCd.g,animWarpCd.b) )*.8 -.2;
445+
446+
// Main Pit
447+
Cd.rgb += (firePitColor + firePitColor*animWarpFit) * (campfireMask*1.1-.1) * vInnerPitMask * .5 * ashMask * shadowInf;
448+
449+
// Region around Pit and Druid Rabbit
450+
Cd.rgb += (fireGlowColor + fireGlowColor*animWarpFit) * vPitMask * vPitMask * .35 * ashMask * shadowInf;
451+
452+
453+
430454
// -- -- -- -- -- -- -- -- -- -- -- --
431455
// -- Final shading and fog color - -- --
432456
// -- -- -- -- -- -- -- -- -- -- -- -- -- --

0 commit comments

Comments
 (0)