1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
luanti/client/shaders/minimap_shader/opengl_fragment.glsl

39 lines
1.6 KiB
Text
Raw Normal View History

2015-06-22 04:34:56 +02:00
uniform sampler2D baseTexture;
uniform sampler2D normalTexture;
uniform vec3 yawVec;
2024-08-29 17:35:35 +02:00
uniform float mapSize;
2015-06-22 04:34:56 +02:00
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;
2015-06-22 04:34:56 +02:00
void main (void)
{
2024-08-29 17:35:35 +02:00
vec2 uv = varTexCoord;
2015-06-22 04:34:56 +02:00
//texture sampling rate
2024-08-29 17:35:35 +02:00
float step = 1.0 / mapSize;
2015-06-22 04:34:56 +02:00
float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r;
float t = texture2D(normalTexture, vec2(uv.x, uv.y + step)).r;
2015-06-22 04:34:56 +02:00
float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r;
float r = texture2D(normalTexture, vec2(uv.x + step, uv.y )).r;
2015-06-22 04:34:56 +02:00
float br = texture2D(normalTexture, vec2(uv.x + step, uv.y - step)).r;
float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r;
2015-06-22 04:34:56 +02:00
float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
float l = texture2D(normalTexture, vec2(uv.x - step, uv.y )).r;
2024-08-29 17:35:35 +02:00
float c = texture2D(normalTexture, vec2(uv.x , uv.y )).r;
float AO = 50.0 * (clamp(t - c, -0.001, 0.001) + clamp(b - c, -0.001, 0.001) + clamp(r - c, -0.001, 0.001) + clamp(l - c, -0.001, 0.001));
float dX = 4.0 * (l - r);
float dY = 4.0 * (t - b);
vec3 bump = normalize(vec3 (dX, dY, 0.1));
2015-06-22 04:34:56 +02:00
float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0;
vec4 base = texture2D(baseTexture, uv).rgba;
2024-08-29 17:35:35 +02:00
vec3 L = normalize(vec3(0.0, 0.0, 1.0));
2015-06-22 04:34:56 +02:00
float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0);
2024-08-29 17:35:35 +02:00
float diffuse = dot(yawVec, bump);
2015-06-22 04:34:56 +02:00
2024-08-29 17:35:35 +02:00
vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular + AO) * base.rgb;
vec4 col = vec4(color, base.a);
col *= varColor;
2015-06-22 04:34:56 +02:00
gl_FragColor = vec4(col.rgb, base.a);
}