mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
also out the LOD to the fragment shader to make sure we use the same LOD
on every hardware
This commit is contained in:
parent
5389dd9666
commit
cc54c4acdf
|
@ -5,10 +5,11 @@ uniform sampler2D textureSampler;
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
|
flat in float fragLOD;
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = texture(textureSampler, texCoord);
|
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ uniform float LOD;
|
||||||
uniform vec2 Dir;
|
uniform vec2 Dir;
|
||||||
|
|
||||||
noperspective out vec2 texCoord;
|
noperspective out vec2 texCoord;
|
||||||
|
flat out float fragLOD;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -18,9 +19,10 @@ void main()
|
||||||
VertPos.y += Dir.y * (gl_InstanceID+1);
|
VertPos.y += Dir.y * (gl_InstanceID+1);
|
||||||
|
|
||||||
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
|
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
|
||||||
float F1 = -(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+1.0))));
|
float F2 = (0.5/(1024.0 * pow(0.5, LOD)));
|
||||||
float tx = (inVertexTexCoord.x/(16.0));
|
float tx = (inVertexTexCoord.x/(16.0));
|
||||||
float ty = (inVertexTexCoord.y/(16.0));
|
float ty = (inVertexTexCoord.y/(16.0));
|
||||||
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
||||||
|
fragLOD = LOD;
|
||||||
}
|
}
|
|
@ -5,10 +5,11 @@ uniform sampler2D textureSampler;
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
|
flat in float fragLOD;
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = texture(textureSampler, texCoord);
|
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ uniform vec2 Dir;
|
||||||
uniform int JumpIndex;
|
uniform int JumpIndex;
|
||||||
|
|
||||||
noperspective out vec2 texCoord;
|
noperspective out vec2 texCoord;
|
||||||
|
flat out float fragLOD;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -22,9 +23,10 @@ void main()
|
||||||
VertPos.y += Offset.y + Dir.y * YCount;
|
VertPos.y += Offset.y + Dir.y * YCount;
|
||||||
|
|
||||||
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
|
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
|
||||||
float F1 = -(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+1.0))));
|
float F2 = (0.5/(1024.0 * pow(0.5, LOD)));
|
||||||
float tx = (inVertexTexCoord.x/(16.0));
|
float tx = (inVertexTexCoord.x/(16.0));
|
||||||
float ty = (inVertexTexCoord.y/(16.0));
|
float ty = (inVertexTexCoord.y/(16.0));
|
||||||
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
||||||
|
fragLOD = LOD;
|
||||||
}
|
}
|
|
@ -5,10 +5,11 @@ uniform sampler2D textureSampler;
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
|
flat in float fragLOD;
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = texture(textureSampler, texCoord);
|
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
|
@ -8,13 +8,15 @@ uniform mat4x2 Pos;
|
||||||
uniform float LOD;
|
uniform float LOD;
|
||||||
|
|
||||||
noperspective out vec2 texCoord;
|
noperspective out vec2 texCoord;
|
||||||
|
flat out float fragLOD;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
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 F1 = -(0.5/(1024.0 * pow(0.5, LOD)));
|
||||||
float F2 = (0.5/(1024.0 * pow(0.5, (LOD+1.0))));
|
float F2 = (0.5/(1024.0 * pow(0.5, LOD)));
|
||||||
float tx = (inVertexTexCoord.x/(16.0));
|
float tx = (inVertexTexCoord.x/(16.0));
|
||||||
float ty = (inVertexTexCoord.y/(16.0));
|
float ty = (inVertexTexCoord.y/(16.0));
|
||||||
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? F2 : F1), ty + (inVertexTexRightOrBottom.y == 0 ? F2 : F1));
|
||||||
|
fragLOD = LOD;
|
||||||
}
|
}
|
|
@ -929,7 +929,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe
|
||||||
//prevent mipmap display bugs, when zooming out far
|
//prevent mipmap display bugs, when zooming out far
|
||||||
if(Width >= 1024 && Height >= 1024)
|
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);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5);
|
||||||
}
|
}
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);
|
glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);
|
||||||
|
|
|
@ -879,9 +879,9 @@ void CGraphics_Threaded::DrawVisualObject(int VisualObjectIDX, float* pColor, ch
|
||||||
Cmd.m_IndicesDrawNum = NumIndicesOffet;
|
Cmd.m_IndicesDrawNum = NumIndicesOffet;
|
||||||
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
||||||
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
|
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
|
//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
|
//log2 gives us the amount of halving the texture for mipmapping
|
||||||
int LOD = (int)log2f(LODFactor);
|
int LOD = (int)log2f(LODFactor);
|
||||||
//5 because log2(1024/(2^5)) is 5 -- 2^5 = 32 which would mean 2 pixels per tile index
|
//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_DrawNum = DrawNum;
|
||||||
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
||||||
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
|
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
|
//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
|
//log2 gives us the amount of halving the texture for mipmapping
|
||||||
int LOD = (int)log2f(LODFactor);
|
int LOD = (int)log2f(LODFactor);
|
||||||
if(LOD > 5) LOD = 5;
|
if(LOD > 5) LOD = 5;
|
||||||
|
@ -984,9 +984,9 @@ void CGraphics_Threaded::DrawBorderTileLine(int VisualObjectIDX, float* pColor,
|
||||||
Cmd.m_DrawNum = RedrawNum;
|
Cmd.m_DrawNum = RedrawNum;
|
||||||
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
Cmd.m_VisualObjectIDX = m_VertexArrayIndices[VisualObjectIDX];
|
||||||
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
|
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
|
//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
|
//log2 gives us the amount of halving the texture for mipmapping
|
||||||
int LOD = (int)log2f(LODFactor);
|
int LOD = (int)log2f(LODFactor);
|
||||||
if(LOD > 5) LOD = 5;
|
if(LOD > 5) LOD = 5;
|
||||||
|
|
Loading…
Reference in a new issue