diff --git a/shader/bordertilelinetex.frag b/shader/bordertilelinetex.frag index 3b2759915..3af09e06c 100644 --- a/shader/bordertilelinetex.frag +++ b/shader/bordertilelinetex.frag @@ -5,10 +5,11 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; noperspective in vec2 texCoord; +flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = texture(textureSampler, texCoord); + vec4 tex = textureLod(textureSampler, texCoord, fragLOD); FragClr = tex * vertColor; } \ No newline at end of file diff --git a/shader/bordertilelinetex.vert b/shader/bordertilelinetex.vert index 4a203cdb4..6ed47f154 100644 --- a/shader/bordertilelinetex.vert +++ b/shader/bordertilelinetex.vert @@ -10,6 +10,7 @@ uniform float LOD; uniform vec2 Dir; noperspective out vec2 texCoord; +flat out float fragLOD; void main() { @@ -18,9 +19,10 @@ void main() VertPos.y += Dir.y * (gl_InstanceID+1); gl_Position = vec4(Pos * VertPos, 0.0, 1.0); - float F1 = -(0.5/(1024.0 * pow(0.5, (LOD+1.0)))); - float F2 = (0.5/(1024.0 * pow(0.5, (LOD+1.0)))); + float F1 = -(0.5/(1024.0 * pow(0.5, LOD))); + float F2 = (0.5/(1024.0 * pow(0.5, LOD))); float tx = (inVertexTexCoord.x/(16.0)); float ty = (inVertexTexCoord.y/(16.0)); texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1)); + fragLOD = LOD; } \ No newline at end of file diff --git a/shader/bordertiletex.frag b/shader/bordertiletex.frag index 3b2759915..3af09e06c 100644 --- a/shader/bordertiletex.frag +++ b/shader/bordertiletex.frag @@ -5,10 +5,11 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; noperspective in vec2 texCoord; +flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = texture(textureSampler, texCoord); + vec4 tex = textureLod(textureSampler, texCoord, fragLOD); FragClr = tex * vertColor; } \ No newline at end of file diff --git a/shader/bordertiletex.vert b/shader/bordertiletex.vert index 278017c68..fe1c23be9 100644 --- a/shader/bordertiletex.vert +++ b/shader/bordertiletex.vert @@ -12,6 +12,7 @@ uniform vec2 Dir; uniform int JumpIndex; noperspective out vec2 texCoord; +flat out float fragLOD; void main() { @@ -22,9 +23,10 @@ void main() VertPos.y += Offset.y + Dir.y * YCount; gl_Position = vec4(Pos * VertPos, 0.0, 1.0); - float F1 = -(0.5/(1024.0 * pow(0.5, (LOD+1.0)))); - float F2 = (0.5/(1024.0 * pow(0.5, (LOD+1.0)))); + float F1 = -(0.5/(1024.0 * pow(0.5, LOD))); + float F2 = (0.5/(1024.0 * pow(0.5, LOD))); float tx = (inVertexTexCoord.x/(16.0)); float ty = (inVertexTexCoord.y/(16.0)); texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1)); + fragLOD = LOD; } \ No newline at end of file diff --git a/shader/tiletex.frag b/shader/tiletex.frag index 1a834e336..f1a21e775 100644 --- a/shader/tiletex.frag +++ b/shader/tiletex.frag @@ -5,10 +5,11 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; noperspective in vec2 texCoord; +flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = texture(textureSampler, texCoord); + vec4 tex = textureLod(textureSampler, texCoord, fragLOD); FragClr = tex * vertColor; } \ No newline at end of file diff --git a/shader/tiletex.vert b/shader/tiletex.vert index f007603ad..5acb6c886 100644 --- a/shader/tiletex.vert +++ b/shader/tiletex.vert @@ -8,13 +8,15 @@ uniform mat4x2 Pos; uniform float LOD; noperspective out vec2 texCoord; +flat out float fragLOD; void main() { gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0); - float F1 = -(0.5/(1024.0 * pow(0.5, (LOD+1.0)))); - float F2 = (0.5/(1024.0 * pow(0.5, (LOD+1.0)))); + float F1 = -(0.5/(1024.0 * pow(0.5, LOD))); + float F2 = (0.5/(1024.0 * pow(0.5, LOD))); float tx = (inVertexTexCoord.x/(16.0)); float ty = (inVertexTexCoord.y/(16.0)); texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1)); + fragLOD = LOD; } \ No newline at end of file diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 55635f02a..01b675d33 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -929,7 +929,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe //prevent mipmap display bugs, when zooming out far if(Width >= 1024 && Height >= 1024) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5.f); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); } glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index ad8efb6eb..691d5fcba 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -879,9 +879,9 @@ void CGraphics_Threaded::DrawVisualObject(int VisualObjectIDX, float* pColor, ch Cmd.m_IndicesDrawNum = NumIndicesOffet; Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX]; mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color)); - float ScreenZoomRatio = (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x) / ScreenWidth(); + float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x); //the number of pixels we would skip in the fragment shader -- basically the LOD - float LODFactor = (64.f / (32.f * 1.f/ScreenZoomRatio)); + float LODFactor = (64.f / (32.f * ScreenZoomRatio)); //log2 gives us the amount of halving the texture for mipmapping int LOD = (int)log2f(LODFactor); //5 because log2(1024/(2^5)) is 5 -- 2^5 = 32 which would mean 2 pixels per tile index @@ -943,9 +943,9 @@ void CGraphics_Threaded::DrawBorderTile(int VisualObjectIDX, float* pColor, char Cmd.m_DrawNum = DrawNum; Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX]; mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color)); - float ScreenZoomRatio = (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x) / ScreenWidth(); + float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x); //the number of pixels we would skip in the fragment shader -- basically the LOD - float LODFactor = (64.f / (32.f * 1.f/ScreenZoomRatio)); + float LODFactor = (64.f / (32.f * ScreenZoomRatio)); //log2 gives us the amount of halving the texture for mipmapping int LOD = (int)log2f(LODFactor); if(LOD > 5) LOD = 5; @@ -984,9 +984,9 @@ void CGraphics_Threaded::DrawBorderTileLine(int VisualObjectIDX, float* pColor, Cmd.m_DrawNum = RedrawNum; Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX]; mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color)); - float ScreenZoomRatio = (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x) / ScreenWidth(); + float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x); //the number of pixels we would skip in the fragment shader -- basically the LOD - float LODFactor = (64.f / (32.f * 1.f/ScreenZoomRatio)); + float LODFactor = (64.f / (32.f * ScreenZoomRatio)); //log2 gives us the amount of halving the texture for mipmapping int LOD = (int)log2f(LODFactor); if(LOD > 5) LOD = 5;