more emissive and glow codes that fixes glow/emsv-seen-thru-foreground

This commit is contained in:
minjaesong
2024-01-27 04:32:42 +09:00
parent b1ca1a9351
commit fd8cdb94bc
33 changed files with 116 additions and 69 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -14,6 +14,10 @@ import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.savegame.ByteArray64Reader import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.EntryID import net.torvald.terrarum.savegame.EntryID
import net.torvald.terrarum.savegame.SimpleFileSystem import net.torvald.terrarum.savegame.SimpleFileSystem
import net.torvald.terrarum.savegame.VDFileID
import net.torvald.terrarum.savegame.VDFileID.BODYPARTEMISSIVE_TO_ENTRY_MAP
import net.torvald.terrarum.savegame.VDFileID.BODYPARTGLOW_TO_ENTRY_MAP
import net.torvald.terrarum.savegame.VDFileID.BODYPART_TO_ENTRY_MAP
import net.torvald.terrarum.serialise.Common import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.spriteassembler.ADProperties import net.torvald.terrarum.spriteassembler.ADProperties
import net.torvald.terrarum.spriteassembler.ADPropertyObject import net.torvald.terrarum.spriteassembler.ADPropertyObject
@@ -31,12 +35,19 @@ class AssembledSpriteAnimation(
@Transient val adp: ADProperties, @Transient val adp: ADProperties,
parentActor: ActorWithBody, parentActor: ActorWithBody,
@Transient val disk: SimpleFileSystem?, // specify if the resources for the animation is contained in the disk archive @Transient val disk: SimpleFileSystem?, // specify if the resources for the animation is contained in the disk archive
@Transient val bodypartToFileMap: EntryID?, // which file in the disk contains bodypart-to-fileid mapping for this particular instance of sprite animation
@Transient val isGlow: Boolean, @Transient val isGlow: Boolean,
@Transient val isEmissive: Boolean @Transient val isEmissive: Boolean
) : SpriteAnimation(parentActor) { ) : SpriteAnimation(parentActor) {
constructor(adp: ADProperties, parentActor: ActorWithBody, isGlow: Boolean, isEmissive: Boolean) : this(adp, parentActor, null, null, isGlow, isEmissive) constructor(adp: ADProperties, parentActor: ActorWithBody, isGlow: Boolean, isEmissive: Boolean) : this(adp, parentActor, null, isGlow, isEmissive)
@Transient val bodypartToFileMap = if (isEmissive)
BODYPARTEMISSIVE_TO_ENTRY_MAP
else if (isGlow)
BODYPARTGLOW_TO_ENTRY_MAP
else
BODYPART_TO_ENTRY_MAP
var currentFrame = 0 // while this number is zero-based, the frame number on the ADP is one-based var currentFrame = 0 // while this number is zero-based, the frame number on the ADP is one-based
private set private set
@@ -69,13 +80,21 @@ class AssembledSpriteAnimation(
val fileGetter = if (disk != null) { val fileGetter = if (disk != null) {
val bodypartMapping = Properties() val bodypartMapping = Properties()
bodypartMapping.load(ByteArray64Reader(disk.getFile(bodypartToFileMap!!)!!.bytes, Common.CHARSET)) bodypartMapping.load(ByteArray64Reader(disk.getFile(bodypartToFileMap)!!.bytes, Common.CHARSET))
AssembleSheetPixmap.getVirtualDiskFileGetter(bodypartMapping, disk) AssembleSheetPixmap.getVirtualDiskFileGetter(bodypartMapping, disk)
} }
else AssembleSheetPixmap.getAssetsDirFileGetter(adp) else AssembleSheetPixmap.getAssetsDirFileGetter(adp)
adp.bodyparts.forEach { res[it] = getPartTexture(fileGetter, it) } val fileGetterFallback = if (disk != null) {
val bodypartMapping = Properties()
bodypartMapping.load(ByteArray64Reader(disk.getFile(BODYPART_TO_ENTRY_MAP)!!.bytes, Common.CHARSET))
AssembleSheetPixmap.getVirtualDiskFileGetter(bodypartMapping, disk)
}
else AssembleSheetPixmap.getAssetsDirFileGetter(adp)
adp.bodyparts.forEach { res[it] = getPartTexture(fileGetter, fileGetterFallback, it) }
val (mugPixmap, headSprite0) = if (disk != null) val (mugPixmap, headSprite0) = if (disk != null)
AssembleSheetPixmap.getMugshotFromVirtualDisk(disk, -1025L, adp) AssembleSheetPixmap.getMugshotFromVirtualDisk(disk, -1025L, adp)
@@ -225,11 +244,25 @@ class AssembledSpriteAnimation(
// TODO fill in with armours/etc // TODO fill in with armours/etc
) )
private fun getPartTexture(getFile: (String) -> InputStream?, partName: String): TextureRegion? { private fun getPartTexture(getFile: (String) -> InputStream?, getFileFallback: (String) -> InputStream?, partName: String): TextureRegion? {
getFile(partName)?.let { getFile(partName)?.let {
val bytes = it.readAllBytes() val bytes = it.readAllBytes()
return TextureRegion(Texture(Pixmap(bytes, 0, bytes.size))) return TextureRegion(Texture(Pixmap(bytes, 0, bytes.size)))
} }
getFileFallback(partName)?.let {
val bytes = it.readAllBytes()
// filter the image so that it's either transparent or black
val pixmap = Pixmap(bytes, 0, bytes.size)
for (y in 0 until pixmap.height) {
for (x in 0 until pixmap.width) {
val c = pixmap.getPixel(x, y)
pixmap.drawPixel(x, y, c and 0xFF)
}
}
return TextureRegion(Texture(pixmap))
}
return null return null
} }
} }

