From b911ee90443dfc5ae1280a122e1b98c70aca1276 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 13 Mar 2018 21:41:37 +0100 Subject: [PATCH] calcualte texel offset on CPU not GPU --- data/shader/bordertilelinetex.frag | 4 ++-- data/shader/bordertilelinetex.vert | 10 ++++------ data/shader/bordertiletex.frag | 4 ++-- data/shader/bordertiletex.vert | 10 ++++------ data/shader/prim.frag | 3 ++- data/shader/tiletex.frag | 4 ++-- data/shader/tiletex.vert | 10 ++++------ 7 files changed, 20 insertions(+), 25 deletions(-) diff --git a/data/shader/bordertilelinetex.frag b/data/shader/bordertilelinetex.frag index ae2d34e0a..8bfb70294 100644 --- a/data/shader/bordertilelinetex.frag +++ b/data/shader/bordertilelinetex.frag @@ -3,13 +3,13 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; +uniform float LOD; noperspective in vec2 texCoord; -flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = textureLod(textureSampler, texCoord, fragLOD); + vec4 tex = textureLod(textureSampler, texCoord, LOD); FragClr = tex * vertColor; } diff --git a/data/shader/bordertilelinetex.vert b/data/shader/bordertilelinetex.vert index 7e937044b..7f273fa90 100644 --- a/data/shader/bordertilelinetex.vert +++ b/data/shader/bordertilelinetex.vert @@ -5,12 +5,11 @@ layout (location = 1) in vec2 inVertexTexCoord; layout (location = 2) in ivec2 inVertexTexRightOrBottom; uniform mat4x2 Pos; -uniform float LOD; +uniform float TexelOffset; uniform vec2 Dir; noperspective out vec2 texCoord; -flat out float fragLOD; void main() { @@ -19,10 +18,9 @@ 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))); - 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; + + texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset)); } diff --git a/data/shader/bordertiletex.frag b/data/shader/bordertiletex.frag index ae2d34e0a..8bfb70294 100644 --- a/data/shader/bordertiletex.frag +++ b/data/shader/bordertiletex.frag @@ -3,13 +3,13 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; +uniform float LOD; noperspective in vec2 texCoord; -flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = textureLod(textureSampler, texCoord, fragLOD); + vec4 tex = textureLod(textureSampler, texCoord, LOD); FragClr = tex * vertColor; } diff --git a/data/shader/bordertiletex.vert b/data/shader/bordertiletex.vert index cd98d3454..b02508e6e 100644 --- a/data/shader/bordertiletex.vert +++ b/data/shader/bordertiletex.vert @@ -5,14 +5,13 @@ layout (location = 1) in vec2 inVertexTexCoord; layout (location = 2) in ivec2 inVertexTexRightOrBottom; uniform mat4x2 Pos; -uniform float LOD; +uniform float TexelOffset; uniform vec2 Offset; uniform vec2 Dir; uniform int JumpIndex; noperspective out vec2 texCoord; -flat out float fragLOD; void main() { @@ -23,10 +22,9 @@ 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))); - 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; + + texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset)); } diff --git a/data/shader/prim.frag b/data/shader/prim.frag index 34c499202..eb287be8f 100644 --- a/data/shader/prim.frag +++ b/data/shader/prim.frag @@ -9,7 +9,8 @@ noperspective in vec4 vertColor; out vec4 FragClr; void main() { - if(isTextured == 1) { + if(isTextured == 1) + { vec4 tex = texture(textureSampler, texCoord); FragClr = tex * vertColor; } diff --git a/data/shader/tiletex.frag b/data/shader/tiletex.frag index 2917d5d56..e2f185fa3 100644 --- a/data/shader/tiletex.frag +++ b/data/shader/tiletex.frag @@ -3,13 +3,13 @@ uniform sampler2D textureSampler; uniform vec4 vertColor; +uniform float LOD; noperspective in vec2 texCoord; -flat in float fragLOD; out vec4 FragClr; void main() { - vec4 tex = textureLod(textureSampler, texCoord, fragLOD); + vec4 tex = textureLod(textureSampler, texCoord, LOD); FragClr = tex * vertColor; } diff --git a/data/shader/tiletex.vert b/data/shader/tiletex.vert index 43082381d..5fcd6e75e 100644 --- a/data/shader/tiletex.vert +++ b/data/shader/tiletex.vert @@ -5,18 +5,16 @@ layout (location = 1) in vec2 inVertexTexCoord; layout (location = 2) in ivec2 inVertexTexRightOrBottom; uniform mat4x2 Pos; -uniform float LOD; +uniform float TexelOffset; 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))); - 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; + + texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset)); }