Skip to content

Commit 6080751

Browse files
committed
Enabled simple mobile shadows + camp clean up
Campfire scene instances cleaned up some Tightened the shaders Added campfire light movement
1 parent 4efd193 commit 6080751

File tree

7 files changed

+62
-9
lines changed

7 files changed

+62
-9
lines changed

docs/js/pxlNav.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

docs/js/pxlRooms/CampfireEnvironment/CampfireEnvironment.js

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export class CampfireEnvironment extends RoomEnvironment{
6767

6868
this.materialList={};
6969
this.particleList={};
70+
71+
this.campfireLight = null;
7072

7173

7274
this.pxlCamFOV={ 'PC':60, 'MOBILE':80 };
@@ -76,7 +78,7 @@ export class CampfireEnvironment extends RoomEnvironment{
7678
this.pxlCamFarClipping = 5000;
7779

7880
// this.fogColor=new Color(.3,.3,.3);
79-
this.fogColor=new Color(.015,.025,.06);
81+
this.fogColor=new Color(.008,.020,.04);
8082
this.fogExp=.0055;
8183
this.fog=new FogExp2( this.fogColor, this.fogExp);
8284

@@ -152,6 +154,34 @@ export class CampfireEnvironment extends RoomEnvironment{
152154

153155
//let curFOV = this.pxlCamFOV[ this.mobile ? 'MOBILE' : 'PC' ];
154156
//this.pxlEnv.pxlCamera.setStats( curFOV, this.pxlCamZoom, this.pxlCamAspect, this.pxlCamNearClipping );
157+
158+
if( this.campfireLight ){
159+
// Flicker the campfire light color and intensity
160+
let basePos = this.campfireLight.origPos.clone();
161+
let totalIntensity = this.campfireLight.origIntensity;
162+
163+
let magnitude = 3.2; // Adjust the flicker magnitude
164+
165+
let timeOffset = this.msRunner.x * .3; // Adjust the flicker speed
166+
167+
let flickerNoise = Math.sin( timeOffset +
168+
this.campfireLight.position.x * 0.01 +
169+
this.campfireLight.position.y * 0.01 +
170+
this.campfireLight.position.z * 0.01 );
171+
172+
this.campfireLight.position.set(
173+
basePos.x + Math.sin( timeOffset + flickerNoise ) * magnitude,
174+
basePos.y + Math.cos( timeOffset + flickerNoise ) * 1.2,
175+
basePos.z + Math.sin( -timeOffset * 1.5 + flickerNoise * 0.5 ) * magnitude
176+
);
177+
this.campfireLight.intensity = totalIntensity * (
178+
Math.sin( timeOffset * 3.5 + flickerNoise*4.0
179+
+ this.campfireLight.position.x
180+
+ this.campfireLight.position.y
181+
+ this.campfireLight.position.z
182+
) * 0.1 + 1.0 ); // Flicker intensity
183+
}
184+
155185
}
156186

157187
checkEyeBlink(){
@@ -424,6 +454,17 @@ export class CampfireEnvironment extends RoomEnvironment{
424454
pokinStick.material.lights = true;
425455
}
426456

457+
458+
if( this.lightList.hasOwnProperty("PointLight") && this.lightList["PointLight"].length > 0 ){
459+
this.lightList["PointLight"].forEach( (light)=>{
460+
if( light.name == "point_campFire_lit" ){
461+
this.campfireLight = light;
462+
this.campfireLight.origPos = light.position.clone(); // Save the original position of the campfire light
463+
this.campfireLight.origIntensity = light.intensity; // Save the original intensity of the campfire light
464+
}
465+
});
466+
}
467+
427468
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
428469

429470
// Log replicator time!
@@ -560,7 +601,8 @@ export class CampfireEnvironment extends RoomEnvironment{
560601
// Enable shadows for non-mobile devices
561602
let shadowMapUniforms = this.mobile ? {} : UniformsLib[ "shadowmap" ];
562603
let hasShadowSettings = {
563-
'shadows' : this.mobile ? false : true,
604+
//'shadows' : this.mobile ? false : true,
605+
'shadows' : true,
564606
}
565607

566608
let envGroundUniforms = UniformsUtils.merge(
@@ -600,6 +642,10 @@ export class CampfireEnvironment extends RoomEnvironment{
600642
'USE_MAP' : "",
601643
};
602644

645+
let envGroundSettings = Object.assign( {}, hasShadowSettings, {
646+
'shadowReach' : this.mobile ? 0.65 : 0.3, // Shadow reach for non-mobile devices
647+
});
648+
603649
let environmentGroundMat=this.pxlFile.pxlShaderBuilder( envGroundUniforms, envGroundVert(hasShadowSettings), envGroundFrag(hasShadowSettings), defines );
604650
environmentGroundMat.lights= true;
605651
environmentGroundMat.transparent=false;
@@ -706,16 +752,20 @@ export class CampfireEnvironment extends RoomEnvironment{
706752
shadowMapUniforms,
707753
{
708754
'noiseTexture' : { type:'t', value: null },
755+
'intensity' : { type: "f", value: 1.25 },
709756
'fogColor' : { type: "c", value: this.fogColor },
710757
}]
711758
)
759+
760+
grassClusterUniforms.intensity.value = this.mobile ? 1.0 : 1.3; // Lower intensity for mobile devices
712761
grassClusterUniforms.noiseTexture.value = this.pxlUtils.loadTexture( this.assetPath+"Noise_UniformWebbing.jpg", null, {'encoding':SRGBColorSpace} );
713762

714763

715764
let grassMat=this.pxlFile.pxlShaderBuilder( grassClusterUniforms, grassClusterVert(hasShadowSettings), grassClusterFrag(hasShadowSettings) );
716765
grassMat.side = FrontSide;
717766
grassMat.lights = true;
718767
grassMat.transparent = false;
768+
719769

720770

721771
// -- -- --
@@ -738,6 +788,7 @@ export class CampfireEnvironment extends RoomEnvironment{
738788
'fogColor' : { type: "c", value: this.fogColor }
739789
}]
740790
)
791+
grassClusterUniforms.intensity.value = this.mobile ? 2.25 : 2.0; // Lower intensity for mobile devices
741792
grassCardsAUniforms.noiseTexture.value = this.pxlUtils.loadTexture( this.assetPath+"Noise_UniformWebbing.jpg" );
742793
grassCardsAUniforms.diffuse.value = this.pxlUtils.loadTexture( this.assetPath+"grassCardsA_diffuse.webp" );
743794
grassCardsAUniforms.alphaMap.value = this.pxlUtils.loadTexture( this.assetPath+"grassCardsA_alpha.jpg" );
@@ -749,7 +800,7 @@ export class CampfireEnvironment extends RoomEnvironment{
749800
'addCampfire' : true,
750801
'depthScalar': 0.003,
751802
'fogDepthScalar': 0.8,
752-
'shadows' : this.mobile ? false : true,
803+
'shadows' : true,
753804
}
754805

755806
let grassCardsMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert( hasShadowSettings ), instPlantsFrag( grassCardSettings ) );
@@ -758,7 +809,7 @@ export class CampfireEnvironment extends RoomEnvironment{
758809
grassCardsMat.transparent = false;
759810

760811
grassCardSettings['shadow'] = false; // Disable shadow for the far grass cards
761-
let grassCardsFarMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert( {} ), instPlantsFrag( grassCardSettings ) );
812+
let grassCardsFarMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert( hasShadowSettings ), instPlantsFrag( grassCardSettings ) );
762813
grassCardsFarMat.side = DoubleSide;
763814
grassCardsFarMat.lights = true;
764815
grassCardsFarMat.transparent = false;

