Skip to content

Commit 4efd193

Browse files
committed
Shadows added to the Campfire Env.
Ground, grass cards, grass clusters, pokin stick Cleaned up the fbx too
1 parent 61ee27f commit 4efd193

File tree

8 files changed

+696
-58
lines changed

8 files changed

+696
-58
lines changed

docs/js/procPages/ProcPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ export class ProcPage {
296296

297297
let vidId = mediaData.src;
298298
let ytEmbed;
299-
if( typeof YT === 'undefined' ){
299+
if( typeof YT === 'undefined' || typeof YT.Player === 'undefined' ){
300+
// Fallback to iframe if YT API is not loaded
300301
ytEmbed = document.createElement('iframe');
301302
ytEmbed.src = "https://www.youtube-nocookie.com/embed/"+vidId;
302303
ytEmbed.title = mediaData.alt;

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: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
DoubleSide, FrontSide,
2929
UniformsUtils, UniformsLib,
3030
SRGBColorSpace, LinearSRGBColorSpace,
31-
AmbientLight
31+
AmbientLight,
32+
MeshPhongMaterial
3233
} from "../../libs/three/three.module.min.js";
3334

3435
import { RoomEnvironment, pxlShaders, pxlEffects } from "../../pxlNav.esm.js";
@@ -394,6 +395,37 @@ export class CampfireEnvironment extends RoomEnvironment{
394395

395396
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
396397

398+
399+
let lightTypeList = Object.keys( this.lightList );
400+
if( lightTypeList.length>0){
401+
lightTypeList.forEach( (type)=>{
402+
this.lightList[type].forEach( (light)=>{
403+
if( type == "DirectionalLight" ){
404+
light.castShadow=false;
405+
}else if( type == "PointLight" ){
406+
light.shadow.radius = 5;
407+
light.shadow.receiveShadow = true;
408+
light.shadow.mapSize.width = 512; // default
409+
light.shadow.mapSize.height = 512; // default
410+
light.shadow.camera.near = 0.5; // default
411+
light.shadow.camera.far = 35; // default
412+
light.shadow.bias = .025; // default
413+
light.shadow.radius = 5; // default
414+
}
415+
});
416+
});
417+
}
418+
419+
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
420+
421+
if( !this.pxlOptions.mobile && this.geoList.hasOwnProperty("pokinStick_geo") ){
422+
let pokinStick = this.geoList["pokinStick_geo"];
423+
pokinStick.castShadow = true;
424+
pokinStick.material.lights = true;
425+
}
426+
427+
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
428+
397429
// Log replicator time!
398430
// Making some shader materials for our burny burny logs.
399431
// Lets get them crackling in that flame!
@@ -455,9 +487,17 @@ export class CampfireEnvironment extends RoomEnvironment{
455487

456488
let curMesh = this.pxlAnim.getMesh( animKey );
457489
if(curMesh){
490+
491+
let envGroundSettings = {
492+
//'shadows' : this.mobile ? false : true,
493+
}
494+
495+
curMesh.castShadow = true;
496+
curMesh.receiveShadow = true;
497+
458498
let curMtl = curMesh.material;
459499
curMtl.side = DoubleSide;
460-
let newSkinnedMtl = this.setSkinnedMaterial( curMesh, rabbitDruidVert(), rabbitDruidFrag() );
500+
let newSkinnedMtl = this.setSkinnedMaterial( curMesh, rabbitDruidVert(envGroundSettings), rabbitDruidFrag(envGroundSettings) );
461501
this.materialList[ "RabbitDruidA" ] = newSkinnedMtl;
462502
}
463503

@@ -469,10 +509,14 @@ export class CampfireEnvironment extends RoomEnvironment{
469509

470510
setSkinnedMaterial( bindObj, vertShader=null, fragShader=null ){
471511

512+
// Enable shadows for non-mobile devices
513+
let shadowMapUniforms = this.mobile ? {} : UniformsLib[ "shadowmap" ];
514+
472515
let skinnedMtlUniforms = UniformsUtils.merge(
473516
[
474517
UniformsLib['common'],
475518
UniformsLib['lights'],
519+
shadowMapUniforms,
476520
{
477521
'diffuseTexture' : { type:'t', value: null },
478522
'areTexture' : { type:'t', value: null },
@@ -513,25 +557,31 @@ export class CampfireEnvironment extends RoomEnvironment{
513557
// -- Environment Ground Material - -- --
514558
// -- -- -- -- -- -- -- -- -- -- -- -- -- --
515559

560+
// Enable shadows for non-mobile devices
561+
let shadowMapUniforms = this.mobile ? {} : UniformsLib[ "shadowmap" ];
562+
let hasShadowSettings = {
563+
'shadows' : this.mobile ? false : true,
564+
}
565+
516566
let envGroundUniforms = UniformsUtils.merge(
517-
[
518-
UniformsLib[ "common" ],
519-
UniformsLib[ "lights" ],
520-
UniformsLib[ "shadowmap" ],
521-
{
522-
'diffuse' : { type:'t', value: null },
523-
'dirtDiffuse' : { type:'t', value: null },
524-
'crackedDirtDiffuse' : { type:'t', value: null },
525-
'hillDiffuse' : { type:'t', value: null },
526-
'mossDiffuse' : { type:'t', value: null },
527-
'grassDiffuse' : { type:'t', value: null },
528-
'dataDiffuse' : { type:'t', value: null },
529-
'fogColor': { type:'c', value: null },
530-
'noiseTexture' : { type:'t', value: null },
531-
'uniformNoise' : { type:'t', value: null },
532-
}
533-
]
534-
);
567+
[
568+
UniformsLib[ "common" ],
569+
UniformsLib[ "lights" ],
570+
shadowMapUniforms,
571+
{
572+
'diffuse' : { type:'t', value: null },
573+
'dirtDiffuse' : { type:'t', value: null },
574+
'crackedDirtDiffuse' : { type:'t', value: null },
575+
'hillDiffuse' : { type:'t', value: null },
576+
'mossDiffuse' : { type:'t', value: null },
577+
'grassDiffuse' : { type:'t', value: null },
578+
'dataDiffuse' : { type:'t', value: null },
579+
'fogColor': { type:'c', value: null },
580+
'noiseTexture' : { type:'t', value: null },
581+
'uniformNoise' : { type:'t', value: null },
582+
}
583+
]
584+
);
535585

536586
envGroundUniforms.fogColor.value = this.fogColor;
537587
envGroundUniforms.diffuse.value = this.pxlUtils.loadTexture( this.assetPath+"EnvGround_Diffuse.webp", null, {'encoding':SRGBColorSpace} );
@@ -546,9 +596,16 @@ export class CampfireEnvironment extends RoomEnvironment{
546596
envGroundUniforms.noiseTexture.value = this.cloud3dTexture;
547597
envGroundUniforms.uniformNoise.value = this.pxlUtils.loadTexture( this.assetPath+"Noise_UniformWebbing.jpg", null, {'encoding':LinearSRGBColorSpace} );
548598

549-
let environmentGroundMat=this.pxlFile.pxlShaderBuilder( envGroundUniforms, envGroundVert(), envGroundFrag(4) );
599+
var defines = {
600+
'USE_MAP' : "",
601+
};
602+
603+
let environmentGroundMat=this.pxlFile.pxlShaderBuilder( envGroundUniforms, envGroundVert(hasShadowSettings), envGroundFrag(hasShadowSettings), defines );
550604
environmentGroundMat.lights= true;
551605
environmentGroundMat.transparent=false;
606+
environmentGroundMat.meshSettings = {
607+
'receiveShadow' : true,
608+
};
552609

553610
envGroundUniforms.uniformNoise.value.wrapS = RepeatWrapping;
554611
envGroundUniforms.uniformNoise.value.wrapT = RepeatWrapping;
@@ -644,7 +701,9 @@ export class CampfireEnvironment extends RoomEnvironment{
644701

645702
let grassClusterUniforms = UniformsUtils.merge(
646703
[
704+
UniformsLib[ "common" ],
647705
UniformsLib[ "lights" ],
706+
shadowMapUniforms,
648707
{
649708
'noiseTexture' : { type:'t', value: null },
650709
'fogColor' : { type: "c", value: this.fogColor },
@@ -653,7 +712,7 @@ export class CampfireEnvironment extends RoomEnvironment{
653712
grassClusterUniforms.noiseTexture.value = this.pxlUtils.loadTexture( this.assetPath+"Noise_UniformWebbing.jpg", null, {'encoding':SRGBColorSpace} );
654713

655714

656-
let grassMat=this.pxlFile.pxlShaderBuilder( grassClusterUniforms, grassClusterVert(), grassClusterFrag() );
715+
let grassMat=this.pxlFile.pxlShaderBuilder( grassClusterUniforms, grassClusterVert(hasShadowSettings), grassClusterFrag(hasShadowSettings) );
657716
grassMat.side = FrontSide;
658717
grassMat.lights = true;
659718
grassMat.transparent = false;
@@ -668,8 +727,9 @@ export class CampfireEnvironment extends RoomEnvironment{
668727

669728
let grassCardsAUniforms = UniformsUtils.merge(
670729
[
671-
UniformsLib[ "lights" ],
672-
/*UniformsLib[ "shadowmap" ],*/
730+
UniformsLib[ "common" ],
731+
UniformsLib[ "lights" ],
732+
shadowMapUniforms,
673733
{
674734
'diffuse' : { type:'t', value: null },
675735
'alphaMap' : { type:'t', value: null },
@@ -689,15 +749,19 @@ export class CampfireEnvironment extends RoomEnvironment{
689749
'addCampfire' : true,
690750
'depthScalar': 0.003,
691751
'fogDepthScalar': 0.8,
752+
'shadows' : this.mobile ? false : true,
692753
}
693754

694-
let grassCardsMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert(), instPlantsFrag( grassCardSettings ) );
755+
let grassCardsMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert( hasShadowSettings ), instPlantsFrag( grassCardSettings ) );
695756
grassCardsMat.side = DoubleSide;
696757
grassCardsMat.lights = true;
697758
grassCardsMat.transparent = false;
698-
//grassCardsMat.alphaTest = .5;
699-
//grassCardsMat.blending = ;
700759

760+
grassCardSettings['shadow'] = false; // Disable shadow for the far grass cards
761+
let grassCardsFarMat=this.pxlFile.pxlShaderBuilder( grassCardsAUniforms, instPlantsVert( {} ), instPlantsFrag( grassCardSettings ) );
762+
grassCardsFarMat.side = DoubleSide;
763+
grassCardsFarMat.lights = true;
764+
grassCardsFarMat.transparent = false;
701765

702766

703767
// -- -- --
@@ -745,6 +809,7 @@ export class CampfireEnvironment extends RoomEnvironment{
745809
//this.materialList[ "mushroomA_lod1_geo" ] = grassMat;
746810
this.materialList[ "grassCardsA_lod0_geo" ] = grassCardsMat;
747811
this.materialList[ "grassCardsA_lod1_geo" ] = grassCardsMat;
812+
this.materialList[ "grassCardsA_lod2_geo" ] = grassCardsFarMat;
748813

749814

750815
//

0 commit comments

Comments
 (0)