diff --git a/assets/Lato-Regular.ttf b/assets/Lato-Regular.ttf new file mode 100644 index 0000000..bb2e887 Binary files /dev/null and b/assets/Lato-Regular.ttf differ diff --git a/assets/gui.frag.spv b/assets/gui.frag.spv index fb06257..4c7e572 100644 Binary files a/assets/gui.frag.spv and b/assets/gui.frag.spv differ diff --git a/assets/gui.vert.spv b/assets/gui.vert.spv index 3955c64..45ce2e3 100644 Binary files a/assets/gui.vert.spv and b/assets/gui.vert.spv differ diff --git a/assets/msdf-atlas.bmp b/assets/msdf-atlas.bmp new file mode 100644 index 0000000..27ce890 Binary files /dev/null and b/assets/msdf-atlas.bmp differ diff --git a/assets/msdf-atlas.png b/assets/msdf-atlas.png new file mode 100644 index 0000000..e988939 Binary files /dev/null and b/assets/msdf-atlas.png differ diff --git a/assets/msdf-atlas.rgba b/assets/msdf-atlas.rgba new file mode 100644 index 0000000..4dca257 Binary files /dev/null and b/assets/msdf-atlas.rgba differ diff --git a/assets/msdf.csv b/assets/msdf.csv new file mode 100644 index 0000000..08e10e8 --- /dev/null +++ b/assets/msdf.csv @@ -0,0 +1,95 @@ +32,0.59999999999999998,0,0,0,0,0,0,0,0 +33,0.59999999999999998,0.19230769230769232,-0.046153846153846149,0.40769230769230769,0.78461538461538449,19.5,151.5,26.5,178.5 +34,0.59999999999999998,0.10000000000000001,0.38461538461538458,0.5,0.78461538461538449,0.5,2.5,13.5,15.5 +35,0.59999999999999998,-0.0076923076923077257,-0.046153846153846149,0.60769230769230764,0.78461538461538449,195.5,188.5,215.5,215.5 +36,0.59999999999999998,0.038461538461538408,-0.20000000000000001,0.56153846153846143,0.90769230769230758,0.5,179.5,17.5,215.5 +37,0.59999999999999998,-0.023076923076923134,-0.046153846153846149,0.62307692307692286,0.78461538461538449,44.5,151.5,65.5,178.5 +38,0.59999999999999998,-0.018461538461538505,-0.046153846153846149,0.65846153846153832,0.78461538461538449,105.5,151.5,127.5,178.5 +39,0.59999999999999998,0.2076923076923077,0.38461538461538458,0.39230769230769225,0.78461538461538449,31.5,2.5,37.5,15.5 +40,0.59999999999999998,0.15038461538461537,-0.16923076923076924,0.51961538461538459,0.87692307692307681,18.5,181.5,30.5,215.5 +41,0.59999999999999998,0.080384615384615388,-0.16923076923076924,0.44961538461538458,0.87692307692307681,71.5,181.5,83.5,215.5 +42,0.59999999999999998,-0.0076923076923077465,0.046153846153846149,0.60769230769230764,0.66153846153846141,143.5,17.5,163.5,37.5 +43,0.59999999999999998,0.023076923076923054,0.046153846153846149,0.57692307692307676,0.59999999999999987,164.5,19.5,182.5,37.5 +44,0.59999999999999998,0.16842307692307693,-0.20000000000000001,0.41457692307692307,0.19999999999999998,206.5,99.5,214.5,112.5 +45,0.59999999999999998,0.10000000000000001,0.23076923076923078,0.5,0.41538461538461535,201.5,31.5,214.5,37.5 +46,0.59999999999999998,0.17692307692307693,-0.046153846153846149,0.42307692307692307,0.19999999999999996,201.5,22.5,209.5,30.5 +47,0.59999999999999998,0.038461538461538457,-0.16923076923076924,0.56153846153846154,0.87692307692307681,84.5,181.5,101.5,215.5 +48,0.59999999999999998,0.038461538461538471,-0.046153846153846149,0.56153846153846154,0.78461538461538449,0.5,122.5,17.5,149.5 +49,0.59999999999999998,0.053461538461538456,-0.046153846153846149,0.57653846153846156,0.78461538461538449,18.5,122.5,35.5,149.5 +50,0.59999999999999998,0.039961538461538437,-0.046153846153846149,0.5630384615384616,0.78461538461538449,53.5,122.5,70.5,149.5 +51,0.59999999999999998,0.028461538461538469,-0.046153846153846149,0.55153846153846153,0.78461538461538449,71.5,122.5,88.5,149.5 +52,0.59999999999999998,0.033846153846153818,-0.046153846153846149,0.52615384615384608,0.78461538461538449,106.5,122.5,122.5,149.5 +53,0.59999999999999998,0.033461538461538466,-0.046153846153846149,0.55653846153846154,0.78461538461538449,123.5,122.5,140.5,149.5 +54,0.59999999999999998,0.023076923076923016,-0.046153846153846149,0.57692307692307676,0.78461538461538449,141.5,122.5,159.5,149.5 +55,0.59999999999999998,0.037076923076923042,-0.046153846153846149,0.59092307692307677,0.78461538461538449,160.5,122.5,178.5,149.5 +56,0.59999999999999998,0.02307692307692303,-0.046153846153846149,0.57692307692307676,0.78461538461538449,135.5,94.5,153.5,121.5 +57,0.59999999999999998,0.023076923076923016,-0.046153846153846149,0.57692307692307676,0.78461538461538449,33.5,38.5,51.5,65.5 +58,0.59999999999999998,0.17692307692307693,-0.046153846153846149,0.42307692307692307,0.59999999999999987,116.5,44.5,124.5,65.5 +59,0.59999999999999998,0.17192307692307693,-0.20000000000000001,0.41807692307692307,0.59999999999999998,71.5,39.5,79.5,65.5 +60,0.59999999999999998,0.053846153846153842,0.015384615384615384,0.5461538461538461,0.63076923076923075,109.5,17.5,125.5,37.5 +61,0.59999999999999998,0.053846153846153842,0.13846153846153847,0.5461538461538461,0.53846153846153844,14.5,2.5,30.5,15.5 +62,0.59999999999999998,0.053846153846153842,0.015384615384615384,0.5461538461538461,0.63076923076923075,126.5,17.5,142.5,37.5 +63,0.59999999999999998,0.092115384615384613,-0.046153846153846149,0.52288461538461539,0.78461538461538449,0.5,38.5,14.5,65.5 +64,0.59999999999999998,0.010192307692307648,-0.23076923076923075,0.59480769230769226,0.78461538461538449,157.5,182.5,176.5,215.5 +65,0.59999999999999998,0.0076923076923076364,-0.046153846153846149,0.59230769230769231,0.78461538461538449,196.5,122.5,215.5,149.5 +66,0.59999999999999998,0.049961538461538467,-0.046153846153846149,0.57303846153846161,0.78461538461538449,156.5,66.5,173.5,93.5 +67,0.59999999999999998,0.060846153846153841,-0.046153846153846149,0.55315384615384611,0.78461538461538449,139.5,66.5,155.5,93.5 +68,0.59999999999999998,0.055846153846153823,-0.046153846153846149,0.5481538461538461,0.78461538461538449,122.5,66.5,138.5,93.5 +69,0.59999999999999998,0.06384615384615383,-0.046153846153846149,0.55615384615384611,0.78461538461538449,105.5,66.5,121.5,93.5 +70,0.59999999999999998,0.063846153846153844,-0.046153846153846149,0.55615384615384611,0.78461538461538449,88.5,66.5,104.5,93.5 +71,0.59999999999999998,0.056846153846153838,-0.046153846153846149,0.5491538461538461,0.78461538461538449,71.5,66.5,87.5,93.5 +72,0.59999999999999998,0.053846153846153814,-0.046153846153846149,0.5461538461538461,0.78461538461538449,54.5,66.5,70.5,93.5 +73,0.59999999999999998,0.069230769230769207,-0.046153846153846149,0.53076923076923077,0.78461538461538449,200.5,151.5,215.5,178.5 +74,0.59999999999999998,0.0084615384615384596,-0.046153846153846149,0.53153846153846152,0.78461538461538449,19.5,66.5,36.5,93.5 +75,0.59999999999999998,0.049076923076923039,-0.046153846153846149,0.60292307692307678,0.78461538461538449,0.5,66.5,18.5,93.5 +76,0.59999999999999998,0.093846153846153829,-0.046153846153846149,0.58615384615384614,0.78461538461538449,194.5,66.5,210.5,93.5 +77,0.59999999999999998,0.038461538461538408,-0.046153846153846149,0.56153846153846143,0.78461538461538449,15.5,38.5,32.5,65.5 +78,0.59999999999999998,0.053846153846153828,-0.046153846153846149,0.5461538461538461,0.78461538461538449,189.5,94.5,205.5,121.5 +79,0.59999999999999998,0.053846153846153842,-0.046153846153846149,0.5461538461538461,0.78461538461538449,172.5,94.5,188.5,121.5 +80,0.59999999999999998,0.059461538461538427,-0.046153846153846149,0.58253846153846145,0.78461538461538449,154.5,94.5,171.5,121.5 +81,0.59999999999999998,0.041461538461538418,-0.23076923076923075,0.56453846153846143,0.78461538461538449,177.5,182.5,194.5,215.5 +82,0.59999999999999998,0.057461538461538425,-0.046153846153846149,0.58053846153846145,0.78461538461538449,117.5,94.5,134.5,121.5 +83,0.59999999999999998,0.038461538461538408,-0.046153846153846149,0.56153846153846143,0.78461538461538449,99.5,94.5,116.5,121.5 +84,0.59999999999999998,0.02307692307692303,-0.046153846153846149,0.57692307692307676,0.78461538461538449,80.5,94.5,98.5,121.5 +85,0.59999999999999998,0.053846153846153828,-0.046153846153846149,0.5461538461538461,0.78461538461538449,63.5,94.5,79.5,121.5 +86,0.59999999999999998,0.0076923076923076364,-0.046153846153846149,0.59230769230769231,0.78461538461538449,43.5,94.5,62.5,121.5 +87,0.59999999999999998,-0.023076923076923141,-0.046153846153846149,0.62307692307692286,0.78461538461538449,21.5,94.5,42.5,121.5 +88,0.59999999999999998,0.0076923076923076684,-0.046153846153846149,0.59230769230769231,0.78461538461538449,174.5,66.5,193.5,93.5 +89,0.59999999999999998,-0.0076923076923077257,-0.046153846153846149,0.60769230769230764,0.78461538461538449,0.5,94.5,20.5,121.5 +90,0.59999999999999998,0.053846153846153842,-0.046153846153846149,0.5461538461538461,0.78461538461538449,179.5,122.5,195.5,149.5 +91,0.59999999999999998,0.17365384615384616,-0.16923076923076924,0.48134615384615381,0.87692307692307681,102.5,181.5,112.5,215.5 +92,0.59999999999999998,0.038461538461538457,-0.16923076923076924,0.56153846153846154,0.87692307692307681,113.5,181.5,130.5,215.5 +93,0.59999999999999998,0.11865384615384617,-0.16923076923076924,0.42634615384615382,0.87692307692307681,131.5,181.5,141.5,215.5 +94,0.59999999999999998,0.038461538461538471,0.29230769230769227,0.56153846153846154,0.78461538461538449,183.5,21.5,200.5,37.5 +95,0.59999999999999998,0.02307692307692304,-0.13846153846153847,0.57692307692307676,0.015384615384615387,195.5,182.5,213.5,187.5 +96,0.59999999999999998,0.12853846153846155,0.59999999999999998,0.40546153846153848,0.84615384615384626,206.5,113.5,215.5,121.5 +97,0.59999999999999998,0.025961538461538449,-0.046153846153846149,0.54903846153846159,0.59999999999999987,18.5,16.5,35.5,37.5 +98,0.59999999999999998,0.056346153846153824,-0.046153846153846149,0.54865384615384605,0.78461538461538449,36.5,122.5,52.5,149.5 +99,0.59999999999999998,0.043961538461538448,-0.046153846153846149,0.5670384615384616,0.59999999999999987,36.5,16.5,53.5,37.5 +100,0.59999999999999998,0.051346153846153826,-0.046153846153846149,0.54365384615384604,0.78461538461538449,37.5,66.5,53.5,93.5 +101,0.59999999999999998,0.038461538461538436,-0.046153846153846149,0.56153846153846154,0.59999999999999987,74.5,16.5,91.5,37.5 +102,0.59999999999999998,0.01557692307692302,-0.046153846153846149,0.56942307692307681,0.78461538461538449,181.5,151.5,199.5,178.5 +103,0.59999999999999998,0.05134615384615384,-0.23076923076923075,0.54365384615384604,0.59999999999999998,164.5,151.5,180.5,178.5 +104,0.59999999999999998,0.054846153846153829,-0.046153846153846149,0.5471538461538461,0.78461538461538449,147.5,151.5,163.5,178.5 +105,0.59999999999999998,0.043076923076923054,-0.046153846153846149,0.59692307692307678,0.81538461538461526,0.5,150.5,18.5,178.5 +106,0.59999999999999998,0.052615384615384626,-0.23076923076923075,0.48338461538461536,0.81538461538461526,142.5,181.5,156.5,215.5 +107,0.59999999999999998,0.051076923076923027,-0.046153846153846149,0.60492307692307679,0.78461538461538449,86.5,151.5,104.5,178.5 +108,0.59999999999999998,-0.0023076923076923313,-0.046153846153846149,0.5823076923076923,0.78461538461538449,66.5,151.5,85.5,178.5 +109,0.59999999999999998,0.02307692307692304,-0.046153846153846149,0.57692307692307676,0.59999999999999987,97.5,44.5,115.5,65.5 +110,0.59999999999999998,0.054846153846153829,-0.046153846153846149,0.5471538461538461,0.59999999999999987,80.5,44.5,96.5,65.5 +111,0.59999999999999998,0.038461538461538436,-0.046153846153846149,0.56153846153846154,0.59999999999999987,0.5,16.5,17.5,37.5 +112,0.59999999999999998,0.056346153846153824,-0.23076923076923075,0.54865384615384605,0.59999999999999998,89.5,122.5,105.5,149.5 +113,0.59999999999999998,0.051346153846153826,-0.23076923076923075,0.54365384615384604,0.59999999999999998,27.5,151.5,43.5,178.5 +114,0.59999999999999998,0.074846153846153826,-0.046153846153846149,0.56715384615384612,0.59999999999999987,125.5,44.5,141.5,65.5 +115,0.59999999999999998,0.053846153846153842,-0.046153846153846149,0.5461538461538461,0.59999999999999987,92.5,16.5,108.5,37.5 +116,0.59999999999999998,0.0065769230769230557,-0.046153846153846149,0.5604230769230768,0.75384615384615383,52.5,39.5,70.5,65.5 +117,0.59999999999999998,0.053846153846153828,-0.046153846153846149,0.5461538461538461,0.59999999999999987,182.5,44.5,198.5,65.5 +118,0.59999999999999998,0.023076923076923054,-0.046153846153846149,0.57692307692307676,0.59999999999999987,163.5,44.5,181.5,65.5 +119,0.59999999999999998,-0.0076923076923077578,-0.046153846153846149,0.60769230769230764,0.59999999999999987,142.5,44.5,162.5,65.5 +120,0.59999999999999998,0.0076923076923076364,-0.046153846153846149,0.59230769230769231,0.59999999999999987,54.5,16.5,73.5,37.5 +121,0.59999999999999998,0.023076923076923054,-0.23076923076923075,0.57692307692307676,0.59999999999999998,128.5,151.5,146.5,178.5 +122,0.59999999999999998,0.053846153846153828,-0.046153846153846149,0.5461538461538461,0.59999999999999987,199.5,44.5,215.5,65.5 +123,0.59999999999999998,0.04384615384615384,-0.16923076923076924,0.53615384615384609,0.87692307692307681,54.5,181.5,70.5,215.5 +124,0.59999999999999998,0.22307692307692309,-0.16923076923076924,0.37692307692307692,0.87692307692307681,48.5,181.5,53.5,215.5 +125,0.59999999999999998,0.063846153846153844,-0.16923076923076924,0.55615384615384611,0.87692307692307681,31.5,181.5,47.5,215.5 +126,0.59999999999999998,0.038461538461538394,0.20000000000000001,0.56153846153846143,0.50769230769230766,38.5,5.5,55.5,15.5 diff --git a/assets/msdf.json b/assets/msdf.json new file mode 100644 index 0000000..0cba010 --- /dev/null +++ b/assets/msdf.json @@ -0,0 +1 @@ +{"atlas":{"type":"msdf","distanceRange":16,"distanceRangeMiddle":0,"size":128,"width":880,"height":880,"yOrigin":"top"},"metrics":{"emSize":1,"lineHeight":1.3200000000000001,"ascender":-1.02,"descender":0.29999999999999999,"underlineY":0.17999999999999999,"underlineThickness":0.050000000000000003},"glyphs":[{"unicode":32,"advance":0.59999999999999998},{"unicode":33,"advance":0.59999999999999998,"planeBounds":{"left":0.15937500000000002,"top":-0.79296875,"right":0.44062499999999999,"bottom":0.07421875},"atlasBounds":{"left":220.5,"top":264.5,"right":256.5,"bottom":375.5}},{"unicode":34,"advance":0.59999999999999998,"planeBounds":{"left":0.077343750000000003,"top":-0.79296875,"right":0.52265625000000004,"bottom":-0.36328125},"atlasBounds":{"left":225.5,"top":800.5,"right":282.5,"bottom":855.5}},{"unicode":35,"advance":0.59999999999999998,"planeBounds":{"left":-0.028124999999999987,"top":-0.79296875,"right":0.62812500000000004,"bottom":0.06640625},"atlasBounds":{"left":0.5,"top":377.5,"right":84.5,"bottom":487.5}},{"unicode":36,"advance":0.59999999999999998,"planeBounds":{"left":0.0070312499999999802,"top":-0.93359375,"right":0.59296875000000004,"bottom":0.20703125},"atlasBounds":{"left":0.5,"top":0.5,"right":75.5,"bottom":146.5}},{"unicode":37,"advance":0.59999999999999998,"planeBounds":{"left":-0.051562499999999969,"top":-0.80078125,"right":0.65156250000000004,"bottom":0.07421875},"atlasBounds":{"left":616.5,"top":147.5,"right":706.5,"bottom":259.5}},{"unicode":38,"advance":0.59999999999999998,"planeBounds":{"left":-0.039375000000000014,"top":-0.80859375,"right":0.67937500000000006,"bottom":0.07421875},"atlasBounds":{"left":78.5,"top":147.5,"right":170.5,"bottom":260.5}},{"unicode":39,"advance":0.59999999999999998,"planeBounds":{"left":0.18281250000000002,"top":-0.79296875,"right":0.41718749999999999,"bottom":-0.36328125},"atlasBounds":{"left":283.5,"top":800.5,"right":313.5,"bottom":855.5}},{"unicode":40,"advance":0.59999999999999998,"planeBounds":{"left":0.12015625000000001,"top":-0.91015625,"right":0.54984374999999996,"bottom":0.18359375},"atlasBounds":{"left":76.5,"top":0.5,"right":131.5,"bottom":140.5}},{"unicode":41,"advance":0.59999999999999998,"planeBounds":{"left":0.050156249999999993,"top":-0.91015625,"right":0.47984375000000001,"bottom":0.18359375},"atlasBounds":{"left":132.5,"top":0.5,"right":187.5,"bottom":140.5}},{"unicode":42,"advance":0.59999999999999998,"planeBounds":{"left":-0.028124999999999987,"top":-0.68359375,"right":0.62812500000000004,"bottom":-0.03515625},"atlasBounds":{"left":752.5,"top":710.5,"right":836.5,"bottom":793.5}},{"unicode":43,"advance":0.59999999999999998,"planeBounds":{"left":-0.00078125000000001338,"top":-0.62890625,"right":0.60078125000000004,"bottom":-0.02734375},"atlasBounds":{"left":0.5,"top":800.5,"right":77.5,"bottom":877.5}},{"unicode":44,"advance":0.59999999999999998,"planeBounds":{"left":0.14696875000000004,"top":-0.21484375,"right":0.43603124999999998,"bottom":0.22265625},"atlasBounds":{"left":839.5,"top":599.5,"right":876.5,"bottom":655.5}},{"unicode":45,"advance":0.59999999999999998,"planeBounds":{"left":0.077343750000000003,"top":-0.43359375,"right":0.52265625000000004,"bottom":-0.22265625},"atlasBounds":{"left":469.5,"top":800.5,"right":526.5,"bottom":827.5}},{"unicode":46,"advance":0.59999999999999998,"planeBounds":{"left":0.15546875000000002,"top":-0.21484375,"right":0.44453124999999999,"bottom":0.07421875},"atlasBounds":{"left":837.5,"top":710.5,"right":874.5,"bottom":747.5}},{"unicode":47,"advance":0.59999999999999998,"planeBounds":{"left":0.010937500000000034,"top":-0.89453125,"right":0.58906250000000004,"bottom":0.17578125},"atlasBounds":{"left":354.5,"top":0.5,"right":428.5,"bottom":137.5}},{"unicode":48,"advance":0.59999999999999998,"planeBounds":{"left":0.014843750000000029,"top":-0.80859375,"right":0.58515625000000004,"bottom":0.07421875},"atlasBounds":{"left":171.5,"top":147.5,"right":244.5,"bottom":260.5}},{"unicode":49,"advance":0.59999999999999998,"planeBounds":{"left":0.025937500000000037,"top":-0.79296875,"right":0.60406250000000006,"bottom":0.06640625},"atlasBounds":{"left":434.5,"top":488.5,"right":508.5,"bottom":598.5}},{"unicode":50,"advance":0.59999999999999998,"planeBounds":{"left":0.012437500000000034,"top":-0.80859375,"right":0.59056249999999999,"bottom":0.06640625},"atlasBounds":{"left":778.5,"top":147.5,"right":852.5,"bottom":259.5}},{"unicode":51,"advance":0.59999999999999998,"planeBounds":{"left":0.0048437500000000295,"top":-0.79296875,"right":0.57515625000000004,"bottom":0.07421875},"atlasBounds":{"left":257.5,"top":264.5,"right":330.5,"bottom":375.5}},{"unicode":52,"advance":0.59999999999999998,"planeBounds":{"left":0.0065625000000000206,"top":-0.79296875,"right":0.55343750000000003,"bottom":0.06640625},"atlasBounds":{"left":154.5,"top":599.5,"right":224.5,"bottom":709.5}},{"unicode":53,"advance":0.59999999999999998,"planeBounds":{"left":0.0098437500000000278,"top":-0.79296875,"right":0.58015625000000004,"bottom":0.07421875},"atlasBounds":{"left":402.5,"top":264.5,"right":475.5,"bottom":375.5}},{"unicode":54,"advance":0.59999999999999998,"planeBounds":{"left":-0.0007812500000000124,"top":-0.79296875,"right":0.60078125000000004,"bottom":0.07421875},"atlasBounds":{"left":476.5,"top":264.5,"right":553.5,"bottom":375.5}},{"unicode":55,"advance":0.59999999999999998,"planeBounds":{"left":0.017124999999999987,"top":-0.79296875,"right":0.61087500000000006,"bottom":0.06640625},"atlasBounds":{"left":225.5,"top":599.5,"right":301.5,"bottom":709.5}},{"unicode":56,"advance":0.59999999999999998,"planeBounds":{"left":0.0031249999999999859,"top":-0.80859375,"right":0.59687500000000004,"bottom":0.07421875},"atlasBounds":{"left":245.5,"top":147.5,"right":321.5,"bottom":260.5}},{"unicode":57,"advance":0.59999999999999998,"planeBounds":{"left":-0.0007812500000000124,"top":-0.80859375,"right":0.60078125000000004,"bottom":0.06640625},"atlasBounds":{"left":0.5,"top":264.5,"right":77.5,"bottom":376.5}},{"unicode":58,"advance":0.59999999999999998,"planeBounds":{"left":0.15156250000000002,"top":-0.62890625,"right":0.44843749999999999,"bottom":0.07421875},"atlasBounds":{"left":833.5,"top":35.5,"right":871.5,"bottom":125.5}},{"unicode":59,"advance":0.59999999999999998,"planeBounds":{"left":0.13875000000000001,"top":-0.62890625,"right":0.45124999999999998,"bottom":0.22265625},"atlasBounds":{"left":834.5,"top":264.5,"right":874.5,"bottom":373.5}},{"unicode":60,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.66015625,"right":0.58125000000000004,"bottom":0.00390625},"atlasBounds":{"left":679.5,"top":710.5,"right":751.5,"bottom":795.5}},{"unicode":61,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.55859375,"right":0.58125000000000004,"bottom":-0.10546875},"atlasBounds":{"left":152.5,"top":800.5,"right":224.5,"bottom":858.5}},{"unicode":62,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.66015625,"right":0.58125000000000004,"bottom":0.00390625},"atlasBounds":{"left":606.5,"top":710.5,"right":678.5,"bottom":795.5}},{"unicode":63,"advance":0.59999999999999998,"planeBounds":{"left":0.065312499999999996,"top":-0.79296875,"right":0.5496875,"bottom":0.07421875},"atlasBounds":{"left":625.5,"top":264.5,"right":687.5,"bottom":375.5}},{"unicode":64,"advance":0.59999999999999998,"planeBounds":{"left":-0.017812499999999992,"top":-0.80859375,"right":0.62281249999999999,"bottom":0.24609375},"atlasBounds":{"left":675.5,"top":0.5,"right":757.5,"bottom":135.5}},{"unicode":65,"advance":0.59999999999999998,"planeBounds":{"left":-0.012500000000000001,"top":-0.79296875,"right":0.61250000000000004,"bottom":0.06640625},"atlasBounds":{"left":0.5,"top":599.5,"right":80.5,"bottom":709.5}},{"unicode":66,"advance":0.59999999999999998,"planeBounds":{"left":0.03025000000000003,"top":-0.79296875,"right":0.59275,"bottom":0.06640625},"atlasBounds":{"left":81.5,"top":599.5,"right":153.5,"bottom":709.5}},{"unicode":67,"advance":0.59999999999999998,"planeBounds":{"left":0.025750000000000026,"top":-0.80859375,"right":0.58825000000000005,"bottom":0.07421875},"atlasBounds":{"left":322.5,"top":147.5,"right":394.5,"bottom":260.5}},{"unicode":68,"advance":0.59999999999999998,"planeBounds":{"left":0.028562500000000022,"top":-0.79296875,"right":0.57543750000000005,"bottom":0.06640625},"atlasBounds":{"left":653.5,"top":488.5,"right":723.5,"bottom":598.5}},{"unicode":69,"advance":0.59999999999999998,"planeBounds":{"left":0.036562500000000026,"top":-0.79296875,"right":0.58343750000000005,"bottom":0.06640625},"atlasBounds":{"left":582.5,"top":488.5,"right":652.5,"bottom":598.5}},{"unicode":70,"advance":0.59999999999999998,"planeBounds":{"left":0.028750000000000026,"top":-0.79296875,"right":0.59125000000000005,"bottom":0.06640625},"atlasBounds":{"left":509.5,"top":488.5,"right":581.5,"bottom":598.5}},{"unicode":71,"advance":0.59999999999999998,"planeBounds":{"left":0.021750000000000026,"top":-0.80859375,"right":0.58425000000000005,"bottom":0.07421875},"atlasBounds":{"left":395.5,"top":147.5,"right":467.5,"bottom":260.5}},{"unicode":72,"advance":0.59999999999999998,"planeBounds":{"left":0.03046875000000002,"top":-0.79296875,"right":0.56953125000000004,"bottom":0.06640625},"atlasBounds":{"left":364.5,"top":488.5,"right":433.5,"bottom":598.5}},{"unicode":73,"advance":0.59999999999999998,"planeBounds":{"left":0.04218750000000001,"top":-0.79296875,"right":0.55781250000000004,"bottom":0.06640625},"atlasBounds":{"left":297.5,"top":488.5,"right":363.5,"bottom":598.5}},{"unicode":74,"advance":0.59999999999999998,"planeBounds":{"left":-0.019062499999999965,"top":-0.79296875,"right":0.55906250000000002,"bottom":0.07421875},"atlasBounds":{"left":688.5,"top":264.5,"right":762.5,"bottom":375.5}},{"unicode":75,"advance":0.59999999999999998,"planeBounds":{"left":0.029124999999999988,"top":-0.79296875,"right":0.62287500000000007,"bottom":0.06640625},"atlasBounds":{"left":147.5,"top":488.5,"right":223.5,"bottom":598.5}},{"unicode":76,"advance":0.59999999999999998,"planeBounds":{"left":0.066562500000000024,"top":-0.79296875,"right":0.61343749999999997,"bottom":0.06640625},"atlasBounds":{"left":76.5,"top":488.5,"right":146.5,"bottom":598.5}},{"unicode":77,"advance":0.59999999999999998,"planeBounds":{"left":0.0070312499999999802,"top":-0.79296875,"right":0.59296875000000004,"bottom":0.06640625},"atlasBounds":{"left":0.5,"top":488.5,"right":75.5,"bottom":598.5}},{"unicode":78,"advance":0.59999999999999998,"planeBounds":{"left":0.026562500000000024,"top":-0.79296875,"right":0.57343750000000004,"bottom":0.06640625},"atlasBounds":{"left":800.5,"top":377.5,"right":870.5,"bottom":487.5}},{"unicode":79,"advance":0.59999999999999998,"planeBounds":{"left":0.02265625000000002,"top":-0.80859375,"right":0.57734375000000004,"bottom":0.07421875},"atlasBounds":{"left":468.5,"top":147.5,"right":539.5,"bottom":260.5}},{"unicode":80,"advance":0.59999999999999998,"planeBounds":{"left":0.028031249999999983,"top":-0.79296875,"right":0.61396875000000006,"bottom":0.06640625},"atlasBounds":{"left":644.5,"top":377.5,"right":719.5,"bottom":487.5}},{"unicode":81,"advance":0.59999999999999998,"planeBounds":{"left":0.013937500000000031,"top":-0.80859375,"right":0.59206250000000005,"bottom":0.24609375},"atlasBounds":{"left":758.5,"top":0.5,"right":832.5,"bottom":135.5}},{"unicode":82,"advance":0.59999999999999998,"planeBounds":{"left":0.029937499999999978,"top":-0.79296875,"right":0.60806250000000006,"bottom":0.06640625},"atlasBounds":{"left":491.5,"top":377.5,"right":565.5,"bottom":487.5}},{"unicode":83,"advance":0.59999999999999998,"planeBounds":{"left":0.0070312499999999802,"top":-0.80859375,"right":0.59296875000000004,"bottom":0.07421875},"atlasBounds":{"left":540.5,"top":147.5,"right":615.5,"bottom":260.5}},{"unicode":84,"advance":0.59999999999999998,"planeBounds":{"left":-0.0085937500000000042,"top":-0.79296875,"right":0.60859375000000004,"bottom":0.06640625},"atlasBounds":{"left":340.5,"top":377.5,"right":419.5,"bottom":487.5}},{"unicode":85,"advance":0.59999999999999998,"planeBounds":{"left":0.026562500000000024,"top":-0.79296875,"right":0.57343750000000004,"bottom":0.07421875},"atlasBounds":{"left":763.5,"top":264.5,"right":833.5,"bottom":375.5}},{"unicode":86,"advance":0.59999999999999998,"planeBounds":{"left":-0.012500000000000001,"top":-0.79296875,"right":0.61250000000000004,"bottom":0.06640625},"atlasBounds":{"left":174.5,"top":377.5,"right":254.5,"bottom":487.5}},{"unicode":87,"advance":0.59999999999999998,"planeBounds":{"left":-0.043749999999999969,"top":-0.79296875,"right":0.64375000000000004,"bottom":0.06640625},"atlasBounds":{"left":85.5,"top":377.5,"right":173.5,"bottom":487.5}},{"unicode":88,"advance":0.59999999999999998,"planeBounds":{"left":-0.024218749999999994,"top":-0.79296875,"right":0.62421875000000004,"bottom":0.06640625},"atlasBounds":{"left":386.5,"top":599.5,"right":469.5,"bottom":709.5}},{"unicode":89,"advance":0.59999999999999998,"planeBounds":{"left":-0.028124999999999987,"top":-0.79296875,"right":0.62812500000000004,"bottom":0.06640625},"atlasBounds":{"left":255.5,"top":377.5,"right":339.5,"bottom":487.5}},{"unicode":90,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.79296875,"right":0.58125000000000004,"bottom":0.06640625},"atlasBounds":{"left":224.5,"top":488.5,"right":296.5,"bottom":598.5}},{"unicode":91,"advance":0.59999999999999998,"planeBounds":{"left":0.14000000000000001,"top":-0.89453125,"right":0.51500000000000001,"bottom":0.17578125},"atlasBounds":{"left":429.5,"top":0.5,"right":477.5,"bottom":137.5}},{"unicode":92,"advance":0.59999999999999998,"planeBounds":{"left":0.010937500000000034,"top":-0.89453125,"right":0.58906250000000004,"bottom":0.17578125},"atlasBounds":{"left":478.5,"top":0.5,"right":552.5,"bottom":137.5}},{"unicode":93,"advance":0.59999999999999998,"planeBounds":{"left":0.085000000000000006,"top":-0.89453125,"right":0.46000000000000002,"bottom":0.17578125},"atlasBounds":{"left":553.5,"top":0.5,"right":601.5,"bottom":137.5}},{"unicode":94,"advance":0.59999999999999998,"planeBounds":{"left":0.014843750000000029,"top":-0.79296875,"right":0.58515625000000004,"bottom":-0.27734375},"atlasBounds":{"left":78.5,"top":800.5,"right":151.5,"bottom":866.5}},{"unicode":95,"advance":0.59999999999999998,"planeBounds":{"left":-0.0046875000000000094,"top":-0.04296875,"right":0.60468750000000004,"bottom":0.16796875},"atlasBounds":{"left":390.5,"top":800.5,"right":468.5,"bottom":827.5}},{"unicode":96,"advance":0.59999999999999998,"planeBounds":{"left":0.099031250000000015,"top":-0.84765625,"right":0.43496875000000002,"bottom":-0.58203125},"atlasBounds":{"left":833.5,"top":0.5,"right":876.5,"bottom":34.5}},{"unicode":97,"advance":0.59999999999999998,"planeBounds":{"left":0.0023437500000000294,"top":-0.62890625,"right":0.57265624999999998,"bottom":0.07421875},"atlasBounds":{"left":548.5,"top":599.5,"right":621.5,"bottom":689.5}},{"unicode":98,"advance":0.59999999999999998,"planeBounds":{"left":0.029062500000000022,"top":-0.79296875,"right":0.57593749999999999,"bottom":0.07421875},"atlasBounds":{"left":331.5,"top":264.5,"right":401.5,"bottom":375.5}},{"unicode":99,"advance":0.59999999999999998,"planeBounds":{"left":0.024250000000000028,"top":-0.62890625,"right":0.58674999999999999,"bottom":0.07421875},"atlasBounds":{"left":622.5,"top":599.5,"right":694.5,"bottom":689.5}},{"unicode":100,"advance":0.59999999999999998,"planeBounds":{"left":0.024062500000000021,"top":-0.79296875,"right":0.57093749999999999,"bottom":0.07421875},"atlasBounds":{"left":554.5,"top":264.5,"right":624.5,"bottom":375.5}},{"unicode":101,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.62890625,"right":0.58125000000000004,"bottom":0.07421875},"atlasBounds":{"left":695.5,"top":599.5,"right":767.5,"bottom":689.5}},{"unicode":102,"advance":0.59999999999999998,"planeBounds":{"left":-0.0082812500000000108,"top":-0.79296875,"right":0.59328124999999998,"bottom":0.06640625},"atlasBounds":{"left":566.5,"top":377.5,"right":643.5,"bottom":487.5}},{"unicode":103,"advance":0.59999999999999998,"planeBounds":{"left":0.024062500000000021,"top":-0.62890625,"right":0.57093749999999999,"bottom":0.24609375},"atlasBounds":{"left":707.5,"top":147.5,"right":777.5,"bottom":259.5}},{"unicode":104,"advance":0.59999999999999998,"planeBounds":{"left":0.027562500000000021,"top":-0.79296875,"right":0.57443750000000005,"bottom":0.06640625},"atlasBounds":{"left":420.5,"top":377.5,"right":490.5,"bottom":487.5}},{"unicode":105,"advance":0.59999999999999998,"planeBounds":{"left":0.019218749999999986,"top":-0.83984375,"right":0.62078125000000006,"bottom":0.06640625},"atlasBounds":{"left":0.5,"top":147.5,"right":77.5,"bottom":263.5}},{"unicode":106,"advance":0.59999999999999998,"planeBounds":{"left":0.021906249999999995,"top":-0.83984375,"right":0.51409375000000002,"bottom":0.24609375},"atlasBounds":{"left":188.5,"top":0.5,"right":251.5,"bottom":139.5}},{"unicode":107,"advance":0.59999999999999998,"planeBounds":{"left":0.031124999999999983,"top":-0.79296875,"right":0.62487499999999996,"bottom":0.06640625},"atlasBounds":{"left":724.5,"top":488.5,"right":800.5,"bottom":598.5}},{"unicode":108,"advance":0.59999999999999998,"planeBounds":{"left":-0.034218749999999992,"top":-0.79296875,"right":0.61421875000000004,"bottom":0.06640625},"atlasBounds":{"left":302.5,"top":599.5,"right":385.5,"bottom":709.5}},{"unicode":109,"advance":0.59999999999999998,"planeBounds":{"left":-0.0046875000000000094,"top":-0.62890625,"right":0.60468750000000004,"bottom":0.06640625},"atlasBounds":{"left":801.5,"top":488.5,"right":879.5,"bottom":577.5}},{"unicode":110,"advance":0.59999999999999998,"planeBounds":{"left":0.027562500000000021,"top":-0.62890625,"right":0.57443750000000005,"bottom":0.06640625},"atlasBounds":{"left":73.5,"top":710.5,"right":143.5,"bottom":799.5}},{"unicode":111,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.62109375,"right":0.58125000000000004,"bottom":0.07421875},"atlasBounds":{"left":0.5,"top":710.5,"right":72.5,"bottom":799.5}},{"unicode":112,"advance":0.59999999999999998,"planeBounds":{"left":0.029062500000000022,"top":-0.62890625,"right":0.57593749999999999,"bottom":0.24609375},"atlasBounds":{"left":78.5,"top":264.5,"right":148.5,"bottom":376.5}},{"unicode":113,"advance":0.59999999999999998,"planeBounds":{"left":0.024062500000000021,"top":-0.62890625,"right":0.57093749999999999,"bottom":0.24609375},"atlasBounds":{"left":149.5,"top":264.5,"right":219.5,"bottom":376.5}},{"unicode":114,"advance":0.59999999999999998,"planeBounds":{"left":0.047562500000000021,"top":-0.62890625,"right":0.59443750000000006,"bottom":0.06640625},"atlasBounds":{"left":768.5,"top":599.5,"right":838.5,"bottom":688.5}},{"unicode":115,"advance":0.59999999999999998,"planeBounds":{"left":0.018750000000000024,"top":-0.62109375,"right":0.58125000000000004,"bottom":0.07421875},"atlasBounds":{"left":144.5,"top":710.5,"right":216.5,"bottom":799.5}},{"unicode":116,"advance":0.59999999999999998,"planeBounds":{"left":-0.017281250000000012,"top":-0.76953125,"right":0.58428124999999997,"bottom":0.06640625},"atlasBounds":{"left":470.5,"top":599.5,"right":547.5,"bottom":706.5}},{"unicode":117,"advance":0.59999999999999998,"planeBounds":{"left":0.026562500000000024,"top":-0.61328125,"right":0.57343750000000004,"bottom":0.07421875},"atlasBounds":{"left":217.5,"top":710.5,"right":287.5,"bottom":798.5}},{"unicode":118,"advance":0.59999999999999998,"planeBounds":{"left":-0.0085937500000000042,"top":-0.61328125,"right":0.60859375000000004,"bottom":0.06640625},"atlasBounds":{"left":288.5,"top":710.5,"right":367.5,"bottom":797.5}},{"unicode":119,"advance":0.59999999999999998,"planeBounds":{"left":-0.032031249999999983,"top":-0.61328125,"right":0.63203125000000004,"bottom":0.06640625},"atlasBounds":{"left":368.5,"top":710.5,"right":453.5,"bottom":797.5}},{"unicode":120,"advance":0.59999999999999998,"planeBounds":{"left":-0.012500000000000001,"top":-0.61328125,"right":0.61250000000000004,"bottom":0.06640625},"atlasBounds":{"left":454.5,"top":710.5,"right":534.5,"bottom":797.5}},{"unicode":121,"advance":0.59999999999999998,"planeBounds":{"left":-0.0085937500000000042,"top":-0.61328125,"right":0.60859375000000004,"bottom":0.24609375},"atlasBounds":{"left":720.5,"top":377.5,"right":799.5,"bottom":487.5}},{"unicode":122,"advance":0.59999999999999998,"planeBounds":{"left":0.026562500000000024,"top":-0.61328125,"right":0.57343750000000004,"bottom":0.06640625},"atlasBounds":{"left":535.5,"top":710.5,"right":605.5,"bottom":797.5}},{"unicode":123,"advance":0.59999999999999998,"planeBounds":{"left":0.0087500000000000251,"top":-0.89453125,"right":0.57125000000000004,"bottom":0.17578125},"atlasBounds":{"left":602.5,"top":0.5,"right":674.5,"bottom":137.5}},{"unicode":124,"advance":0.59999999999999998,"planeBounds":{"left":0.19062500000000002,"top":-0.89453125,"right":0.40937499999999999,"bottom":0.17578125},"atlasBounds":{"left":325.5,"top":0.5,"right":353.5,"bottom":137.5}},{"unicode":125,"advance":0.59999999999999998,"planeBounds":{"left":0.028750000000000026,"top":-0.89453125,"right":0.59125000000000005,"bottom":0.17578125},"atlasBounds":{"left":252.5,"top":0.5,"right":324.5,"bottom":137.5}},{"unicode":126,"advance":0.59999999999999998,"planeBounds":{"left":0.007031249999999982,"top":-0.51953125,"right":0.59296875000000004,"bottom":-0.18359375},"atlasBounds":{"left":314.5,"top":800.5,"right":389.5,"bottom":843.5}}],"kerning":[]} diff --git a/assets/slug/slug.frag.spv b/assets/slug/slug.frag.spv new file mode 100644 index 0000000..75ac081 Binary files /dev/null and b/assets/slug/slug.frag.spv differ diff --git a/assets/slug/slug.vert.spv b/assets/slug/slug.vert.spv new file mode 100644 index 0000000..b29d6c8 Binary files /dev/null and b/assets/slug/slug.vert.spv differ diff --git a/build.sh b/build.sh index 9aaa32a..a6981d5 100755 --- a/build.sh +++ b/build.sh @@ -3,29 +3,18 @@ set -eu # SHADERS -shader_compiler="glslc" -shader_flags="-std=460 -O --target-env=vulkan1.2 -g" -shader_out="-oassets/" +shader_compiler="glslang" +shader_flags="--target-env vulkan1.2 -gVS" +shader_out="-o assets/" mkdir -p build mkdir -p assets for shader in src/shaders/*.glsl; do base_name=$(basename -- "$shader" .glsl) - - case "$base_name" in - *.vert) shader_stage="-fshader-stage=vert" ;; - *.frag) shader_stage="-fshader-stage=frag" ;; - *.tesc) shader_stage="-fshader-stage=tesc" ;; - *.tese) shader_stage="-fshader-stage=tese" ;; - *.geom) shader_stage="-fshader-stage=geom" ;; - *.comp) shader_stage="-fshader-stage=comp" ;; - *) continue ;; - esac - - $shader_compiler $shader_flags $shader_stage $shader "${shader_out}${base_name}.spv" + $shader_compiler $shader_flags $shader_out${base_name}.spv $shader done -#/bin/bash src/VulkanRenderer/build.sh build +/bin/bash src/VulkanRenderer/build.sh build /bin/bash src/dlib/build.sh build diff --git a/frag.spv b/frag.spv new file mode 100644 index 0000000..de1f07f Binary files /dev/null and b/frag.spv differ diff --git a/src/VulkanRenderer b/src/VulkanRenderer index b7674e4..245db6e 160000 --- a/src/VulkanRenderer +++ b/src/VulkanRenderer @@ -1 +1 @@ -Subproject commit b7674e43bde4661dac2a11092826079c57a4d66c +Subproject commit 245db6ea6fe787e91839dd78f92dda007e234f7c diff --git a/src/dlib b/src/dlib index 8690e93..6ae59da 160000 --- a/src/dlib +++ b/src/dlib @@ -1 +1 @@ -Subproject commit 8690e93b41ffe7bba528b76dfa749ee4bb6f28d5 +Subproject commit 6ae59dab5bca9d44fdf4a7f517654b1c0f8545f1 diff --git a/src/editor/editor.d b/src/editor/editor.d index 687353c..ae84e39 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -24,12 +24,13 @@ struct RenderCtx Descriptor[FS] font_descs; Descriptor default_tex; Descriptor sampler; + Descriptor msdf_texture; Pipeline pipeline; + Pipeline slug_pipeline; DescSetLayout desc_set_layout; DescSet[FO] desc_sets; PipelineLayout pipeline_layout; PushConst pc; - Vec2 res; } struct Ctx @@ -54,14 +55,19 @@ struct Ctx LinkedList!(UIInput) events; IVec2 mouse_pos; + SlugFont slug_font; FontFace font; FontSet[FS] font_sets; u32 font_sets_used; bool[FO] fonts_to_load; bool prev_has_tex; - u32 prev_atlas_index; + u32 prev_atlas_index; UIBuffer[FO] buffers; + + SlugBuffer[FO] slug_buffers; + MappedBuffer!(SlugVertex)[FO] slug_vertex_buffers; + MappedBuffer!(u32)[FO] slug_index_buffers; u32 tab_width; Vec4[TS.max][UISH.max] syntax_colors; diff --git a/src/editor/main.d b/src/editor/main.d index 8ae9d5b..747bb47 100644 --- a/src/editor/main.d +++ b/src/editor/main.d @@ -43,11 +43,12 @@ void main(string[] argv) } Vec2 current_res = Vec2(window.w, window.h); - if(g_ctx.res != current_res) + if(g_ctx.pc.resolution != current_res) { SetExtent(window.w, window.h); - g_ctx.res = current_res; + g_ctx.pc.resolution = current_res; Ortho(&g_ctx.pc.projection, 0.0, 0.0, current_res.x, current_res.y, -10.0, 10.0); + UpdateMSDFShaderInfo(&g_ctx.pc, g_ctx.pc.resolution); } if(inputs.first == null) diff --git a/src/editor/ui.d b/src/editor/ui.d index 0e89ac4..abf34c0 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -60,9 +60,9 @@ const f32 CORNER_RADIUS = 8.0; //u8[] FONT_BYTES = Arr!(u8)(import("pc-9800.ttf")); //u8[] FONT_BYTES = Arr!(u8)(import("NuberNextCondensed-DemiBold.otf")); -u8[] FONT_BYTES = cast(u8[])import("jetbrains-mono/JetBrainsMono-Regular.ttf"); -u8[] VERTEX_BYTES = cast(u8[])import("gui.vert.spv"); -u8[] FRAGMENT_BYTES = cast(u8[])import("gui.frag.spv"); +u8[] FONT_BYTES = cast(u8[])import("jetbrains-mono/JetBrainsMono-Regular.ttf"); +u8[] VERTEX_BYTES = cast(u8[])import("gui.vert.spv"); +u8[] FRAGMENT_BYTES = cast(u8[])import("gui.frag.spv"); const SEP_FLAGS = UIF.Drag|UIF.Priority|UIF.TargetLeniency; const PANEL_FLAGS = UIF.Click|UIF.Drag; @@ -179,7 +179,12 @@ enum ItemStateFlags struct PushConst { Mat4 projection; + Vec2 resolution; + Vec2 aem_range; u32 atlas_index; + f32 threshold_em; + f32 antialias_per_em; + f32 distance_range; } enum FO = FRAME_OVERLAP; @@ -288,6 +293,19 @@ struct UIPanel alias item this; } +void +UpdateMSDFShaderInfo(PushConst* pc, Vec2 resolution) +{ + const f32 AA_PIXEL_SIZE = 1.0; + + f32 aa_in_em = AA_PIXEL_SIZE * resolution.x / MSDF_INFO.pixels_per_em; + + pc.antialias_per_em = 1.0 / aa_in_em; + pc.aem_range = MSDF_INFO.aem_range; + pc.threshold_em = 0.0; + pc.distance_range = MSDF_INFO.distance_field_range; +} + struct Window { Window* next, prev; @@ -305,16 +323,16 @@ enum SettingType } Attribute[10] attributes = [ - { binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof }, - { binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.corner_radius.offsetof }, - { binding: 0, location: 2, format: FMT.RG_F32, offset: Vertex.dst_start.offsetof }, - { binding: 0, location: 3, format: FMT.RG_F32, offset: Vertex.dst_end.offsetof }, - { binding: 0, location: 4, format: FMT.RG_F32, offset: Vertex.src_start.offsetof }, - { binding: 0, location: 5, format: FMT.RG_F32, offset: Vertex.src_end.offsetof }, - { binding: 0, location: 6, format: FMT.R_F32, offset: Vertex.border_thickness.offsetof }, - { binding: 0, location: 7, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof }, - { binding: 0, location: 8, format: FMT.R_F32, offset: Vertex.raised.offsetof }, - { binding: 0, location: 9, format: FMT.R_U32, offset: Vertex.has_texture.offsetof }, + { binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof }, + { binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.corner_radius.offsetof }, + { binding: 0, location: 2, format: FMT.RG_F32, offset: Vertex.dst_start.offsetof }, + { binding: 0, location: 3, format: FMT.RG_F32, offset: Vertex.dst_end.offsetof }, + { binding: 0, location: 4, format: FMT.RG_F32, offset: Vertex.src_start.offsetof }, + { binding: 0, location: 5, format: FMT.RG_F32, offset: Vertex.src_end.offsetof }, + { binding: 0, location: 6, format: FMT.R_F32, offset: Vertex.border_thickness.offsetof }, + { binding: 0, location: 7, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof }, + { binding: 0, location: 8, format: FMT.R_F32, offset: Vertex.raised.offsetof }, + { binding: 0, location: 9, format: FMT.R_U32, offset: Vertex.has_texture.offsetof }, ]; union Rect @@ -336,6 +354,226 @@ struct UIKey bool opCast(T)() if(is(T == bool)) => this.hash != 0; } +/* + "atlas": { + "type": "mtsdf", + "distanceRange": 2, + "distanceRangeMiddle": 0, + "size": 32.5, + "width": 216, + "height": 216, + "yOrigin": "bottom" + }, + "metrics": { + "emSize": 1, + "lineHeight": 1.3200000000000001, + "ascender": 1.02, + "descender": -0.29999999999999999, + "underlineY": -0.17999999999999999, + "underlineThickness": 0.050000000000000003 + }, + "glyphs": [ + { + "unicode": 32, + "advance": 0.59999999999999998 + }, + { + "unicode": 33, + "advance": 0.59999999999999998, + "planeBounds": { + "left": 0.19230769230769232, + "bottom": -0.046153846153846149, + "right": 0.40769230769230769, + "top": 0.78461538461538449 + }, + "atlasBounds": { + "left": 19.5, + "bottom": 151.5, + "right": 26.5, + "top": 178.5 + } + }, + +*/ + +enum MSDFType +{ + None, + HardMask, + SoftMask, + SDF, + PSDF, + MSDF, + MTSDF, +} + +enum MSDFYOrigin +{ + None, + Left, + Bottom, + Right, + Top, +} + +struct MSDFInfo +{ + MSDFGlyph[] glyphs; + MSDFType type; + Vec2 aem_range; + u32 distance_field_range; + u32 distance_field_range_middle; + f32 pixels_per_em; + u32 texture_width; + u32 texture_height; + MSDFYOrigin y_origin; + f32 line_height; // EM + f32 ascender; // EM + f32 descender; // EM + f32 underline_y; // EM + f32 underline_thickness; // EM +} + +struct MSDFBounds +{ + f32 left = 0.0, bottom = 0.0, right = 0.0, top = 0.0; +} + +struct MSDFGlyph +{ + dchar glyph = 0; + f32 advance = 0.0; + MSDFBounds plane; // EM + MSDFBounds atlas; // Pixels +} + +const u8[] MSDF_ATLAS = cast(u8[])import("msdf-atlas.rgba"); + +const MSDFInfo MSDF_INFO = GenerateMSDF(); + +static MSDFInfo +GenerateMSDF() +{ + import std.json; + + string msdf_json = import("msdf.json"); + + JSONValue jsonv = parseJSON(msdf_json); + + static T GetJSONValue(T)(JSONValue jsonv, string name) + { + static if(is(T == string)) + { + T result = ""; + } + else + { + T result = cast(T)0; + } + + if(const(JSONValue)* value = name in jsonv) + { + switch(value.type()) + { + static if(is(T == u32) || is(T == u64) || is(T == f32)) + { + case JSONType.float_: result = cast(T)value.floating; break; + case JSONType.uinteger: result = cast(T)value.uinteger; break; + case JSONType.integer: result = cast(T)value.integer; break; + } + static if(is(T == string)) + { + case JSONType.string: result = cast(T)value.str; break; + } + default: assert(false, "Unable to retrieve value"); + } + } + + return result; + } + + MSDFInfo result = { + distance_field_range: GetJSONValue!(u32)(jsonv["atlas"], "distanceRange"), + distance_field_range_middle: GetJSONValue!(u32)(jsonv["atlas"], "distanceRangeMiddle"), + pixels_per_em: GetJSONValue!(f32)(jsonv["atlas"], "size"), + texture_width: GetJSONValue!(u32)(jsonv["atlas"], "width"), + texture_height: GetJSONValue!(u32)(jsonv["atlas"], "height"), + line_height: GetJSONValue!(f32)(jsonv["metrics"], "lineHeight"), + ascender: GetJSONValue!(f32)(jsonv["metrics"], "ascender"), + descender: GetJSONValue!(f32)(jsonv["metrics"], "descender"), + underline_y: GetJSONValue!(f32)(jsonv["metrics"], "underlineY"), + underline_thickness: GetJSONValue!(f32)(jsonv["metrics"], "underlineThickness"), + }; + + result.aem_range = Vec2( + (result.distance_field_range_middle - result.distance_field_range/2) / result.pixels_per_em, + (result.distance_field_range_middle + result.distance_field_range/2) / result.pixels_per_em + ); + + string type_string = GetJSONValue!(string)(jsonv["atlas"], "type"); + string y_origin_string = GetJSONValue!(string)(jsonv["atlas"], "yOrigin"); + + assert(type_string.length); + assert(y_origin_string.length); + + final switch(type_string) with(MSDFType) + { + case "hardmask": result.type = HardMask; break; + case "softmask": result.type = SoftMask; break; + case "sdf": result.type = SDF; break; + case "psdf": result.type = PSDF; break; + case "msdf": result.type = MSDF; break; + case "mtsdf": result.type = MTSDF; break; + } + + final switch(y_origin_string) with(MSDFYOrigin) + { + case "top": result.y_origin = Top; break; + case "left": result.y_origin = Left; break; + case "right": result.y_origin = Right; break; + case "bottom": result.y_origin = Bottom; break; + } + + MSDFGlyph[] glyphs = new MSDFGlyph[128]; + + JSONValue[] glyph_json = jsonv["glyphs"].array; + + foreach(i; 0 .. glyph_json.length) + { + u64 ch = cast(u64)glyph_json[i]["unicode"].integer; + MSDFGlyph glyph = { glyph: cast(dchar)ch }; + glyph.advance = GetJSONValue!(f32)(glyph_json[i], "advance"); + if("planeBounds" in glyph_json[i]) + { + glyph.plane.left = GetJSONValue!(f32)(glyph_json[i]["planeBounds"], "left"); + glyph.plane.right = GetJSONValue!(f32)(glyph_json[i]["planeBounds"], "right"); + glyph.plane.bottom = GetJSONValue!(f32)(glyph_json[i]["planeBounds"], "bottom"); + glyph.plane.top = GetJSONValue!(f32)(glyph_json[i]["planeBounds"], "top"); + + glyph.atlas.left = GetJSONValue!(f32)(glyph_json[i]["atlasBounds"], "left"); + glyph.atlas.right = GetJSONValue!(f32)(glyph_json[i]["atlasBounds"], "right"); + glyph.atlas.bottom = GetJSONValue!(f32)(glyph_json[i]["atlasBounds"], "bottom"); + glyph.atlas.top = GetJSONValue!(f32)(glyph_json[i]["atlasBounds"], "top"); + } + + glyphs[ch] = glyph; + } + + foreach(i; 0 .. glyphs.length) + { + if(glyphs[i].glyph == 0xFFFF) + { + glyphs[i].glyph = 0; + glyphs[i].plane = MSDFBounds(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0); + glyphs[i].atlas = MSDFBounds(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0); + } + } + + result.glyphs = glyphs; + + return result; +} + enum bool KeyType(T) = (StringType!(T) || is(T == UIKey) || is(T == const(UIKey))); enum bool ItemAndKeyType(T) = (KeyType!(T) || is(T == UIItem*)); @@ -362,12 +600,12 @@ InitUI(Ctx* ctx) UIBuffer[FRAME_OVERLAP] buffers; - ctx.items = CreateHashTable!(UIHash, UIItem*)(12); - ctx.arena = arena; - ctx.temp_arena = CreateArena(MB(1)); - ctx.font = OpenFont(cast(u8[])FONT_BYTES); - ctx.tab_width = 2; - ctx.syntax_colors = [DEFAULT_COLORS, SYNTAX_COLORS]; + ctx.items = CreateHashTable!(UIHash, UIItem*)(12); + ctx.arena = arena; + ctx.temp_arena = CreateArena(MB(1)); + ctx.font = OpenFont(cast(u8[])FONT_BYTES); + ctx.tab_width = 2; + ctx.syntax_colors = [DEFAULT_COLORS, SYNTAX_COLORS]; assert(ctx.font); @@ -375,9 +613,10 @@ InitUI(Ctx* ctx) { InitRenderer(handles, MB(16), MB(8)); - DescLayoutBinding[2] layout_bindings = [ + DescLayoutBinding[3] layout_bindings = [ { binding: 0, descriptorType: DT.Image, descriptorCount: FONT_SIZES, stageFlags: SS.All }, { binding: 1, descriptorType: DT.Sampler, descriptorCount: 1, stageFlags: SS.All }, + { binding: 2, descriptorType: DT.Image, descriptorCount: 1, stageFlags: SS.All }, ]; ctx.desc_set_layout = CreateDescSetLayout(layout_bindings); @@ -392,6 +631,11 @@ InitUI(Ctx* ctx) ctx.buffers[i].idx[0 .. $] = [0, 1, 2, 2, 1, 3]; ctx.desc_sets[i] = AllocDescSet(ctx.desc_set_layout); ctx.str_arenas[i] = CreateArena(MB(1)); + + ctx.slug_vertex_buffers[i] = CreateMappedBuffer!(SlugVertex)(BT.Vertex, 1000); + ctx.slug_index_buffers[i] = CreateMappedBuffer!(u32)(BT.Index, 1000); + ctx.slug_buffers[i].vertices = ctx.slug_vertex_buffers[i].data; + ctx.slug_buffers[i].indices = ctx.slug_index_buffers[i].data; } GfxPipelineInfo ui_info = { @@ -411,6 +655,20 @@ InitUI(Ctx* ctx) CreateGraphicsPipeline(&ctx.pipeline, &ui_info); + CreateDescriptor( + &ctx.msdf_texture, + DescInfo( + type: DT.Image, + format: FMT.RGBA_UNORM, + usage: IU.Texture, + w: MSDF_INFO.texture_width, + h: MSDF_INFO.texture_height, + ch: 4, + binding: 2, + ), + cast(u8[])MSDF_ATLAS[12 .. $] + ); + for(u32 i = 0; i < ctx.font_descs.length; i += 1) { CreateDescriptor(&ctx.font_descs[i], DescInfo( @@ -428,9 +686,12 @@ InitUI(Ctx* ctx) } CreateDescriptor(&ctx.sampler, DescInfo( - type: DT.Sampler, - mipmap_mode: MipmapMode.Nearest, - binding: 1, + type: DT.Sampler, + min_filter: Filter.Nearest, + mag_filter: Filter.Nearest, + enable_anisotropy: true, + mipmap_mode: MipmapMode.Linear, + binding: 1, )); u8[512*512*4] white_tex = 255; @@ -443,6 +704,7 @@ InitUI(Ctx* ctx) { Write(ctx.desc_sets[i], ctx.font_descs); Write(ctx.desc_sets[i], &ctx.sampler); + Write(ctx.desc_sets[i], &ctx.msdf_texture); } SetClearColors([0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 0.0]); @@ -558,10 +820,12 @@ Scissor(Ctx* ctx, Rect rect, Style* style) f32 b = style.border_thickness + style.border_thickness*style.edge_softness; - i32 x = cast(i32)clamp(floor(rect.p0.x+b), 0.0, ctx.res.x); - i32 y = cast(i32)clamp(floor(rect.p0.y+b), 0.0, ctx.res.y); - i32 w = cast(i32)clamp(floor(rect.p1.x-b) - x, 0.0, ctx.res.x); - i32 h = cast(i32)clamp(floor(rect.p1.y-b) - y, 0.0, ctx.res.y); + Vec2 res = ctx.pc.resolution; + + i32 x = cast(i32)clamp(floor(rect.p0.x+b), 0.0, res.x); + i32 y = cast(i32)clamp(floor(rect.p0.y+b), 0.0, res.y); + i32 w = cast(i32)clamp(floor(rect.p1.x-b) - x, 0.0, res.x); + i32 h = cast(i32)clamp(floor(rect.p1.y-b) - y, 0.0, res.y); SetScissor(x, y, w, h); } @@ -1477,6 +1741,22 @@ DrawUI(Ctx* ctx, u32 atlas_index) } } +void +DrawSlug(Ctx* ctx) +{ + version(ENABLE_RENDERER) + { + // TODO: fix this + SlugBuffer* buffer = ctx.slug_buffers.ptr + ctx.f_idx; + + auto vertex_buffer = ctx.slug_vertex_buffers.ptr + ctx.f_idx; + auto index_buffer = ctx.slug_index_buffers.ptr + ctx.f_idx; + + BindBuffers(index_buffer, vertex_buffer); + DrawIndexed(buffer.quad_offset*6, 1, 0, 0, 0); + } +} + void DrawUI(Ctx* ctx) { @@ -1638,9 +1918,15 @@ BeginUI(Inputs* inputs) Bind(ctx.pipeline, ctx.desc_sets[ctx.f_idx]); } - memset(ctx.buffers[ctx.f_idx].vtx.ptr, 0, Vertex.sizeof * ctx.buffers[ctx.f_idx].count); - ctx.buffers[ctx.f_idx].count = 0; - ctx.buffers[ctx.f_idx].vtx_offset = 0; + UIBuffer* buffer = ctx.buffers.ptr + ctx.f_idx; + SlugBuffer* slug_buffer = ctx.slug_buffers.ptr + ctx.f_idx; + + memset(buffer.vtx.ptr, 0, Vertex.sizeof * buffer.count); + memset(slug_buffer.vertices.ptr, 0, SlugVertex.sizeof * slug_buffer.quad_offset); + + buffer.count = 0; + buffer.vtx_offset = 0; + slug_buffer.quad_offset = 0; } UIKey @@ -1741,8 +2027,8 @@ SetNil(Args...)(Args args) void Clamp(Ctx* ctx, Vertex* v) { - v.dst_start = Clamp(v.dst_start, Vec2(0.0), cast(Vec2)ctx.res); - v.dst_end = Clamp(v.dst_end, Vec2(0.0), cast(Vec2)ctx.res); + v.dst_start = Clamp(v.dst_start, Vec2(0.0), cast(Vec2)ctx.pc.resolution); + v.dst_end = Clamp(v.dst_end, Vec2(0.0), cast(Vec2)ctx.pc.resolution); } bool @@ -1917,7 +2203,7 @@ DrawText(T, U, V)(Ctx* ctx, T text_param, U col_param, V text_size_param, Rect r } AnimateReady(ready, &col); - DrawGlyph(rect, g, &x, rect.p0.y, fs.line_height, col); + DrawGlyph(rect, g, &x, rect.p0.y, fs.line_height, fs.size, col); } } else static if(is(U == Vec4)) @@ -1929,7 +2215,7 @@ DrawText(T, U, V)(Ctx* ctx, T text_param, U col_param, V text_size_param, Rect r { u8 ch = text[j]; Glyph* g = ch < fs.glyphs.length ? fs.glyphs.ptr + ch : null; - DrawGlyph(rect, g, &x, rect.p0.y, fs.line_height, hl_char == j ? InvertCol(col) : col); + DrawGlyph(rect, g, &x, rect.p0.y, fs.line_height, fs.size, hl_char == j ? InvertCol(col) : col); } } else static assert(false, "invalid input parameter, U must be TokenStyle[] or Vec4"); @@ -1946,10 +2232,12 @@ BeginScissor(Ctx* ctx, UIItem* item, bool scissor_x = true, bool scissor_y = tru { DrawUI(ctx); - i32 x = cast(i32)clamp(scissor_x ? floor(item.rect.p0.x) : 0, 0.0, ctx.res.x); - i32 y = cast(i32)clamp(scissor_y ? floor(item.rect.p0.y) : 0, 0.0, ctx.res.y); - i32 w = cast(i32)clamp(scissor_x ? floor(item.rect.p1.x) - x : ctx.res.x, 0.0, ctx.res.x); - i32 h = cast(i32)clamp(scissor_y ? floor(item.rect.p1.y) - y : ctx.res.y, 0.0, ctx.res.y); + Vec2 res = ctx.pc.resolution; + + i32 x = cast(i32)clamp(scissor_x ? floor(item.rect.p0.x) : 0, 0.0, res.x); + i32 y = cast(i32)clamp(scissor_y ? floor(item.rect.p0.y) : 0, 0.0, res.y); + i32 w = cast(i32)clamp(scissor_x ? floor(item.rect.p1.x) - x : res.x, 0.0, res.x); + i32 h = cast(i32)clamp(scissor_y ? floor(item.rect.p1.y) - y : res.y, 0.0, res.y); SetScissor(x, y, w, h); @@ -2254,11 +2542,13 @@ GlyphWidth(Glyph* g, FontSet* fs) } pragma(inline) void -DrawGlyph(Rect rect, Glyph* glyph, f32* x_pos, f32 y, f32 line_height, Vec4 col = Vec4(1.0)) +DrawGlyph(Rect rect, Glyph* glyph, f32* x_pos, f32 y, f32 line_height, u32 size, Vec4 col = Vec4(1.0)) { if(glyph) { - Ctx* ctx = GetCtx(); + const(MSDFGlyph)* msdf_glyph = &MSDF_INFO.glyphs[glyph.ch]; + + Ctx* ctx = GetCtx(); Vertex* v = null; f32 advance = glyph.advance; @@ -2279,11 +2569,12 @@ DrawGlyph(Rect rect, Glyph* glyph, f32* x_pos, f32 y, f32 line_height, Vec4 col f32 y_pos = y + glyph.plane_top; + // Need to change how the quads are calculated, i had changed it so they were all same height and same top/bottom placement as it was easier to draw rasterized glyphs that way but doesn't work when the SDFs are not generated in a similar way v.dst_start = Vec2(*x_pos+glyph.plane_left, y_pos); v.dst_end = Vec2(*x_pos+glyph.plane_left+w, y_pos+h); v.cols = col; - v.src_start = Vec2(glyph.atlas_left, glyph.atlas_top); - v.src_end = Vec2(glyph.atlas_right, glyph.atlas_bottom); + v.src_start = Vec2(glyph.atlas_left, glyph.atlas_top); // Vec2(msdf_glyph.atlas.left, msdf_glyph.atlas.top); + v.src_end = Vec2(glyph.atlas_right, glyph.atlas_bottom); // Vec2(msdf_glyph.atlas.right, msdf_glyph.atlas.bottom); v.has_texture = true; f32 end_x = *x_pos + advance; @@ -2329,7 +2620,7 @@ GetVertex(Ctx* ctx) bool Nil(T)(T item) { - static if(is(T == UIItem*)) return item == null || item == g_UI_NIL; + static if(is(T == UIItem*)) return item == null || item == g_UI_NIL; else static if(is(T == UIInput*)) return item == null || item == g_UI_NIL_INPUT; else static if(is(T == UIPanel*)) return item == null || item == g_NIL_PANEL; else static assert(false, "Invalid nil type checked"); diff --git a/src/shaders/gui.frag.glsl b/src/shaders/gui.frag.glsl index 43da360..5d6249a 100644 --- a/src/shaders/gui.frag.glsl +++ b/src/shaders/gui.frag.glsl @@ -7,33 +7,91 @@ #include "gui.layout" +layout (location = 0) FragDataFlat +{ + vec2 atlas_size; + uint has_texture; +} FDF; + +layout (location = 2) FragData +{ + vec4 color; + vec2 uv; + vec2 dst_pos; + vec2 dst_center; + vec2 dst_half_size; + vec2 sdf_sample_pos; + float corner_radius; + float softness; + float raised; + float border_thickness; +} FD; + layout (location = 0) out vec4 FragColor; -float RectSDF(vec2 pos, vec2 half_size, float radius) +float +RectSDF(vec2 pos, vec2 half_size, float radius) { return length(max(abs(pos) - half_size + radius, 0.0)) - radius; } -float ToSRGB(float col) +float +ToSRGB(float col) { return pow(col, 1.0/2.2); } -vec4 ToSRGB(vec4 col) +vec4 +ToSRGB(vec4 col) { return vec4(ToSRGB(col.r), ToSRGB(col.g), ToSRGB(col.b), col.a); } -vec4 ToLinear(vec4 col) +vec4 +ToLinear(vec4 col) { return pow(col, vec4(vec3(2.2), 1.0)); } -float GradientNoise(vec2 uv) +float +GradientNoise(vec2 uv) { return fract(52.9829189 * fract(dot(uv, vec2(0.06711056, 0.00583715)))); } +float +Median(vec3 v) +{ + return max(min(v.r, v.g), min(max(v.r, v.g), v.b)); +} + +float +GetMSDFTexel() +{ + vec2 dx = 0.25 * dFdx(FD.uv); + vec2 dy = 0.25 * dFdy(FD.uv); + float center = Median(texture(MSDFAtlas, FD.uv).rgb); + float s0 = Median(texture(MSDFAtlas, FD.uv - dx - dy).rgb); + float s1 = Median(texture(MSDFAtlas, FD.uv + dx - dy).rgb); + float s2 = Median(texture(MSDFAtlas, FD.uv - dx + dy).rgb); + float s3 = Median(texture(MSDFAtlas, FD.uv + dx + dy).rgb); + + return mix(center, 0.25 * (s0+s1+s2+s3), 0.0); +} + +vec2 +Square(vec2 x) +{ + return x*x; +} + +float +ScreenPxRange() +{ + vec2 screen_tex_size = vec2(1.0)/fwidth(FD.uv); + return max(0.5*dot(vec2(0.03125), screen_tex_size), 1.0); +} + void main() { float softness = FD.softness; @@ -65,19 +123,28 @@ void main() vec4 inv_gamma = vec4(1.4); vec4 gamma = vec4(1.0/1.4); - vec4 tex_color = vec4(1.0); + vec4 tex_color = vec4(1.0); // ToLinear(FD.color); if(FDF.has_texture != 0) { - tex_color = texture(sampler2D(SpriteAtlas, SamplerNearest), FD.uv); + // old: + tex_color = texture(SpriteAtlas, FD.uv); + + /* + float sd = Median(texture(MSDFAtlas, FD.uv).rgb); + float px_range = ScreenPxRange(); + float screen_px_dist = ScreenPxRange() * (sd-0.5); + float opacity = clamp(0.5 + screen_px_dist/fwidth(screen_px_dist), 0.0, 1.0); + + color.a *= opacity; + */ } - vec4 color = FD.color; // ToLinear(FD.color); - vec4 out_color = color * tex_color; + vec4 color = FD.color * tex_color; - out_color.a *= corner_factor; - out_color.a *= border_factor; + color.a *= corner_factor; + color.a *= border_factor; - out_color += (1.0 / 255.0) * GradientNoise(gl_FragCoord.xy); + color += (1.0 / 255.0) * GradientNoise(gl_FragCoord.xy); - FragColor = out_color; + FragColor = color; } diff --git a/src/shaders/gui.layout b/src/shaders/gui.layout index 1691df7..aaa3fbf 100644 --- a/src/shaders/gui.layout +++ b/src/shaders/gui.layout @@ -1,15 +1,23 @@ -layout (rgba16f, set = 0, binding = 0) uniform image2D DrawImage; -layout (set = 1, binding = 0) uniform texture2D SpriteAtlasArray[24]; -layout (set = 1, binding = 1) uniform sampler SamplerNearest; +layout(rgba16f, set = 0, binding = 0) uniform image2D DrawImage; + +layout(set = 1, binding = 0) uniform texture2D SpriteAtlasArray[24]; +layout(set = 1, binding = 1) uniform sampler SamplerNearest; +layout(set = 1, binding = 2) uniform texture2D MSDFAtlasTexture; layout (push_constant) uniform Constants { - mat4 projection; - uint atlas_index; + mat4 projection; + vec2 resolution; + vec2 aem_range; + uint atlas_index; + float threshold_em; + float antialias_per_em; + float distance_range; } PC; -#define SpriteAtlas SpriteAtlasArray[PC.atlas_index] +#define SpriteAtlas sampler2D(SpriteAtlasArray[PC.atlas_index], SamplerNearest) +#define MSDFAtlas sampler2D(MSDFAtlasTexture, SamplerNearest) #ifdef VERT_SHADER # define FragData out struct FragDataOut @@ -21,21 +29,3 @@ layout (push_constant) uniform Constants { # define FragDataFlat flat in struct FragDataFlatIn #endif -layout (location = 0) FragDataFlat -{ - uint has_texture; -} FDF; - -layout (location = 1) FragData -{ - vec4 color; - vec2 uv; - vec2 dst_pos; - vec2 dst_center; - vec2 dst_half_size; - vec2 sdf_sample_pos; - float corner_radius; - float softness; - float raised; - float border_thickness; -} FD; diff --git a/src/shaders/gui.vert.glsl b/src/shaders/gui.vert.glsl index 87f37ab..c0a8c0c 100644 --- a/src/shaders/gui.vert.glsl +++ b/src/shaders/gui.vert.glsl @@ -17,6 +17,26 @@ layout (location = 7) in float edge_softness; layout (location = 8) in float raised; layout (location = 9) in uint has_texture; +layout (location = 0) FragDataFlat +{ + vec2 atlas_size; + uint has_texture; +} FDF; + +layout (location = 2) FragData +{ + vec4 color; + vec2 uv; + vec2 dst_pos; + vec2 dst_center; + vec2 dst_half_size; + vec2 sdf_sample_pos; + float corner_radius; + float softness; + float raised; + float border_thickness; +} FD; + vec2 Vertices[4] = vec2[4]( vec2(-1.0, -1.0), vec2(-1.0, +1.0), @@ -31,7 +51,7 @@ vec2 rotate(vec2 coords, float theta) void main() { - ivec2 tex_size = textureSize(sampler2D(SpriteAtlas, SamplerNearest), 0); + ivec2 tex_size = textureSize(SpriteAtlas, 0); vec4 pos_start = vec4(in_dst_start.x, in_dst_start.y - raised, 0.0, 1.0); vec4 pos_end = vec4(in_dst_end.x, in_dst_end.y, 0.0, 1.0); @@ -47,8 +67,8 @@ void main() vec2 uvs[4] = vec2[4]( vec2(in_src_start.x, in_src_start.y), vec2(in_src_start.x, in_src_end.y), - vec2(in_src_end.x, in_src_start.y), - vec2(in_src_end.x, in_src_end.y) + vec2(in_src_end.x, in_src_start.y), + vec2(in_src_end.x, in_src_end.y) ); float corner_radius[4] = float[4]( @@ -72,6 +92,7 @@ void main() FD.border_thickness = border_thickness; FD.sdf_sample_pos = (2.0f * dst_verts_pct - 1.0f) * half_size; FDF.has_texture = has_texture; + FDF.atlas_size = in_src_end - in_src_start; vec4 v_pos = PC.projection * vec4(pos.x, pos.y, 0, 1); gl_Position = vec4(v_pos.x, v_pos.y, v_pos.z, 1); diff --git a/vert.spv b/vert.spv new file mode 100644 index 0000000..0eda396 Binary files /dev/null and b/vert.spv differ