summaryrefslogtreecommitdiff
path: root/source/shaders
diff options
context:
space:
mode:
authortalha <talha@talhaamir.xyz>2024-06-30 22:31:36 +0500
committertalha <talha@talhaamir.xyz>2024-06-30 22:31:36 +0500
commit5ebf4c228b9d26c2b1b32073487413eea6a4c4f2 (patch)
tree0d6a6566f180072954fb3d458a9f552bfbeabeb5 /source/shaders
parent8824908b696278f34891d95c15e519710ea0d18d (diff)
Super simple version of optimized text rendering done
Diffstat (limited to 'source/shaders')
-rw-r--r--source/shaders/ui_text_shader.fs.glsl10
-rw-r--r--source/shaders/ui_text_shader.vs.glsl13
2 files changed, 15 insertions, 8 deletions
diff --git a/source/shaders/ui_text_shader.fs.glsl b/source/shaders/ui_text_shader.fs.glsl
index d8bdcfb..bca9f7a 100644
--- a/source/shaders/ui_text_shader.fs.glsl
+++ b/source/shaders/ui_text_shader.fs.glsl
@@ -1,12 +1,16 @@
#version 330 core
in vec2 TexCoords;
-uniform sampler2D Texture;
+flat in int Index;
+uniform sampler2DArray TextureAtlas;
+uniform int TextureMap[32];
uniform vec3 TextColor;
out vec4 FragColor;
void main() {
- vec4 sampled = vec4(1.0, 1.0, 1.0, texture(Texture, TexCoords));
- FragColor = sampled * vec4(TextColor, 1.0);
+ int TextureId = TextureMap[Index];
+ vec3 TextureIndexCoords = vec3(TexCoords.xy, TextureId);
+ vec4 sampled = vec4(1.0, 1.0, 1.0, texture(TextureAtlas, TextureIndexCoords).r);
+ FragColor = sampled * vec4(TextColor, 1);
};
diff --git a/source/shaders/ui_text_shader.vs.glsl b/source/shaders/ui_text_shader.vs.glsl
index ecaefa4..363833e 100644
--- a/source/shaders/ui_text_shader.vs.glsl
+++ b/source/shaders/ui_text_shader.vs.glsl
@@ -1,12 +1,15 @@
#version 330 core
-layout(location=0) in vec3 aPos;
-layout(location=1) in vec2 aTex;
+layout(location=0) in vec2 aPos;
uniform mat4 Projection;
-
+uniform mat4 LetterTransforms[32];
out vec2 TexCoords;
+flat out int Index;
void main() {
- gl_Position = Projection * vec4(aPos, 1.0);
- TexCoords = aTex;
+ gl_Position = Projection * LetterTransforms[gl_InstanceID] * vec4(aPos, 0.0, 1.0);
+ vec2 tex = aPos;
+ TexCoords = tex;
+ TexCoords.y = 1.0 - TexCoords.y;
+ Index = gl_InstanceID;
}