Merge branch 'master' into dev

This commit is contained in:
bjorn 2022-03-30 13:52:58 -07:00
commit efbcb5e4c2
4 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -48,7 +48,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;
}

View File

@ -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);

View File

@ -121,12 +121,11 @@ void lovrFontSetFilter(Font* font, TextureFilter filter) {
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;
@ -148,7 +147,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;
@ -181,13 +180,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,