1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Minimap shenanigans

Half broken lol
This commit is contained in:
Gefüllte Taubenbrust 2024-08-29 17:35:35 +02:00
parent e5afca89f7
commit ed4cc81c23
3 changed files with 18 additions and 11 deletions

View file

@ -1,16 +1,17 @@
uniform sampler2D baseTexture; uniform sampler2D baseTexture;
uniform sampler2D normalTexture; uniform sampler2D normalTexture;
uniform vec3 yawVec; uniform vec3 yawVec;
uniform float mapSize;
varying lowp vec4 varColor; varying lowp vec4 varColor;
varying mediump vec2 varTexCoord; varying mediump vec2 varTexCoord;
void main (void) void main (void)
{ {
vec2 uv = varTexCoord.st; vec2 uv = varTexCoord;
//texture sampling rate //texture sampling rate
const float step = 1.0 / 256.0; float step = 1.0 / mapSize;
float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r; float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r;
float t = texture2D(normalTexture, vec2(uv.x, uv.y + step)).r; float t = texture2D(normalTexture, vec2(uv.x, uv.y + step)).r;
float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r; float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r;
@ -19,17 +20,19 @@ void main (void)
float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r; float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r;
float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r; float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
float l = texture2D(normalTexture, vec2(uv.x - step, uv.y )).r; float l = texture2D(normalTexture, vec2(uv.x - step, uv.y )).r;
float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl); float c = texture2D(normalTexture, vec2(uv.x , uv.y )).r;
float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr); 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));
vec4 bump = vec4 (normalize(vec3 (dX, dY, 0.1)),1.0); float dX = 4.0 * (l - r);
float dY = 4.0 * (t - b);
vec3 bump = normalize(vec3 (dX, dY, 0.1));
float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0; float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0;
vec4 base = texture2D(baseTexture, uv).rgba; vec4 base = texture2D(baseTexture, uv).rgba;
vec3 L = normalize(vec3(0.0, 0.75, 1.0)); vec3 L = normalize(vec3(0.0, 0.0, 1.0));
float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0); float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0);
float diffuse = dot(yawVec, bump.xyz); float diffuse = dot(yawVec, bump);
vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular) * base.rgb; vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular + AO) * base.rgb;
vec4 col = vec4(color.rgb, base.a); vec4 col = vec4(color, base.a);
col *= varColor; col *= varColor;
gl_FragColor = vec4(col.rgb, base.a); gl_FragColor = vec4(col.rgb, base.a);
} }

View file

@ -384,6 +384,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
CachedPixelShaderSetting<float, 3> m_artificial_light{ "artificialLight" }; CachedPixelShaderSetting<float, 3> m_artificial_light{ "artificialLight" };
CachedPixelShaderSetting<float, 3> m_day_light{"dayLight"}; CachedPixelShaderSetting<float, 3> m_day_light{"dayLight"};
CachedPixelShaderSetting<float, 3> m_minimap_yaw{"yawVec"}; CachedPixelShaderSetting<float, 3> m_minimap_yaw{"yawVec"};
CachedPixelShaderSetting<float> m_minimap_size{"mapSize"};
CachedVertexShaderSetting<float, 3> m_camera_offset_vertex{"cameraOffset"}; CachedVertexShaderSetting<float, 3> m_camera_offset_vertex{"cameraOffset"};
CachedPixelShaderSetting<float, 3> m_camera_offset_pixel{ "cameraOffset" }; CachedPixelShaderSetting<float, 3> m_camera_offset_pixel{ "cameraOffset" };
CachedVertexShaderSetting<float, 3> m_camera_position_vertex{"cameraPosition"}; CachedVertexShaderSetting<float, 3> m_camera_position_vertex{"cameraPosition"};
@ -507,6 +508,8 @@ public:
if (m_client->getMinimap()) { if (m_client->getMinimap()) {
v3f minimap_yaw = m_client->getMinimap()->getYawVec(); v3f minimap_yaw = m_client->getMinimap()->getYawVec();
m_minimap_yaw.set(minimap_yaw, services); m_minimap_yaw.set(minimap_yaw, services);
float minimap_size = m_client->getMinimap()->getModeDef().map_size;
m_minimap_size.set(&minimap_size, services);
} }
v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS); v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS);

View file

@ -607,8 +607,8 @@ void Minimap::drawMinimap(core::rect<s32> rect)
video::SMaterial &material = m_meshbuffer->getMaterial(); video::SMaterial &material = m_meshbuffer->getMaterial();
material.forEachTexture([] (auto &tex) { material.forEachTexture([] (auto &tex) {
tex.MinFilter = video::ETMINF_LINEAR_MIPMAP_LINEAR; tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST;
tex.MagFilter = video::ETMAGF_LINEAR; tex.MagFilter = video::ETMAGF_NEAREST;
}); });
material.Lighting = false; material.Lighting = false;
material.TextureLayers[0].Texture = minimap_texture; material.TextureLayers[0].Texture = minimap_texture;
@ -648,6 +648,7 @@ void Minimap::drawMinimap(core::rect<s32> rect)
driver->setTransform(video::ETS_WORLD, matrix); driver->setTransform(video::ETS_WORLD, matrix);
driver->setMaterial(material); driver->setMaterial(material);
driver->drawMeshBuffer(m_meshbuffer); driver->drawMeshBuffer(m_meshbuffer);
driver->drawMeshBuffer(m_meshbuffer);
// Reset transformations // Reset transformations
driver->setTransform(video::ETS_VIEW, oldViewMat); driver->setTransform(video::ETS_VIEW, oldViewMat);