Skip to content

Commit 9b60cd6

Browse files
committed
Hoodoos and Attribution Error Blog Entry
-Left and Right Hoodoos are linked to NDC, relative camera-screen space, so they always stay to the sides of the screen. -Attribution Error blog post on AI Notes & Research
1 parent be9cc89 commit 9b60cd6

11 files changed

Lines changed: 368 additions & 5 deletions

File tree

39.2 KB
Loading
83.5 KB
Loading
45.8 KB
Loading
102 KB
Loading
Binary file not shown.
Binary file not shown.

docs/js/pxlRooms/SaltFlatsEnvironment/SaltFlatsEnvironment.js

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import { RoomEnvironment, pxlEffects } from "pxlNav";
4141

4242
import { rabbitDruidVert, rabbitDruidFrag,
4343
envGroundVert, envGroundFrag,
44-
salioaPlantVert, salioaPlantFrag
44+
salioaPlantVert, salioaPlantFrag,
45+
hoodooVert, hoodooFrag
4546
} from "./Shaders.js";
4647

4748
const FloatingDust = pxlEffects.pxlParticles.FloatingDust;
@@ -104,6 +105,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
104105
this.inspectDuration = 1.5;
105106
this.inspectInitialTransition = 0;
106107

108+
this.initialHoodooSet = false;
107109

108110
this.touchMouseData={
109111
'active':false,
@@ -131,11 +133,11 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
131133
ndcPosition: null
132134
},
133135
'leftHoodooPosition': {
134-
basePosition: new Vector3( -.9, 0.5, 200 ),
136+
basePosition: new Vector3( -.83, 0.47, 165 ),
135137
ndcPosition: null
136138
},
137139
'rightHoodooPosition': {
138-
basePosition: new Vector3( .9, 0.5, 200 ),
140+
basePosition: new Vector3( .73, 0.47, 165 ),
139141
ndcPosition: null
140142
},
141143
};
@@ -199,6 +201,15 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
199201
coreCanvas.addEventListener("mouseup", (e)=>{ this.mapOnUp(e); }, false);
200202

201203
setTimeout(()=>{ this.setCameraSpaceNDC(); }, 0);
204+
205+
if( !this.initialHoodooSet ){
206+
setTimeout(() => {
207+
this.updateHoodooPositions();
208+
this.geoList["Scripted"]["Hoodoo_Left_geo"].updateMatrix();
209+
this.geoList["Scripted"]["Hoodoo_Right_geo"].updateMatrix();
210+
}, 10 );
211+
this.initialHoodooSet = true;
212+
}
202213
}
203214