docs/js/pxlRooms/CampfireEnvironment/Shaders/RabbitDruid_campfire.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export function rabbitDruidFrag(settings={}){
270270
vec3 lightInf= clamp( (dot(refTan, vN )+.15)*(1.65+areCd.g*.7)+.5, 0.0, 1.0) * pointLights[x].color;
271271
lights += lightInf * lightContrib;
272272
}
273-
outCd.rgb *= lights*.85;
273+
outCd.rgb *= lights;
274274
275275
// CampFire Light Magnitude; Ambient Light Mask
276276
lMag = min(1.0, max(0.0,length( lights )-.3)*.35 + max(0.0,-vN.y));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export function envGroundVert(settings={}){
104104
export function envGroundFrag(settings={}){
105105
const defaultSettings = {
106106
'shadows': false, // Set to true to enable shadow mapping
107+
'shadowReach': 0.3, // How far the shadows reach from the light source
107108
};
108109
settings = Object.assign({}, defaultSettings, settings);
109110

@@ -413,7 +414,7 @@ export function envGroundFrag(settings={}){
413414
float shadowMix = length(vPos)*.1;
414415
415416
float shadowMixFit = max(0.0,min(1.0, shadowMix*shadowMix*.04)*1.4-.4);
416-
float shadowRadius = max(0.0,min(1.0, 1.0-shadowMixFit*0.3));
417+
float shadowRadius = max(0.0, 1.0-shadowMixFit * ${settings.shadowReach});
417418
418419
for( int x = 0; x < NUM_POINT_LIGHT_SHADOWS; ++x ) {
419420
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 );
@@ -434,6 +435,7 @@ export function envGroundFrag(settings={}){
434435
shade = max( lights.r, shade * (1.0 - (vFarMask*.1+max(0.0,depth-.1))) );
435436
shade += length( lights ) ;
436437
shade *= dataCd.b*.35+.65*vInnerPitMask;
438+
shade = max( 0.0, shade-dataCd.r*(dataCd.r) * vPitMask );
437439
Cd.rgb= mix( Cd.rgb*shade, fogColor, depth );
438440
439441
gl_FragColor=Cd;

docs/js/pxlRooms/CampfireEnvironment/Shaders/grassCluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export function grassClusterFrag(settings={}){
366366
// -- -- -- -- -- -- -- -- -- --
367367
368368
float fogMix = clamp( depth * (depth*2.2501), 0.0, 0.85 ) ;
369-
Cd.rgb += Cd.rgb * (animWarpCd.r*3.0+.20) * vCampfireInf;
369+
Cd.rgb += Cd.rgb * intensity * (animWarpCd.r*3.0+.20) * vCampfireInf;
370370
Cd.rgb= mix( Cd.rgb, vFogColor, fogMix );
371371
Cd.a=1.0;
372372

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const projectName = "ProcStack.Github.io";
33
let listenIP = 'localhost';
4-
//listenIP = '192.168.1.3'; // For testing on my phone
4+
listenIP = '192.168.1.3'; // For testing on my phone
55
var httpPort = 3000;
66

77
const args = process.argv.slice(2);

0 commit comments

Comments
 (0)