calcualte texel offset on CPU not GPU

This commit is contained in:
Jupeyy 2018-03-13 21:41:37 +01:00
parent 3858a930a9
commit b911ee9044
7 changed files with 20 additions and 25 deletions

View file

@ -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;
} }

View file

@ -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));
} }

View file

@ -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;
} }

View file

@ -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));
} }

View file

@ -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;
} }

View file

@ -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;
} }

View file

@ -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));
} }