I put the noise texture in the alpha channel of the normalmap, since I wasn't using it. But, I also left room in it in case I wanted to add different noise textures.
I also added the ability to base the moss of height.
#version 120
uniform sampler2D texture0; // Diffuse
uniform sampler2D texture1; //Normal Map
uniform sampler2D texture2; //Moss
uniform sampler2D texture3; //Noise texture
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7; // Shadow
//uniform mediump vec3 SunLightValue;
varying highp vec3 posVarying;
varying mediump vec3 vertPos;
varying mediump vec3 TangentViewPos;
varying mediump vec3 TangentLightPos;
varying mediump vec3 TangentFragPos;
varying mediump vec3 normalVarying;
varying mediump vec2 uvVarying;
varying mediump vec3 lightVarying;
uniform mediump vec4 agk_MeshEmissive;
uniform mediump vec4 agk_MeshDiffuse;
uniform mediump vec3 agk_CameraPos;
uniform float agk_time;
uniform float water_level;
uniform float mossHeight;
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );
mediump vec3 blend(mediump vec4 TextureA, float a1, mediump vec4 TextureB, float a2);
void main()
{
mediump vec3 viewDir = normalize( TangentViewPos - TangentFragPos );
mediump vec3 lightDir = normalize( TangentLightPos - TangentFragPos );
mediump vec4 MainColor = texture2D(texture0, uvVarying);
mediump vec4 RocknormalMap = texture2D(texture1, uvVarying);
mediump vec4 MossColor = texture2D(texture2, uvVarying);
float n = 1.0-RocknormalMap.a;
//float n = texture2D(texture3, uvVarying).r; // for own noise texture
float k = clamp(vertPos.y/mossHeight,0.0,1.0);
n = k*n;
vec3 finalColor = blend(MainColor,(1.0-n),MossColor,n);
mediump vec3 ambient = 0.2 * finalColor.rgb;
RocknormalMap.rgb = normalize(RocknormalMap.rgb*2.0-1.0);
float diff = max(dot(lightDir, RocknormalMap.rgb), 0.05);
finalColor.rgb = diff*finalColor.rgb;
//spec
mediump vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(RocknormalMap.rgb, halfwayDir), 0.0), 32.0);
mediump vec3 specular = vec3(.02) * spec;
finalColor.rgb = finalColor.rgb+specular+ambient;
mediump vec3 light = clamp(lightVarying + GetPSLighting( RocknormalMap.rgb, posVarying ),.5,1.0);
finalColor = ApplyFog( finalColor * light, posVarying );
finalColor = mix( finalColor, vec3( 0.63529, .89, .86 ), clamp((posVarying.y+(water_level*-1.0))/-2.45,0,1) );
gl_FragColor = vec4(finalColor,MainColor.a)*agk_MeshDiffuse+agk_MeshEmissive;
}
mediump vec3 blend(mediump vec4 TextureA, float a1, mediump vec4 TextureB, float a2)
{
float depth = 0.4;
float ma = max(TextureA.a + a1, TextureB.a + a2) - depth;
float b1 = max(TextureA.a + a1 - ma, 0);
float b2 = max(TextureB.a + a2 - ma, 0);
return (TextureA.rgb * b1 + TextureB.rgb * b2) / (b1 + b2);
}
Thanks for the cool tips, btw!