]> git.nega.tv - josh/narcissus/commitdiff
Tidy text shader
authorJoshua Simmons <josh@nega.tv>
Sat, 11 Mar 2023 08:55:36 +0000 (09:55 +0100)
committerJoshua Simmons <josh@nega.tv>
Sat, 11 Mar 2023 08:57:20 +0000 (09:57 +0100)
bins/narcissus/Cargo.toml
bins/narcissus/src/main.rs
bins/narcissus/src/shaders/text.frag.glsl
bins/narcissus/src/shaders/text.frag.spv
bins/narcissus/src/shaders/text.vert.glsl
bins/narcissus/src/shaders/text.vert.spv

index c17ab4cc1bb70161767939e0de5df49c86ee52f9..03e33951a1d49c2348b882dff2e1be638070458d 100644 (file)
@@ -6,9 +6,9 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+narcissus-app = { path = "../../libs/narcissus-app" }
 narcissus-core = { path = "../../libs/narcissus-core" }
 narcissus-font = { path = "../../libs/narcissus-font" }
 narcissus-maths = { path = "../../libs/narcissus-maths" }
 narcissus-image = { path = "../../libs/narcissus-image" }
-narcissus-app = { path = "../../libs/narcissus-app" }
 narcissus-gpu = { path = "../../libs/narcissus-gpu" }
\ No newline at end of file
index 3cfc546b8a8f615b77ec5c13cd7961b883f55373..cfe4e4448aa6ae92f2dda431b50219725b824828 100644 (file)
@@ -164,6 +164,8 @@ pub fn main() {
     }
 
     let mut glyph_instances = Vec::new();
+    let mut line_glyph_indices = Vec::new();
+    let mut line_kern_advances = Vec::new();
 
     let mut align_v = false;
     let mut kerning = true;
@@ -284,9 +286,6 @@ pub fn main() {
 
         glyph_instances.clear();
 
-        let mut line_glyph_indices = Vec::new();
-        let mut line_kern_advances = Vec::new();
-
         for line in 0.. {
             let (font_family, font_size_px, text) = if line & 1 == 0 {
                 (FontFamily::RobotoRegular, 14.0, line0)
index 0163eda64e5d7436231f565e77ddb93c67cbd625..f241618408ec0c649a171ac458b58cbce039289b 100644 (file)
@@ -8,6 +8,6 @@ layout(location = 1) in vec4 color;
 layout(location = 0) out vec4 outColor;
 
 void main() {
-    float coverage = texture(sampler2D(tex, texSampler), vec2(texcoord.x, texcoord.y)).r;
+    float coverage = texture(sampler2D(tex, texSampler), texcoord).r;
     outColor = color * coverage;
 }
index c54b72753fa2755e08fda86ebadd2ef387a0872d..3bb4aa05dca613a4a2ed6c6c9023c2176a6bccc0 100644 (file)
Binary files a/bins/narcissus/src/shaders/text.frag.spv and b/bins/narcissus/src/shaders/text.frag.spv differ
index 26b1e08b9e6c1f22c3fcaa892f6dc02fc80be158..dc8ce74c150e65522787031e975c754b0d946678 100644 (file)
@@ -48,6 +48,12 @@ void main() {
         vec2(cg.offset_x1, cg.offset_y1)
     };
 
+    vec2 position = positions[gl_VertexIndex];
+    vec2 halfScreenSize = vec2(screenWidth, screenHeight) / 2.0;
+    vec2 glyphPosition = vec2(gi.x, gi.y);
+    vec2 vertexPosition = (position + glyphPosition) / halfScreenSize - 1.0;
+    gl_Position = vec4(vertexPosition, 0.0, 1.0);
+
     vec2 texcoords[4] = {
         vec2(cg.x0, cg.y0),
         vec2(cg.x0, cg.y1),
@@ -55,12 +61,8 @@ void main() {
         vec2(cg.x1, cg.y1)
     };
 
-    vec2 halfScreenSize = vec2(screenWidth, screenHeight) / 2.0;
-    vec2 glyphPosition = vec2(gi.x, gi.y);
-    vec2 vertexPosition = positions[gl_VertexIndex] + glyphPosition;
-    vec2 position = vertexPosition / halfScreenSize - 1.0;
-    gl_Position = vec4(position, 0.0, 1.0);
-    outTexcoord = texcoords[gl_VertexIndex] / vec2(atlasWidth, atlasHeight);
+    vec2 texcoord = texcoords[gl_VertexIndex];
+    outTexcoord = texcoord / vec2(atlasWidth, atlasHeight);
 
     vec4 color = unpackUnorm4x8(gi.color).bgra;
     outColor = color;
index c4b15a6324e1b860c7e9c8dd73debeaa2b6b0bba..4f9060d4c25848441d0057d66c7f5b444f4a67f5 100644 (file)
Binary files a/bins/narcissus/src/shaders/text.vert.spv and b/bins/narcissus/src/shaders/text.vert.spv differ