varying vec2 texCoord;
uniform sampler2D baseMap;
uniform sampler2D noiseMap;
uniform sampler2D skyMap;
uniform samplerCube envMap;

uniform float anim;
varying vec3 norm;
varying vec3 eyeVec;
varying vec3 lightVec;
varying vec4 eyeVecProj;
void main()
{
vec3 noiseSample = texture2D(noiseMap,vec2(anim*0.03 - texCoord.x*13.1,anim*0.0003 - texCoord.y*93.01)).rgb * 2.0 - vec3(1.0,1.0,1.0);
vec3 bumpNorm = norm;
bumpNorm.x+=noiseSample.x*0.3 + sin(anim*0.02 + texCoord.x*0.4 + texCoord.y*0.4)*0.08 + 0.08;
bumpNorm.z+=noiseSample.z*0.3 + cos(anim*0.02 + texCoord.x*0.1 +1.0323 + texCoord.y*0.4)*0.08 + 0.08;
bumpNorm = normalize(bumpNorm);

vec3 lightVec2=normalize(lightVec);
float lightRec = max(dot(bumpNorm,lightVec2),0.2);
float spec = clamp(dot(reflect(normalize(eyeVec),bumpNorm),normalize(-lightVec2)),0.0,1.0);
spec = pow(spec,4.0);
float dist = length(eyeVec)/1.0;
spec = spec*(1.0/pow(dist,1.3));
vec3 envCol = textureCube(envMap,reflect(normalize(eyeVec),bumpNorm)).rgb;

vec4 col = texture2D(baseMap,vec2(texCoord.x*12.0,texCoord.y*193.0+anim*1.3));

vec2 tC = refract(eyeVecProj.xyz,bumpNorm,0.9).xy/eyeVecProj.w;
tC=tC*0.5 + vec2(0.5);
vec3 lookThrough = texture2D(skyMap,tC).rgb;

envCol = vec3(envCol.r/3.0 + envCol.g/3.0 + envCol.b/3.0);

gl_FragColor = vec4((envCol*0.7 + lookThrough*0.3) ,1.00);
}

