Skip to content

Commit

Permalink
Bugfix: Fix shaders so tiling now works (at least at native res)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozniak committed Jul 3, 2020
1 parent 0fbc9ee commit 9bc74f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 29 deletions.
52 changes: 49 additions & 3 deletions Rzxe/Windowing/Implementations/GlfwFx/Shaders/fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
#version 330 core

in vec2 fsUV;
in vec2 fsUV;
in vec4 fsSourceRect;
in vec2 fsOrigin;
in float fsDrawMode;

out vec4 Colour;
out vec4 outColor;

uniform vec2 gCanvasResolution;
uniform vec2 gUvMapResolution;
uniform sampler2D TextureSampler;


vec2 makeRelative(
in vec2 point,
in vec2 factor
)
{
return vec2(
point.x / factor.x,
1.0 - (point.y / factor.y)
);
}


void main()
{
Colour = texture(TextureSampler, fsUV).rgba;
// Set up UV
//
vec2 naturalUV = vec2(0, 0);
vec2 scaledUV = vec2(0, 0);

if (fsDrawMode == 0)
{
naturalUV = fsUV;
}
else if (fsDrawMode == 1)
{
vec2 modUV;
vec2 naturalVertex;

modUV =
vec2(
mod(gl_FragCoord.x - fsOrigin.x, fsSourceRect.z),
mod(gCanvasResolution.y - gl_FragCoord.y - fsOrigin.y, fsSourceRect.w)
);

naturalUV = fsSourceRect.xy + modUV.xy;
}

scaledUV =
makeRelative(
naturalUV,
gUvMapResolution
);

outColor = texture(TextureSampler, scaledUV).rgba;
}
35 changes: 9 additions & 26 deletions Rzxe/Windowing/Implementations/GlfwFx/Shaders/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ layout(location = 2) in vec4 vsSourceRect;
layout(location = 3) in vec2 vsOrigin;
layout(location = 4) in float vsDrawMode;

out vec2 fsUV;
out vec2 fsUV;
out vec4 fsSourceRect;
out vec2 fsOrigin;
out float fsDrawMode;

uniform vec2 gCanvasResolution;
uniform vec2 gUvMapResolution;


vec2 inViewportCoordSpace(
Expand Down Expand Up @@ -44,29 +46,10 @@ void main()
gl_Position.z = 1.0;
gl_Position.w = 1.0;

// Set up UV
// Pass-thru
//
vec2 actualUV = vec2(0, 0);

if (vsDrawMode == 0)
{
actualUV = vsVertexUV;
}
else if (vsDrawMode == 1)
{
vec2 modUV;

modUV =
vec2(
mod(vsVertexPosition.x - vsOrigin.x, vsSourceRect.z),
mod(vsVertexPosition.y - vsOrigin.y, vsSourceRect.w)
);

actualUV = vsSourceRect.xy + modUV.xy;
}

fsUV = makeRelative(
actualUV,
gUvMapResolution
);
fsUV = vsVertexUV;
fsSourceRect = vsSourceRect;
fsOrigin = vsOrigin;
fsDrawMode = vsDrawMode;
}

0 comments on commit 9bc74f1

Please sign in to comment.