1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-12 08:04:09 +02:00

fix pre-multiply alpha for atlas borders (sprites only)

This commit is contained in:
XProger
2019-02-19 00:35:13 +03:00
parent 48e2bcf9e7
commit c8cfff82a4
3 changed files with 24 additions and 17 deletions

View File

@@ -1195,11 +1195,11 @@ struct Level : IGame {
// oxygen bar // oxygen bar
{ 0xFF647464, 0xFFA47848, 0xFF647464, 0xFF4C504C, 0xFF303030 }, { 0xFF647464, 0xFFA47848, 0xFF647464, 0xFF4C504C, 0xFF303030 },
// option bar // option bar
{ 0x00FFFFFF, 0x20FFFFFF, 0x20FFFFFF, 0x20FFFFFF, 0x00FFFFFF, { 0x00000000, 0x20202020, 0x20202020, 0x20202020, 0x00000000,
0x00FFFFFF, 0x60FFFFFF, 0x60FFFFFF, 0x60FFFFFF, 0x00FFFFFF, 0x00000000, 0x60606060, 0x60606060, 0x60606060, 0x00000000,
0x00FFFFFF, 0x80FFFFFF, 0x80FFFFFF, 0x80FFFFFF, 0x00FFFFFF, 0x00000000, 0x80808080, 0x80808080, 0x80808080, 0x00000000,
0x00FFFFFF, 0x60FFFFFF, 0x60FFFFFF, 0x60FFFFFF, 0x00FFFFFF, 0x00000000, 0x60606060, 0x60606060, 0x60606060, 0x00000000,
0x00FFFFFF, 0x20FFFFFF, 0x20FFFFFF, 0x20FFFFFF, 0x00FFFFFF }, 0x00000000, 0x20202020, 0x20202020, 0x20202020, 0x00000000 },
// white bar (white tile) // white bar (white tile)
{ 0xFFFFFFFF }, { 0xFFFFFFFF },
}; };
@@ -1212,26 +1212,31 @@ struct Level : IGame {
Color32 *src, *dst = (Color32*)data; Color32 *src, *dst = (Color32*)data;
short4 mm; short4 mm;
bool isSprite = false;
if (id < level->objectTexturesCount) { // textures if (id < level->objectTexturesCount) { // textures
TR::TextureInfo &t = level->objectTextures[id]; TR::TextureInfo &t = level->objectTextures[id];
mm = t.getMinMax(); mm = t.getMinMax();
src = owner->tileData->color; src = owner->tileData->color;
uv = t.texCoordAtlas; uv = t.texCoordAtlas;
uvCount = 4; uvCount = 4;
if (data) if (data) {
level->fillObjectTexture(owner->tileData, tile.uv, tile.tex); level->fillObjectTexture(owner->tileData, tile.uv, tile.tex);
}
} else { } else {
id -= level->objectTexturesCount; id -= level->objectTexturesCount;
if (id < level->spriteTexturesCount) { // sprites if (id < level->spriteTexturesCount) { // sprites
TR::TextureInfo &t = level->spriteTextures[id]; TR::TextureInfo &t = level->spriteTextures[id];
mm = t.getMinMax(); mm = t.getMinMax();
src = owner->tileData->color; src = owner->tileData->color;
uv = t.texCoordAtlas; uv = t.texCoordAtlas;
uvCount = 2; uvCount = 2;
if (data) isSprite = true;
if (data) {
level->fillObjectTexture(owner->tileData, tile.uv, tile.tex); level->fillObjectTexture(owner->tileData, tile.uv, tile.tex);
}
} else { // common (generated) textures } else { // common (generated) textures
id -= level->spriteTexturesCount; id -= level->spriteTexturesCount;
@@ -1281,7 +1286,12 @@ struct Level : IGame {
ASSERT((y + ATLAS_BORDER + tileY) >= 0 && (y + ATLAS_BORDER + tileY) < atlasHeight); ASSERT((y + ATLAS_BORDER + tileY) >= 0 && (y + ATLAS_BORDER + tileY) < atlasHeight);
p += clamp(x, 0, w - 1); p += clamp(x, 0, w - 1);
p += clamp(y, 0, h - 1) * stride; p += clamp(y, 0, h - 1) * stride;
dst[x + ATLAS_BORDER] = *p;
if (isSprite && (y < 0 || y >= h || x < 0 || x >= w)) {
dst[x + ATLAS_BORDER] = Color32(0, 0, 0, 0);
} else {
dst[x + ATLAS_BORDER] = *p;
}
} }
dst += atlasWidth; dst += atlasWidth;
} }

View File

@@ -151,7 +151,7 @@ varying vec4 vTexCoord; // xy - atlas coords, zw - trapezoidal correction
#ifdef TYPE_FLASH #ifdef TYPE_FLASH
vDiffuse.xyz += uMaterial.w; vDiffuse.xyz += uMaterial.w;
#else #else
vDiffuse.w = uMaterial.w; vDiffuse *= uMaterial.w;
#endif #endif
#ifdef TYPE_SPRITE #ifdef TYPE_SPRITE
@@ -465,8 +465,6 @@ varying vec4 vTexCoord; // xy - atlas coords, zw - trapezoidal correction
fragColor = color; fragColor = color;
#ifdef TYPE_FLASH #ifdef TYPE_FLASH
fragColor.w = 0.0; fragColor.w = 0.0;
#else
fragColor.xyz *= fragColor.w;
#endif #endif
} }

View File

@@ -20,7 +20,6 @@ varying vec4 vColor;
void main() { void main() {
fragColor = texture2D(sDiffuse, vTexCoord) * vColor; fragColor = texture2D(sDiffuse, vTexCoord) * vColor;
fragColor.rgb *= fragColor.a;
} }
#endif #endif
)====" )===="