gpu: move texture animation to gpu

This commit is contained in:
Adam
2022-03-01 22:02:44 -05:00
parent 3ad8452d41
commit 2520da4dca
4 changed files with 66 additions and 87 deletions

View File

@@ -25,7 +25,6 @@
#version 330
uniform sampler2DArray textures;
uniform vec2 textureOffsets[128];
uniform float brightness;
uniform float smoothBanding;
uniform vec4 fogColor;
@@ -49,9 +48,7 @@ void main() {
if (textureId > 0) {
int textureIdx = textureId - 1;
vec2 animatedUv = fUv + textureOffsets[textureIdx];
vec4 textureColor = texture(textures, vec3(animatedUv, float(textureIdx)));
vec4 textureColor = texture(textures, vec3(fUv, float(textureIdx)));
vec4 textureColorBrightness = pow(textureColor, vec4(brightness, brightness, brightness, 1.0f));
// textured triangles hsl is a 7 bit lightness 2-126

View File

@@ -27,6 +27,10 @@
#define TILE_SIZE 128
// smallest unit of the texture which can be moved per tick. textures are all
// 128x128px - so this is equivalent to +1px
#define TEXTURE_ANIM_UNIT (1.0f / 128.0f)
#define FOG_SCENE_EDGE_MIN TILE_SIZE
#define FOG_SCENE_EDGE_MAX (103 * TILE_SIZE)
#define FOG_CORNER_ROUNDING 1.5
@@ -52,6 +56,8 @@ uniform int useFog;
uniform int fogDepth;
uniform int drawDistance;
uniform mat4 projectionMatrix;
uniform vec2 textureAnimations[128];
uniform int tick;
out vec4 Color;
noperspective centroid out float fHsl;
@@ -77,8 +83,17 @@ void main()
gl_Position = projectionMatrix * vec4(vertex, 1.f);
Color = vec4(rgb, 1.f - a);
fHsl = float(hsl);
textureId = int(uv.x);
fUv = uv.yz;
int textureIdx = int(uv.x); // the texture id + 1
vec2 textureUv = uv.yz;
vec2 textureAnim = vec2(0);
if (textureIdx > 0) {
textureAnim = textureAnimations[textureIdx - 1];
}
textureId = textureIdx;
fUv = textureUv + tick * textureAnim * TEXTURE_ANIM_UNIT;
int fogWest = max(FOG_SCENE_EDGE_MIN, cameraX - drawDistance);
int fogEast = min(FOG_SCENE_EDGE_MAX, cameraX + drawDistance - TILE_SIZE);