mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
calcualte texel offset on CPU not GPU
This commit is contained in:
parent
3858a930a9
commit
b911ee9044
|
@ -3,13 +3,13 @@
|
||||||
uniform sampler2D textureSampler;
|
uniform sampler2D textureSampler;
|
||||||
|
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
uniform float LOD;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
flat in float fragLOD;
|
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
vec4 tex = textureLod(textureSampler, texCoord, LOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,11 @@ layout (location = 1) in vec2 inVertexTexCoord;
|
||||||
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
||||||
|
|
||||||
uniform mat4x2 Pos;
|
uniform mat4x2 Pos;
|
||||||
uniform float LOD;
|
uniform float TexelOffset;
|
||||||
|
|
||||||
uniform vec2 Dir;
|
uniform vec2 Dir;
|
||||||
|
|
||||||
noperspective out vec2 texCoord;
|
noperspective out vec2 texCoord;
|
||||||
flat out float fragLOD;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -19,10 +18,9 @@ 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)));
|
|
||||||
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));
|
|
||||||
fragLOD = LOD;
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
uniform sampler2D textureSampler;
|
uniform sampler2D textureSampler;
|
||||||
|
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
uniform float LOD;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
flat in float fragLOD;
|
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
vec4 tex = textureLod(textureSampler, texCoord, LOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,13 @@ layout (location = 1) in vec2 inVertexTexCoord;
|
||||||
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
||||||
|
|
||||||
uniform mat4x2 Pos;
|
uniform mat4x2 Pos;
|
||||||
uniform float LOD;
|
uniform float TexelOffset;
|
||||||
|
|
||||||
uniform vec2 Offset;
|
uniform vec2 Offset;
|
||||||
uniform vec2 Dir;
|
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()
|
||||||
{
|
{
|
||||||
|
@ -23,10 +22,9 @@ 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)));
|
|
||||||
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));
|
|
||||||
fragLOD = LOD;
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ noperspective in vec4 vertColor;
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
if(isTextured == 1) {
|
if(isTextured == 1)
|
||||||
|
{
|
||||||
vec4 tex = texture(textureSampler, texCoord);
|
vec4 tex = texture(textureSampler, texCoord);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
uniform sampler2D textureSampler;
|
uniform sampler2D textureSampler;
|
||||||
|
|
||||||
uniform vec4 vertColor;
|
uniform vec4 vertColor;
|
||||||
|
uniform float LOD;
|
||||||
|
|
||||||
noperspective in vec2 texCoord;
|
noperspective in vec2 texCoord;
|
||||||
flat in float fragLOD;
|
|
||||||
|
|
||||||
out vec4 FragClr;
|
out vec4 FragClr;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex = textureLod(textureSampler, texCoord, fragLOD);
|
vec4 tex = textureLod(textureSampler, texCoord, LOD);
|
||||||
FragClr = tex * vertColor;
|
FragClr = tex * vertColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,16 @@ layout (location = 1) in vec2 inVertexTexCoord;
|
||||||
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
|
||||||
|
|
||||||
uniform mat4x2 Pos;
|
uniform mat4x2 Pos;
|
||||||
uniform float LOD;
|
uniform float TexelOffset;
|
||||||
|
|
||||||
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)));
|
|
||||||
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));
|
|
||||||
fragLOD = LOD;
|
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue