From 99a4c38712159f9684a1b0c945323a466eb66e32 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 16 Mar 2022 12:17:37 -0700 Subject: [PATCH 1/4] Standard shader uses material alpha; --- src/resources/shaders.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/resources/shaders.c b/src/resources/shaders.c index 2b332971..209a78fa 100644 --- a/src/resources/shaders.c +++ b/src/resources/shaders.c @@ -219,7 +219,7 @@ const char* lovrStandardFragmentShader = "" " vec3 result = vec3(0.); \n" // Parameters -" vec3 baseColor = texture(lovrDiffuseTexture, lovrTexCoord).rgb * lovrDiffuseColor.rgb; \n" +" vec4 baseColor = texture(lovrDiffuseTexture, lovrTexCoord) * lovrDiffuseColor; \n" " float metalness = texture(lovrMetalnessTexture, lovrTexCoord).b * lovrMetalness; \n" " float roughness = max(texture(lovrRoughnessTexture, lovrTexCoord).g * lovrRoughness, .05); \n" "#ifdef FLAG_normalMap \n" @@ -237,12 +237,12 @@ const char* lovrStandardFragmentShader = "" " float VoH = clamp(dot(V, H), 0., 1.); \n" // Direct lighting -" vec3 F0 = mix(vec3(.04), baseColor, metalness); \n" +" vec3 F0 = mix(vec3(.04), baseColor.rgb, metalness); \n" " float D = D_GGX(NoH, roughness); \n" " float G = G_SmithGGXCorrelated(NoV, NoL, roughness); \n" " vec3 F = F_Schlick(F0, VoH); \n" " vec3 specularDirect = vec3(D * G * F); \n" -" vec3 diffuseDirect = (vec3(1.) - F) * (1. - metalness) * baseColor; \n" +" vec3 diffuseDirect = (vec3(1.) - F) * (1. - metalness) * baseColor.rgb; \n" " result += (diffuseDirect / PI + specularDirect) * NoL * lovrLightColor.rgb * lovrLightColor.a; \n" // Indirect lighting @@ -267,7 +267,7 @@ const char* lovrStandardFragmentShader = "" " result = tonemap_ACES(result * lovrExposure); \n" "#endif \n" -" return lovrGraphicsColor * vec4(result, 1.); \n" +" return lovrGraphicsColor * vec4(result, baseColor.a); \n" "}" // Helpers From 1ca3d1c8e1409c5f2fd42ebef254e58d0bc31ff2 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 16 Mar 2022 12:23:59 -0700 Subject: [PATCH 2/4] Fix unintended int truncation in Font:getLineHeight; --- src/api/l_graphics_font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/l_graphics_font.c b/src/api/l_graphics_font.c index c95eb1ce..b0b29f8f 100644 --- a/src/api/l_graphics_font.c +++ b/src/api/l_graphics_font.c @@ -46,7 +46,7 @@ static int l_lovrFontGetBaseline(lua_State* L) { static int l_lovrFontGetLineHeight(lua_State* L) { Font* font = luax_checktype(L, 1, Font); - lua_pushinteger(L, lovrFontGetLineHeight(font)); + lua_pushnumber(L, lovrFontGetLineHeight(font)); return 1; } From 8955c6fc02fa388e95f26ac6f72d5e8ce87eb33c Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 19 Mar 2022 13:26:28 -0700 Subject: [PATCH 3/4] Remove assert for missing glyphs; The notdef glyph will get rendered instead, which is slightly better. Note that the default font does not have a notdef glyph (bug). Note that notdef will be rasterized multiple times right now. --- src/modules/data/rasterizer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/data/rasterizer.c b/src/modules/data/rasterizer.c index cbb713ec..f2edcc32 100644 --- a/src/modules/data/rasterizer.c +++ b/src/modules/data/rasterizer.c @@ -101,7 +101,6 @@ bool lovrRasterizerHasGlyphs(Rasterizer* rasterizer, const char* str) { void lovrRasterizerLoadGlyph(Rasterizer* rasterizer, uint32_t character, uint32_t padding, double spread, Glyph* glyph) { int glyphIndex = stbtt_FindGlyphIndex(&rasterizer->font, character); - lovrAssert(glyphIndex, "No font glyph found for character code %d, try using Rasterizer:hasGlyphs", character); int advance, bearing; stbtt_GetGlyphHMetrics(&rasterizer->font, glyphIndex, &advance, &bearing); From af3ec874f0aca97ec6d1748bab27d66adaac6ff9 Mon Sep 17 00:00:00 2001 From: monolifed <6624464+monolifed@users.noreply.github.com> Date: Mon, 28 Mar 2022 11:26:31 +0300 Subject: [PATCH 4/4] Keep winding with flip --- src/modules/graphics/font.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/font.c b/src/modules/graphics/font.c index 88d9f6ac..ef6af1bf 100644 --- a/src/modules/graphics/font.c +++ b/src/modules/graphics/font.c @@ -110,12 +110,11 @@ Texture* lovrFontGetTexture(Font* font) { void lovrFontRender(Font* font, const char* str, size_t length, float wrap, HorizontalAlign halign, float* vertices, uint16_t* indices, uint16_t baseVertex) { FontAtlas* atlas = &font->atlas; - bool flip = font->flip; int height = lovrRasterizerGetHeight(font->rasterizer); float cx = 0.f; - float cy = -height * .8f * (flip ? -1.f : 1.f); + float cy = -height * .8f; float u = atlas->width; float v = atlas->height; float scale = 1.f / font->pixelDensity; @@ -137,7 +136,7 @@ void lovrFontRender(Font* font, const char* str, size_t length, float wrap, Hori if (codepoint == '\n' || (wrap && cx * scale > wrap && (codepoint == ' ' || previous == ' '))) { lineStart = lovrFontAlignLine(lineStart, vertexCursor, cx, halign); cx = 0.f; - cy -= height * font->lineHeight * (flip ? -1.f : 1.f); + cy -= height * font->lineHeight; previous = '\0'; if (codepoint == ' ' || codepoint == '\n') { str += bytes; @@ -170,13 +169,20 @@ void lovrFontRender(Font* font, const char* str, size_t length, float wrap, Hori if (glyph->w > 0 && glyph->h > 0) { int32_t padding = font->padding; float x1 = cx + glyph->dx - padding; - float y1 = cy + (glyph->dy + padding) * (flip ? -1.f : 1.f); + float y1 = cy + (glyph->dy + padding); float x2 = x1 + glyph->tw; - float y2 = y1 - glyph->th * (flip ? -1.f : 1.f); + float y2 = y1 - glyph->th; float s1 = glyph->x / u; float t1 = (glyph->y + glyph->th) / v; float s2 = (glyph->x + glyph->tw) / u; float t2 = glyph->y / v; + + if (font->flip) { + float tmp = y1; + y1 = -y2; y2 = -tmp; + tmp = t1; + t1 = t2; t2 = tmp; + } memcpy(vertexCursor, (float[32]) { x1, y1, 0.f, 0.f, 0.f, 0.f, s1, t1,