float signOf(float x){
if(x >= 0.0){return 1.0;}
return 0.0;
}
const vec3 lightDir = vec3(-1.0, -0.0, -1.0);
highp float randff(highp float n){
return fract(sin(n) * 3782.288); //fract(sin(n) * 3782.0);
}
highp float cos_between_vecs(highp vec3 v1, highp vec3 v2){
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z) / length(v1) / length(v2);
}
highp float CalcLightByNormal(highp vec3 lightdir, highp vec3 normal){
return min(1.0, acos(cos_between_vecs(lightdir, normal)) / 3.14195);
}
vec4 AddLight(vec4 texcolor, vec4 lightmap, float light, float shadow){
vec4 ambient = texcolor * lightmap;
vec4 torch = texcolor * vec4(1.0, light * light, 0.0, 1.0);
vec4 fog = vec4(1.0, min(1.0, sqrt(light)), 0.2, 1.0);
if(shadow < 0.05){light = 0.0; ambient *= 1.1;}
return mix(ambient, torch, light) + fog * light * 0.5;
}
highp float smoothrand(highp float pos){
highp float start = floor(pos);
#ifdef FANCY
highp float smooth = smoothstep(0.0, 1.0, fract(pos));
#else
highp float smooth = fract(pos);
#endif
return mix(randff(start), randff(start + 1.0), smooth);
}
highp float smoothrand2d(highp float horizont, highp float forward){
highp float start = floor(forward);
#ifdef FANCY
highp float smooth = smoothstep(0.0, 1.0, fract(forward));
#else
highp float smooth = fract(forward);
#endif
return mix(smoothrand(horizont + randff(start) * 1000.0), smoothrand(horizont + randff(start + 1.0) * 1000.0), smooth);
}
highp float CheapWaterMap(highp vec3 pos){
pos.z += TIME * 0.4;
highp float wave1 = smoothrand2d(pos.z, pos.x / 6.0);
highp float wave2 = sin(wave1) * 0.5 + 0.5;
float interp = sin(TIME * 3.0 + sin(pos.z * 0.3728) + sin(pos.x * 0.4264)) * 0.5 + 0.5;
return mix(wave1, wave2, interp);
}
highp vec3 WaterNormalMap(highp vec3 pos){
highp float value = (CheapWaterMap(pos + vec3(0.0, 0.0, 0.1)) - CheapWaterMap(pos)) * 7.5;
return vec3(0.0, 1.0, -value);
}
if(x >= 0.0){return 1.0;}
return 0.0;
}
const vec3 lightDir = vec3(-1.0, -0.0, -1.0);
highp float randff(highp float n){
return fract(sin(n) * 3782.288); //fract(sin(n) * 3782.0);
}
highp float cos_between_vecs(highp vec3 v1, highp vec3 v2){
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z) / length(v1) / length(v2);
}
highp float CalcLightByNormal(highp vec3 lightdir, highp vec3 normal){
return min(1.0, acos(cos_between_vecs(lightdir, normal)) / 3.14195);
}
vec4 AddLight(vec4 texcolor, vec4 lightmap, float light, float shadow){
vec4 ambient = texcolor * lightmap;
vec4 torch = texcolor * vec4(1.0, light * light, 0.0, 1.0);
vec4 fog = vec4(1.0, min(1.0, sqrt(light)), 0.2, 1.0);
if(shadow < 0.05){light = 0.0; ambient *= 1.1;}
return mix(ambient, torch, light) + fog * light * 0.5;
}
highp float smoothrand(highp float pos){
highp float start = floor(pos);
#ifdef FANCY
highp float smooth = smoothstep(0.0, 1.0, fract(pos));
#else
highp float smooth = fract(pos);
#endif
return mix(randff(start), randff(start + 1.0), smooth);
}
highp float smoothrand2d(highp float horizont, highp float forward){
highp float start = floor(forward);
#ifdef FANCY
highp float smooth = smoothstep(0.0, 1.0, fract(forward));
#else
highp float smooth = fract(forward);
#endif
return mix(smoothrand(horizont + randff(start) * 1000.0), smoothrand(horizont + randff(start + 1.0) * 1000.0), smooth);
}
highp float CheapWaterMap(highp vec3 pos){
pos.z += TIME * 0.4;
highp float wave1 = smoothrand2d(pos.z, pos.x / 6.0);
highp float wave2 = sin(wave1) * 0.5 + 0.5;
float interp = sin(TIME * 3.0 + sin(pos.z * 0.3728) + sin(pos.x * 0.4264)) * 0.5 + 0.5;
return mix(wave1, wave2, interp);
}
highp vec3 WaterNormalMap(highp vec3 pos){
highp float value = (CheapWaterMap(pos + vec3(0.0, 0.0, 0.1)) - CheapWaterMap(pos)) * 7.5;
return vec3(0.0, 1.0, -value);
}