forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to a fragment shader solution for border tile rendering
- Loading branch information
Showing
27 changed files
with
804 additions
and
1,159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,19 @@ | ||
layout (location = 0) in vec2 inVertex; | ||
#ifdef TW_TILE_TEXTURED | ||
layout (location = 1) in vec3 inVertexTexCoord; | ||
layout (location = 1) in uvec4 inVertexTexCoord; | ||
#endif | ||
|
||
uniform mat4x2 gPos; | ||
|
||
#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE) | ||
uniform vec2 gDir; | ||
uniform vec2 gOffset; | ||
#endif | ||
|
||
#if defined(TW_TILE_BORDER) | ||
uniform int gJumpIndex; | ||
#endif | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
noperspective out vec3 TexCoord; | ||
#endif | ||
|
||
void main() | ||
{ | ||
#if defined(TW_TILE_BORDER) | ||
vec4 VertPos = vec4(inVertex, 0.0, 1.0); | ||
int XCount = gl_InstanceID - (int(gl_InstanceID/gJumpIndex) * gJumpIndex); | ||
int YCount = (int(gl_InstanceID/gJumpIndex)); | ||
VertPos.x += gOffset.x + gDir.x * float(XCount); | ||
VertPos.y += gOffset.y + gDir.y * float(YCount); | ||
|
||
gl_Position = vec4(gPos * VertPos, 0.0, 1.0); | ||
#elif defined(TW_TILE_BORDER_LINE) | ||
vec4 VertPos = vec4(inVertex.x + gOffset.x, inVertex.y + gOffset.y, 0.0, 1.0); | ||
VertPos.x += gDir.x * float(gl_InstanceID); | ||
VertPos.y += gDir.y * float(gl_InstanceID); | ||
|
||
gl_Position = vec4(gPos * VertPos, 0.0, 1.0); | ||
#else | ||
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0); | ||
#endif | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
TexCoord = inVertexTexCoord; | ||
TexCoord = vec3(inVertexTexCoord.xyz); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifdef TW_TILE_TEXTURED | ||
#ifdef TW_TILE_3D_TEXTURED | ||
uniform sampler3D gTextureSampler; | ||
#else | ||
uniform sampler2DArray gTextureSampler; | ||
#endif | ||
#endif | ||
|
||
uniform vec4 gVertColor; | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
noperspective in vec3 TexCoord; | ||
#endif | ||
|
||
out vec4 FragClr; | ||
|
||
void main() | ||
{ | ||
#ifdef TW_TILE_TEXTURED | ||
vec3 realTexCoords = vec3(fract(TexCoord.xy), TexCoord.z); | ||
vec2 dx = dFdx(TexCoord.xy); | ||
vec2 dy = dFdy(TexCoord.xy); | ||
vec4 tex = textureGrad(gTextureSampler, realTexCoords, dx, dy); | ||
FragClr = tex * gVertColor; | ||
#else | ||
FragClr = gVertColor; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
layout (location = 0) in vec2 inVertex; | ||
#ifdef TW_TILE_TEXTURED | ||
layout (location = 1) in uvec4 inVertexTexCoord; | ||
#endif | ||
|
||
uniform mat4x2 gPos; | ||
|
||
uniform vec2 gOffset; | ||
uniform vec2 gScale; | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
noperspective out vec3 TexCoord; | ||
#endif | ||
|
||
void main() | ||
{ | ||
// scale then position vertex | ||
vec2 VertexPos = (inVertex * gScale) + gOffset; | ||
gl_Position = vec4(gPos * vec4(VertexPos, 0.0, 1.0), 0.0, 1.0); | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
// scale the texture coordinates too | ||
vec2 TexScale = gScale; | ||
if (float(inVertexTexCoord.w) > 0.0) | ||
TexScale = gScale.yx; | ||
TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z)); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
layout(binding = 0) uniform sampler2DArray gTextureSampler; | ||
#endif | ||
|
||
layout(push_constant) uniform SVertexColorBO { | ||
layout(offset = 64) uniform vec4 gVertColor; | ||
} gColorBO; | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
layout (location = 0) noperspective in vec3 TexCoord; | ||
#endif | ||
|
||
layout (location = 0) out vec4 FragClr; | ||
void main() | ||
{ | ||
#ifdef TW_TILE_TEXTURED | ||
vec3 realTexCoords = vec3(fract(TexCoord.xy), TexCoord.z); | ||
vec2 dx = dFdx(TexCoord.xy); | ||
vec2 dy = dFdy(TexCoord.xy); | ||
vec4 tex = textureGrad(gTextureSampler, realTexCoords, dx, dy); | ||
FragClr = tex * gColorBO.gVertColor; | ||
#else | ||
FragClr = gColorBO.gVertColor; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
layout (location = 0) in vec2 inVertex; | ||
#ifdef TW_TILE_TEXTURED | ||
layout (location = 1) in uvec4 inVertexTexCoord; | ||
#endif | ||
|
||
layout(push_constant) uniform SPosBO { | ||
layout(offset = 0) uniform mat4x2 gPos; | ||
|
||
layout(offset = 32) uniform vec2 gOffset; | ||
layout(offset = 40) uniform vec2 gScale; | ||
} gPosBO; | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
layout (location = 0) noperspective out vec3 TexCoord; | ||
#endif | ||
|
||
void main() | ||
{ | ||
// scale then position vertex | ||
vec2 VertexPos = (inVertex * gPosBO.gScale) + gPosBO.gOffset; | ||
gl_Position = vec4(gPosBO.gPos * vec4(VertexPos, 0.0, 1.0), 0.0, 1.0); | ||
|
||
#ifdef TW_TILE_TEXTURED | ||
// scale the texture coordinates too | ||
vec2 TexScale = gPosBO.gScale; | ||
if (inVertexTexCoord.w > 0) | ||
TexScale = gPosBO.gScale.yx; | ||
TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z)); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.