changeset 1382:ec9f19151d44

sync to notebook in bedroom
author sam <sam@basx.dev>
date Sat, 14 Dec 2024 13:51:28 +0700
parents c8d1b87cf6c8
children d17ec8048f93
files semicongine/rendering/shaders.nim semicongine/text.nim tests/test_text.nim
diffstat 3 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/rendering/shaders.nim	Thu Dec 12 23:54:49 2024 +0700
+++ b/semicongine/rendering/shaders.nim	Sat Dec 14 13:51:28 2024 +0700
@@ -492,6 +492,7 @@
     if l.Valid:
       layouts.add l
 
+  # TODO: only add pushConstants if shader actually uses them
   let pushConstant = VkPushConstantRange(
     stageFlags: VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS),
     offset: 0,
--- a/semicongine/text.nim	Thu Dec 12 23:54:49 2024 +0700
+++ b/semicongine/text.nim	Sat Dec 14 13:51:28 2024 +0700
@@ -98,13 +98,14 @@
 const int[6] indices = int[](0, 1, 2, 2, 3, 0);
 const int[4] i_x = int[](0, 0, 2, 2);
 const int[4] i_y = int[](1, 3, 3, 1);
-const vec2[4] pp = vec2[](vec2(-0.1, -0.1), vec2(-0.1, 0.1), vec2(0.1, 0.1), vec2(0.1, -0.1));
+// const float epsilon = 0.000000000000001;
+const float epsilon = 0.01;
 
 void main() {
   int vertexI = indices[gl_VertexIndex];
   vec3 pos = vec3(glyphData.pos[glyphIndex][i_x[vertexI]], glyphData.pos[glyphIndex][i_y[vertexI]], 0);
   vec2 uv = vec2(glyphData.uv[glyphIndex][i_x[vertexI]], glyphData.uv[glyphIndex][i_y[vertexI]]);
-  gl_Position = vec4(pos * scale + position, 1.0);
+  gl_Position = vec4(pos * scale + position, 1.0) + vec4(0, 0, 0, gl_VertexIndex * epsilon);
   fragmentUv = uv;
   fragmentColor = color;
 }  """
@@ -112,10 +113,12 @@
       """void main() {
     float v = texture(fontAtlas, fragmentUv).r;
     // CARFULL: This can lead to rough edges at times
-    if(v == 0) {
-      discard;
-    }
-    outColor = vec4(fragmentColor.rgb, fragmentColor.a * v);
+    // if(v == 0) {
+      // discard;
+    // }
+    // outColor = vec4(fragmentColor.rgb, fragmentColor.a * v);
+    // outColor = fragmentColor;
+    outColor = vec4(1, 1, 1, v);
 }"""
 
 proc `=copy`(dest: var FontObj, source: FontObj) {.error.}
--- a/tests/test_text.nim	Thu Dec 12 23:54:49 2024 +0700
+++ b/tests/test_text.nim	Sat Dec 14 13:51:28 2024 +0700
@@ -24,11 +24,11 @@
     createPipeline[GlyphShader[N_GLYPHS]](renderPass = vulkan.swapchain.renderPass)
   var (ds, glyphtable) = glyphDescriptorSet(font, N_GLYPHS)
   var glyphs = Glyphs(
-    position: asGPUArray([vec3(), vec3()], VertexBufferMapped),
+    position: asGPUArray([vec3(0, 0, 0), vec3(0, 0, 0)], VertexBufferMapped),
     scale: asGPUArray([1'f32, 1'f32], VertexBufferMapped),
     color: asGPUArray([vec4(1, 1, 1, 1), vec4(1, 1, 1, 1)], VertexBufferMapped),
     glyphIndex:
-      asGPUArray([glyphtable[Rune('Q')], glyphtable[Rune('H')]], VertexBufferMapped),
+      asGPUArray([glyphtable[Rune('A')], glyphtable[Rune('B')]], VertexBufferMapped),
   )
 
   assignBuffers(renderdata, glyphs)
@@ -49,7 +49,14 @@
         vec4(0, 0, 0, 0),
       ):
         withPipeline(commandbuffer, pipeline):
-          render(commandbuffer, pipeline, EMPTY(), glyphs, fixedVertexCount = 6)
+          render(
+            commandbuffer,
+            pipeline,
+            EMPTY(),
+            glyphs,
+            fixedVertexCount = 6,
+            fixedInstanceCount = 2,
+          )
 
         # cleanup
   checkVkResult vkDeviceWaitIdle(vulkan.device)