Index: ps/trunk/binaries/data/mods/public/gui/session/minimap/MiniMap.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/minimap/MiniMap.xml +++ ps/trunk/binaries/data/mods/public/gui/session/minimap/MiniMap.xml @@ -5,7 +5,7 @@ type="image" > - + - + + + Index: ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.fs =================================================================== --- ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.fs +++ ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.fs @@ -5,6 +5,11 @@ varying vec2 v_tex; #endif +#if MINIMAP_MASK + uniform sampler2D maskTex; + varying vec2 v_maskUV; +#endif + #if MINIMAP_POINT varying vec3 color; #endif @@ -15,9 +20,19 @@ void main() { + #if MINIMAP_MASK + float mask = texture2D(maskTex, v_maskUV).a; + #endif + #if MINIMAP_BASE + #if MINIMAP_MASK + vec4 color = texture2D(baseTex, v_tex); + gl_FragColor.rgb = color.rgb; + gl_FragColor.a = color.a * mask; + #else gl_FragColor = texture2D(baseTex, v_tex); #endif + #endif #if MINIMAP_LOS gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0 - texture2D(baseTex, v_tex).a); Index: ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.vs =================================================================== --- ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.vs +++ ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.vs @@ -4,9 +4,17 @@ uniform mat4 textureTransform; uniform float pointSize; -#if MINIMAP_BASE || MINIMAP_LOS +#if MINIMAP_MASK + uniform mat4 maskTextureTransform; + varying vec2 v_maskUV; +#endif + +#if MINIMAP_BASE || MINIMAP_LOS || MINIMAP_MASK attribute vec3 a_vertex; attribute vec2 a_uv0; +#endif + +#if MINIMAP_BASE || MINIMAP_LOS varying vec2 v_tex; #endif @@ -27,6 +35,10 @@ v_tex = (textureTransform * vec4(a_uv0, 0.0, 1.0)).xy; #endif + #if MINIMAP_MASK + v_maskUV = (maskTextureTransform * vec4(a_uv0, 0.0, 1.0)).xy; + #endif + #if MINIMAP_POINT gl_PointSize = pointSize; gl_Position = transform * vec4(a_vertex, 0.0, 1.0); Index: ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.xml =================================================================== --- ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.xml +++ ps/trunk/binaries/data/mods/public/shaders/glsl/minimap.xml @@ -3,10 +3,10 @@ - + - + Index: ps/trunk/source/gui/ObjectTypes/CMiniMap.h =================================================================== --- ps/trunk/source/gui/ObjectTypes/CMiniMap.h +++ ps/trunk/source/gui/ObjectTypes/CMiniMap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -83,6 +83,9 @@ // whether we need to regenerate the terrain texture bool m_TerrainDirty; + // Whether to draw a black square around and under the minimap. + bool m_Mask; + ssize_t m_Width, m_Height; // map size Index: ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp +++ ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp @@ -70,9 +70,11 @@ CMiniMap::CMiniMap(CGUI& pGUI) : IGUIObject(pGUI), m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f), - m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW), + m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW), m_Mask(false), m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false), m_WaterHeight(0.0) { + RegisterSetting("mask", m_Mask); + m_Clicking = false; m_MouseHovering = false; @@ -427,6 +429,7 @@ const float angle = GetAngle(); const float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f); + CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); // Disable depth updates to prevent apparent z-fighting-related issues // with some drivers causing units to get drawn behind the texture. glDepthMask(0); @@ -436,26 +439,53 @@ CShaderDefines baseDefines; baseDefines.Add(str_MINIMAP_BASE, str_1); + if (m_Mask) + baseDefines.Add(str_MINIMAP_MASK, str_1); + tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), baseDefines); tech->BeginPass(); shader = tech->GetShader(); // Draw the main textured quad shader->BindTexture(str_baseTex, m_TerrainTexture); + if (m_Mask) + { + shader->BindTexture(str_maskTex, losTexture.GetTexture()); + CMatrix3D maskTextureTransform = *losTexture.GetMinimapTextureMatrix(); + // We need to have texture coordinates in the same coordinate space. + const float scale = 1.0f / texCoordMax; + maskTextureTransform.Scale(scale, scale, 1.0f); + shader->Uniform(str_maskTextureTransform, maskTextureTransform); + } const CMatrix3D baseTransform = GetDefaultGuiMatrix(); CMatrix3D baseTextureTransform; baseTextureTransform.SetIdentity(); shader->Uniform(str_transform, baseTransform); shader->Uniform(str_textureTransform, baseTextureTransform); + if (m_Mask) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + DrawTexture(shader, texCoordMax, angle, x, y, x2, y2, z); - // Draw territory boundaries - glEnable(GL_BLEND); + if (!m_Mask) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + // Draw territory boundaries CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture(); shader->BindTexture(str_baseTex, territoryTexture.GetTexture()); + if (m_Mask) + { + shader->BindTexture(str_maskTex, losTexture.GetTexture()); + shader->Uniform(str_maskTextureTransform, *losTexture.GetMinimapTextureMatrix()); + } const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix(); shader->Uniform(str_transform, baseTransform); shader->Uniform(str_textureTransform, *territoryTransform); @@ -464,23 +494,22 @@ tech->EndPass(); // Draw the LOS quad in black, using alpha values from the LOS texture - CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); - - CShaderDefines losDefines; - losDefines.Add(str_MINIMAP_LOS, str_1); - tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), losDefines); - tech->BeginPass(); - shader = tech->GetShader(); - shader->BindTexture(str_baseTex, losTexture.GetTexture()); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix(); - shader->Uniform(str_transform, baseTransform); - shader->Uniform(str_textureTransform, *losTransform); + if (!m_Mask) + { + CShaderDefines losDefines; + losDefines.Add(str_MINIMAP_LOS, str_1); + tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), losDefines); + tech->BeginPass(); + shader = tech->GetShader(); + shader->BindTexture(str_baseTex, losTexture.GetTexture()); + + const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix(); + shader->Uniform(str_transform, baseTransform); + shader->Uniform(str_textureTransform, *losTransform); - DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); - tech->EndPass(); + DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); + tech->EndPass(); + } glDisable(GL_BLEND); Index: ps/trunk/source/ps/CStrInternStatic.h =================================================================== --- ps/trunk/source/ps/CStrInternStatic.h +++ ps/trunk/source/ps/CStrInternStatic.h @@ -41,6 +41,7 @@ X(MINIMAP_BASE) X(MINIMAP_LINE) X(MINIMAP_LOS) +X(MINIMAP_MASK) X(MINIMAP_POINT) X(MODE_SHADOWCAST) X(MODE_SILHOUETTEDISPLAY) @@ -109,6 +110,7 @@ X(los_interp) X(mapSize) X(maskTex) +X(maskTextureTransform) X(minimap) X(modelViewMatrix) X(murkiness)