KP3Dii/Data/resources/shaders/.kp3d/map_grid_f.glsl

65 lines
1.2 KiB
GLSL
Raw Normal View History

2024-07-22 07:48:42 +00:00
#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);
2024-07-24 08:17:46 +00:00
tc.x *= 1000.0;
tc.y *= 1000.0;
2024-07-22 07:48:42 +00:00
vec4 tex = texture(u_texture, tc);
vec3 norm = normalize(v_normal);
vec3 res = light.diffuse * lambert(norm, light.position);
2024-07-27 22:27:31 +00:00
float a = dist(v_position.xz, vec2(0.0, 0.0)) * 25.0f;
2024-07-22 07:48:42 +00:00
2024-07-27 22:27:31 +00:00
tex.rgb *= 1.0 - a;
v_output = vec4(tex.rgb, tex.a);
2024-07-22 07:48:42 +00:00
}