#version 330 core uniform vec3 u_campos; in vec3 v_position; in vec3 v_normal; in vec2 v_texcoord; layout (location=0) out vec4 v_output; uniform sampler2D u_texture; float get_fog_factor(float d) { const float FogMax = 10.0; const float FogMin = 0.0; if (d >= FogMax) return 1.0; if (d <= FogMin) return 0.0; return 1 - (FogMax - d) / (FogMax - FogMin); } struct Light { vec3 position; vec3 diffuse; }; float lambert(vec3 n, vec3 l) { vec3 nrmn = normalize(n); vec3 nrml = normalize(l); float res = dot(nrmn, nrml); return max(res, 0.0); } float dist(vec2 p0, vec2 pf){return sqrt((pf.x-p0.x)*(pf.x-p0.x)+(pf.y-p0.y)*(pf.y-p0.y));} void main() { Light light; light.position = vec3(0.0, 0.0, 0.0); light.diffuse = vec3(1.0, 1.0, 1.0); vec2 tc = v_texcoord; tc.x = (v_texcoord.x)+u_campos.x/1000.0; //mod(u_campos.x/1024.0, 10.0); tc.y = (v_texcoord.y)+u_campos.z/1000.0; //mod(u_campos.z/1024.0, 10.0); tc.x *= 64.0; tc.y *= 64.0; vec4 tex = texture(u_texture, tc); vec3 norm = normalize(v_normal); vec3 res = light.diffuse * lambert(norm, light.position); float a = dist(v_position.xy, vec2(0.0, 0.0)) * 2.0f; v_output = vec4(tex.rgb, tex.a - a); /* vec3 col; vec4 tex = texture(u_texture, v_texcoord); vec3 norm = normalize(v_normal); vec3 dir = normalize(vec3(5.0, 0.25, -5.0) - v_position); float diff = max(dot(norm, dir), 0.0); float alpha = get_fog_factor(distance(u_campos, v_position)); vec3 diffuse = diff * vec3(0.8, 0.75, 0.7); float ff = 1.75; if (diffuse.x > 0.0) diffuse.x *= ff; if (diffuse.y > 0.0) diffuse.y *= ff; if (diffuse.z > 0.0) diffuse.z *= ff; vec3 ambient = vec3(0.3, 0.3, 0.3); col = (ambient + diffuse) * tex.rgb; col *= mix(vec4(1.0), vec4(0.0f, 0.0, 0.0, 1.0), alpha-0.2).xyz; */ // vec4 tex = texture(u_texture, v_texcoord); // v_output = tex * vec4(vec3(1.5), 1.0); }