204215
stop(){
@@ -304,6 +315,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
304315

305316
mapOnDown(e){
306317
//let target= e.path ? e.path[0] : e.target; // Chrome or Firefox
318+
if ( !this.inspectToMode ) return false;
307319
if( this.pxlTimer.active ){
308320
this.touchMouseData.button=e.which;
309321
this.touchMouseData.active=true;
@@ -319,6 +331,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
319331
}
320332
}
321333
mapOnMove(e){
334+
if ( !this.inspectToMode ) return false;
322335
if( this.pxlTimer.active || this.pxlDevice.cursorLockActive){
323336
this.pxlDevice.getMouseXY(e);
324337
if((this.touchMouseData.active || this.pxlDevice.cursorLockActive) && this.touchMouseData.startPos ){
@@ -332,6 +345,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
332345
}
333346
}
334347
mapOnUp(e){
348+
if ( !this.inspectToMode ) return false;
335349

336350
this.touchMouseData.dragCount++;
337351
this.touchMouseData.dragTotal+=this.touchMouseData.dragCount;
@@ -413,6 +427,21 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
413427
curMesh.morphTargetInfluences[0] = this.eyeBlinkInf.x;
414428
}
415429

430+
// -- -- --
431+
432+
updateHoodooPositions(){
433+
if( this.geoList["Scripted"]?.hasOwnProperty( "Hoodoo_Left_geo" ) && this.ndcPositions.leftHoodooPosition.ndcPosition ){
434+
let locPos = this.ndcPositions.leftHoodooPosition.ndcPosition.clone();
435+
this.geoList["Scripted"]["Hoodoo_Left_geo"].position.copy( locPos );
436+
this.geoList["Scripted"]["Hoodoo_Left_geo"].updateMatrix();
437+
}
438+
if( this.geoList["Scripted"]?.hasOwnProperty( "Hoodoo_Right_geo" ) && this.ndcPositions.rightHoodooPosition.ndcPosition ){
439+
let locPos = this.ndcPositions.rightHoodooPosition.ndcPosition.clone();
440+
this.geoList["Scripted"]["Hoodoo_Right_geo"].position.copy( locPos );
441+
this.geoList["Scripted"]["Hoodoo_Right_geo"].updateMatrix();
442+
}
443+
}
444+
416445
// -- -- --
417446

418447
prepInspectMode( curMesh ){
@@ -537,6 +566,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
537566
if( this.inspectToMode && this.inspectController && this.ndcPositions.inspectorPosition.ndcPosition ){
538567
setTimeout(()=>{
539568
this.inspectController.position.copy( this.ndcPositions.inspectorPosition.ndcPosition );
569+
this.updateHoodooPositions();
540570
});
541571
}
542572
super.resize( sw, sh );
@@ -617,6 +647,7 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
617647
}
618648
}
619649

650+
620651
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
621652

622653
// TODO : This needs to not be needed --
@@ -737,6 +768,40 @@ export class SaltFlatsEnvironment extends RoomEnvironment{
737768
envGroundUniforms.noiseTexture.value = this.pxlUtils.loadTexture( "Noise_UniformWebbing.jpg" );
738769
envGroundUniforms.smoothNoiseTexture.value = this.pxlUtils.loadTexture( "Noise_Soft3d.jpg", null, textureOptionsRepeat );
739770

771+
// -- -- --
772+
773+
let hoodooLeftUniforms = UniformsUtils.merge(
774+
[
775+
UniformsLib[ "lights" ],
776+
{
777+
'cloudTexture' : { type:'t', value: this.cloud3dTexture },
778+
'fogColor' : { type: "c", value: this.fogColor },
779+
}]
780+
)
781+
let hoodooLeftMtl=this.pxlFile.pxlShaderBuilder( hoodooLeftUniforms, hoodooVert(), hoodooFrag() );
782+
hoodooLeftMtl.lights= true;
783+
784+
this.materialList[ "Hoodoo_Left_geo" ]=hoodooLeftMtl;
785+
786+
// -- -- --
787+
788+
let hoodooRightUniforms = UniformsUtils.merge(
789+
[
790+
UniformsLib[ "lights" ],
791+
{
792+
'cloudTexture' : { type:'t', value: this.cloud3dTexture },
793+
'fogColor' : { type: "c", value: this.fogColor },
794+
}]
795+
)
796+
let hoodooRightMtl=this.pxlFile.pxlShaderBuilder( hoodooRightUniforms, hoodooVert(), hoodooFrag() );
797+
hoodooRightMtl.lights= true;
798+
799+
this.materialList[ "Hoodoo_Right_geo" ]=hoodooRightMtl;
800+
801+
802+
803+
804+
740805
// No need for normal maps on mobile
741806
// Just wasted resources with little pay off
742807
let enableNormalMap = !this.mobile;

docs/js/pxlRooms/SaltFlatsEnvironment/Shaders.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import {envGroundVert, envGroundFrag} from "./Shaders/envGround.js";
44
import {rabbitDruidVert, rabbitDruidFrag} from "./Shaders/rabbitDruid.js";
55
import {salioaPlantVert, salioaPlantFrag} from "./Shaders/salioaPlant.js";
6+
import {hoodooVert, hoodooFrag} from "./Shaders/hoodoo.js";
67

78
// -- -- -- -- -- -- -- -- -- -- -- //
89

910
export {
1011
envGroundVert, envGroundFrag,
1112
rabbitDruidVert, rabbitDruidFrag,
12-
salioaPlantVert, salioaPlantFrag
13+
salioaPlantVert, salioaPlantFrag,
14+
hoodooVert, hoodooFrag
1315
};
1416

1517

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// This is the shader for the crystals stickin out of the water
2+
// I wasn't sure what to make for a "plant" in a salty environment
3+
// With a little mysticism goin on
4+
// I should call it a `Salioa Cluster`
5+
// But I gotta rename this "salt flats" environment anyway hahaha
6+
7+
import { pxlShaders } from "pxlNav";
8+
const shaderHeader = pxlShaders.core.shaderHeader;
9+
10+
11+
export function hoodooVert(){
12+
let ret=shaderHeader();
13+
ret+=`
14+
attribute vec4 color;
15+
16+
varying vec2 vUv;
17+
varying vec3 vPos;
18+
varying vec3 vWorldPos;
19+
varying vec3 vLocalPos;
20+
varying vec3 vN;
21+
varying vec3 vLocalN;
22+
varying vec3 vCd;
23+
varying float vAlphaAdd;
24+
25+
void main(){
26+
vUv=uv;
27+
vCd=color.rgb;
28+
29+
vAlphaAdd = max(0.0, position.y);
30+
vAlphaAdd = min(1.0, vAlphaAdd*vAlphaAdd*.035 + max(0.0,1.0-vAlphaAdd*1.3 ) );
31+
vCd.g = 1.0-vCd.g;
32+
33+
vLocalPos = position;
34+
vN = (modelViewMatrix * vec4(normal, 0.0)).xyz;
35+
vLocalN = normal;
36+
37+
// Shift position to Instance position-
38+
vec4 pos = vec4( position, 1.0 );
39+
vPos = pos.xyz;
40+
41+
vec4 mvPos=modelViewMatrix * pos;
42+
gl_Position = projectionMatrix*mvPos;
43+
vWorldPos = gl_Position.xyz;
44+
45+
46+
}`;
47+
return ret;
48+
}
49+
50+
export function hoodooFrag(){
51+
let ret=shaderHeader();
52+
ret+=`
53+
uniform sampler2D diffuse;
54+
uniform sampler2D noiseTexture;
55+
uniform sampler2D cloudTexture;
56+
57+
uniform vec2 time;
58+
uniform vec3 fogColor;
59+
60+
varying vec2 vUv;
61+
varying vec3 vWorldPos;
62+
varying vec3 vPos;
63+
varying vec3 vN;
64+
varying vec3 vLocalN;
65+
varying vec3 vCd;
66+
varying float vAlphaAdd;
67+
68+
69+
struct DirLight {
70+
vec3 color;
71+
vec3 direction;
72+
};
73+
74+
#if NUM_DIR_LIGHTS > 0
75+
uniform DirLight directionalLights[NUM_DIR_LIGHTS];
76+
#endif
77+
78+
void main(){
79+
float timer = time.x*.01;
80+
vec3 pos = vPos*0.006666666666666; // Loop point is 150 units
81+
vec2 uv = vUv;
82+
float depth = min(1.0, gl_FragCoord.z / gl_FragCoord.w * .0035 );
83+
float depthFade = max(0.0, min(1.0, 1.1-depth ));
84+
depthFade *= depthFade*depthFade;
85+
86+
87+
// Initial color read
88+
vec4 Cd = texture2D(diffuse,vUv);
89+
90+
vec2 nUv = fract( vec2( (pos.x*2.+pos.z*1.5 + timer )*(1.0+ vCd.g*2.5) , pos.y*vCd.g ) );
91+
float nCd = texture2D(noiseTexture,nUv).r;
92+
93+
94+
// -- -- -- -- -- -- -- --
95+
// -- Direction Lights -- --
96+
// -- -- -- -- -- -- -- -- -- --
97+
98+
vec3 lights = vec3(0.0, 0.0, 0.0);
99+
#if NUM_DIR_LIGHTS > 0
100+
101+
for(int x = 0; x < NUM_DIR_LIGHTS; ++x) {
102+
vec3 lightInf= ( max(0.0, dot(normalize(directionalLights[x].direction+nCd*.65), reflect( normalize(vPos), vN ) ))) * directionalLights[x].color;
103+
lights += lightInf;
104+
}
105+
106+
lights = lights*(((1.0-vCd.g-vCd.r)*.5+.5)+ .5);
107+
#endif
108+
109+
lights = mix( vec3(0.0), lights, max( 0.0, nCd*vCd.g*.75 + vCd.r*.5 ) );
110+
111+
// Add blue lighting around some of the crystals
112+
lights += vec3( 0.3038, 0.3643, 0.679 ) * ( nCd*.2+.2 );
113+
114+
115+
116+
Cd.rgb += Cd.rgb * lights * (depthFade*.5+.5) ;
117+
118+
Cd.a = 1.0;
119+
120+
gl_FragColor=Cd;
121+
}`;
122+
return ret;
123+
}

0 commit comments

Comments
 (0)