View File

@@ -1796,8 +1796,8 @@ open class ActorWithBody : Actor {
if (isVisible) { if (isVisible) {
blendNormalStraightAlpha(batch) blendNormalStraightAlpha(batch)
if (spriteGlow != null) if (spriteGlow != null)
drawSpriteInGoodPosition(frameDelta, spriteGlow!!, batch, 2) drawSpriteInGoodPosition(frameDelta, spriteGlow!!, batch, 1)
else else if (sprite != null)
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 1, Color.BLACK) drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 1, Color.BLACK)
} }
} }
@@ -1807,7 +1807,7 @@ open class ActorWithBody : Actor {
blendNormalStraightAlpha(batch) blendNormalStraightAlpha(batch)
if (spriteEmissive != null) if (spriteEmissive != null)
drawSpriteInGoodPosition(frameDelta, spriteEmissive!!, batch, 1) drawSpriteInGoodPosition(frameDelta, spriteEmissive!!, batch, 1)
else else if (sprite != null)
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 2, Color.BLACK) drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 2, Color.BLACK)
} }
} }

View File

@@ -179,7 +179,6 @@ object ReadActor {
actor.animDesc!!, actor.animDesc!!,
actor, actor,
if (bodypartsFile != null) disk else null, if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPART_TO_ENTRY_MAP else null,
false, false false, false
) )
@@ -189,7 +188,6 @@ object ReadActor {
actor.animDescGlow!!, actor.animDescGlow!!,
actor, actor,
if (bodypartsFile != null) disk else null, if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPARTGLOW_TO_ENTRY_MAP else null,
true, false true, false
) )
} }
@@ -200,7 +198,6 @@ object ReadActor {
actor.animDescEmissive!!, actor.animDescEmissive!!,
actor, actor,
if (bodypartsFile != null) disk else null, if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPARTEMISSIVE_TO_ENTRY_MAP else null,
false, true false, true
) )
} }
@@ -223,50 +220,4 @@ object ReadActor {
} }
} }
private fun makeSprite(mode: Int, actor: IngamePlayer, disk: SimpleFileSystem, file: EntryFile?, bodypartsFile: EntryFile?) {
val animDesc = when (mode) {
0 -> actor.animDesc
1 -> actor.animDescGlow
2 -> actor.animDescEmissive
else -> throw IllegalArgumentException()
}
if (file != null) {
when (mode) {
0 -> { actor.animDesc = ADProperties(ByteArray64Reader(file.bytes, Common.CHARSET)) }
1 -> { actor.animDescGlow = ADProperties(ByteArray64Reader(file.bytes, Common.CHARSET)) }
2 -> { actor.animDescEmissive = ADProperties(ByteArray64Reader(file.bytes, Common.CHARSET)) }
else -> throw IllegalArgumentException()
}
when (mode) {
0 -> { actor.sprite = AssembledSpriteAnimation(
actor.animDesc!!,
actor,
if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPART_TO_ENTRY_MAP else null,
false, false
) }
1 -> { actor.spriteGlow = AssembledSpriteAnimation(
actor.animDescGlow!!,
actor,
if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPARTGLOW_TO_ENTRY_MAP else null,
true, false
) }
2 -> { actor.spriteEmissive = AssembledSpriteAnimation(
actor.animDescEmissive!!,
actor,
if (bodypartsFile != null) disk else null,
if (bodypartsFile != null) BODYPARTEMISSIVE_TO_ENTRY_MAP else null,
false, true
) }
else -> throw IllegalArgumentException()
}
}
else {
}
}
} }

View File

@@ -16,6 +16,5 @@ const vec2 boolean = vec2(0.0, 1.0);
void main(void) { void main(void) {
vec4 colorTex0 = texture(u_texture, v_texCoords); // lightmap (RGB) pre-mixed vec4 colorTex0 = texture(u_texture, v_texCoords); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture(tex1, v_texCoords); // lightmap (A) pre-mixed vec4 colorTex1 = texture(tex1, v_texCoords); // lightmap (A) pre-mixed
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + (colorTex0 * boolean.xxxy);
fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex0 * boolean.xxxy); fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex0 * boolean.xxxy);
} }

View File

@@ -16,6 +16,10 @@ const vec2 boolean = vec2(0.0, 1.0);
void main(void) { void main(void) {
vec4 colorTex0 = texture(u_texture, v_texCoords); // lightmap (RGB) pre-mixed vec4 colorTex0 = texture(u_texture, v_texCoords); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture(tex1, vec2(v_texCoords.x, 1.0 - v_texCoords.y)); // lightmap (A) pre-mixed vec4 colorTex1 = texture(tex1, vec2(v_texCoords.x, 1.0 - v_texCoords.y)); // lightmap (A) pre-mixed
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + (colorTex0 * boolean.xxxy); // if (colorTex0.a > colorTex1.a) {
fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex0 * boolean.xxxy); fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex0 * boolean.xxxy);
// }
// else {
// fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex1 * boolean.xxxy);
// }
} }