@@ -183,6 +183,12 @@ export function rabbitDruidVert(){
183183export function envGroundVert ( ) {
184184 let ret = shaderHeader ( ) ;
185185 ret += `
186+ #ifdef GL_FRAGMENT_PRECISION_HIGH
187+ precision highp float;
188+ #else
189+ precision mediump float;
190+ #endif
191+
186192 #define USE_INSTANCING
187193
188194 attribute vec4 color;
@@ -194,6 +200,8 @@ export function envGroundVert(){
194200 varying vec3 vLocalN;
195201 varying vec3 vCd;
196202
203+ varying mat3 vTBN;
204+
197205 void main(){
198206 vUv=uv;
199207 vCd=color.rgb;
@@ -211,7 +219,12 @@ export function envGroundVert(){
211219
212220 vec4 mvPos=modelViewMatrix * pos;
213221 gl_Position = projectionMatrix*mvPos;
214- vPos = position;
222+ vPos = mvPos.xyz;
223+
224+ // Create TBN Matrix for normal mapping
225+ vec3 tangent = normalize( mat3(modelMatrix) * vec3(1.0, 0.0, 0.0) );
226+ vec3 bitangent = ( cross( vLocalN, tangent ) );
227+ vTBN = mat3( tangent, bitangent, vLocalN );
215228
216229 }` ;
217230 return ret ;
@@ -222,15 +235,22 @@ export function envGroundFrag(){
222235 let ret = shaderHeader ( ) ;
223236 ret += `
224237 uniform sampler2D diffuse;
238+ uniform sampler2D normalTexture;
225239 uniform sampler2D noiseTexture;
240+ uniform sampler2D smoothNoiseTexture;
241+ uniform sampler2D cloudTexture;
242+
226243
227244 uniform vec2 time;
228245 uniform vec3 fogColor;
229246
230247 varying vec2 vUv;
231248 varying vec3 vPos;
249+ varying vec3 vLocalPos;
232250 varying vec3 vN;
251+ varying vec3 vLocalN;
233252 varying vec3 vCd;
253+ varying mat3 vTBN;
234254
235255
236256 struct DirLight {
@@ -242,43 +262,68 @@ export function envGroundFrag(){
242262 uniform DirLight directionalLights[NUM_DIR_LIGHTS];
243263 #endif
244264
265+ #define EPSILON 0.00001
266+
245267 void main(){
246- float timer = time.x*.01 ;
268+ float timer = time.x*.02 ;
247269 vec3 pos = vPos*0.006666666666666; // Loop point is 150 units
248270 vec2 uv = vUv;
249271 float depth = min(1.0, gl_FragCoord.z / gl_FragCoord.w * .0035 );
250272 float depthFade = max(0.0, min(1.0, 1.1-depth ));
251273 depthFade *= depthFade*depthFade;
252274
253- float crystalGlow = max(0.0,vCd.b-.25);
275+ float plantGrowth = mix( 0.0, pow(vCd.z, 1.0 / 2.2), step( EPSILON, vCd.z));
276+ float crystalGlow = clamp( max(0.0,plantGrowth*plantGrowth*.8-.15), 0.0,1.0);
254277
255278 // Initial color read
256279 vec4 Cd = texture2D(diffuse,vUv);
257280
258281 vec2 nUv = fract( vec2( (pos.x*2.+pos.z*1.5 + + timer*crystalGlow )*(1.0+ vCd.g*2.5) , pos.y*vCd.g ) );
259282 float nCd = texture2D(noiseTexture,nUv).r;
283+ nUv = fract( vec2( (pos.x*1.+pos.z*.5 + + timer + plantGrowth )*(1.0+ vCd.g*2.5) , pos.y*vCd.g ) );
284+ vec3 snCd = texture2D(smoothNoiseTexture,nUv).rgb;
285+ vec3 snCdFit = texture2D(smoothNoiseTexture,nUv).rgb*2.0-1.0;
286+
260287
288+ // -- -- -- -- -- -- -- --
289+ // -- Normal Map Calc - -- --
290+ // -- -- -- -- -- -- -- -- -- --
291+
292+ //vec3 nMap = (texture2D(normalTexture, vUv).xyz-.5) * 1.5 + .5;
293+ vec3 nMap = (texture2D(normalTexture, vUv).xyz);// * 2.0 - 1.0;
294+ //nMap = normalize( vTBN * nMap );
295+
296+
261297 // -- -- -- -- -- -- -- --
262298 // -- Direction Lights -- --
263299 // -- -- -- -- -- -- -- -- -- --
264300
265301 vec3 lights = vec3(0.0, 0.0, 0.0);
266302 #if NUM_DIR_LIGHTS > 0
267-
303+ vec3 lightInf=vec3(0.0);
268304 for(int x = 0; x < NUM_DIR_LIGHTS; ++x) {
269- vec3 lightInf= ( max(0.0, dot(normalize(directionalLights[x].direction+nCd*.65), reflect( normalize(vPos), vN ) ))) * directionalLights[x].color;
305+ vec3 lightInf= max(0.0, dot(normalize(directionalLights[x].direction), reflect( -normalize(vPos), nMap ) )*.5+.5) * directionalLights[x].color;
306+ //lightInf= ( max(0.0, dot(normalize(directionalLights[x].direction), nMap ))) * directionalLights[x].color;
270307 lights += lightInf;
308+ //lights = max(lights, vec3(dot( directionalLights[x].direction, nMap)*.5+.5 + plantGrowth));
271309 }
272-
273- lights = lights*(((1.0-vCd.g-vCd.r)*.5+.5)+ .5);
274310 #endif
275311
276- lights = mix( vec3(0.0), lights, max( 0.0, nCd*vCd.g*.75 + vCd.r*.5 ) );
312+ // Lighting Influence based on surface normals
313+ float facingDown = dot( normalize( nMap ), vec3(0.0,1.0,0.0) ) *.45 +.55;
314+ facingDown = clamp( (facingDown*facingDown)*1.4, 0.0, 1.0 );
315+
316+ //lights = mix( vec3(0.0), lights*facingDown, max( 0.0, nCd*vCd.g*.75 + vCd.r*.5 ) );
277317
278318 // Add blue lighting around some of the crystals
279- lights += vec3( 0.4038, 0.643, 0.779 ) * (crystalGlow * nCd );
319+ crystalGlow *= (nCd);
320+ lights = (lights + vec3( 0.4038, 0.643, 0.779 ) * (crystalGlow * nCd )) * 1.5;
280321
281- Cd.rgb += Cd.rgb * lights * (depthFade*.5+.5) ;
322+ float scalar = sin( plantGrowth*2. + time.x*1.5 + vPos.z*.2 + vPos.x*.2 - vPos.y*.2 + snCd.x*2. + snCd.y*4. + snCd.z*5. )+1.0;
323+ scalar = cos( scalar*2. - time.x*.3 + vPos.y*2. + snCd.x + snCd.y + snCd.z )*0.5 + scalar;
324+ scalar = clamp( (scalar*scalar*snCd.r+.5) * plantGrowth * 2. * vCd.y* vCd.y, 0.0, 1.0);
325+ Cd.rgb += vec3( 0.4038, 0.643, 0.779 ) * ( (depthFade*.85)* scalar) ;
326+ //Cd.rgb = vec3( scalar ) ;
282327
283328 gl_FragColor=Cd;
284329 }` ;
@@ -312,7 +357,7 @@ export function salioaPlantVert(){
312357 vCd=color.rgb;
313358
314359 vAlphaAdd = max(0.0, position.y);
315- vAlphaAdd = min(1.0, vAlphaAdd*vAlphaAdd*.014 + max(0.0,1.0-vAlphaAdd*1.3 ) );
360+ vAlphaAdd = min(1.0, vAlphaAdd*vAlphaAdd*.035 + max(0.0,1.0-vAlphaAdd*1.3 ) );
316361 vCd.g = 1.0-vCd.g;
317362
318363 vLocalPos = position;
@@ -410,14 +455,15 @@ export function salioaPlantFrag(){
410455
411456 Cd.rgb = vec3( 0.4545, 0.8138, 1.0 ) * cnCrystal * vAlphaAdd;
412457
413- Cd.rgb += vec3(0.3122, .3683,.4011) * ( min(.8, (nCd) * (1.0+cnCrystal*cnCd.g) )+0.75 );
458+ Cd.rgb += vec3(0.3122, .3683,.4011) * ( min(.8, (nCd) * (1.0+cnCrystal*cnCd.g) )+0.65 );
414459 Cd.rgb += Cd.rgb * lights * (depthFade*.5+.5) ;
415460
416461
417462 float alpha = abs(dot( normalize(-vWorldPos), vLocalN ))*.35 * (cnCd.x * cnCd.y * cnCd.z+.5) ;
418- Cd.a=abs(.5 -min(1.0,vCd.x*vN.z))+.5;
463+ Cd.a=abs(.85 -min(1.0,vCd.x*vN.z))+.5;
419464 alpha = clamp( alpha*cnCd.x + vAlphaAdd, 0.0, 0.5 )+.5;
420465 Cd.a = clamp( Cd.a*alpha + .2, 0.0, 1.0 );
466+ //Cd.rgb = vec3(vAlphaAdd);
421467
422468 gl_FragColor=Cd;
423469 }` ;
0 commit comments