Skip to content

Commit

Permalink
Fix TMD shader (B+F)/2 translucency (closes #1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMonoxide committed Dec 6, 2024
1 parent 505bd2a commit 03a4746
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions gfx/shaders/battle_tmd.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
bool textured = (vertFlags & 0x2) != 0;
outColour = vertColour;

int translucencyMode = translucency;
int translucencyMode = translucency + 1;
if(translucent && (!textured || uniformLit)) {
translucencyMode = tmdTranslucency + 1;
}
Expand All @@ -74,22 +74,22 @@ void main() {
}

// If translucent primitive and texture pixel translucency bit is set, pixel is translucent so we defer rendering
if(discardTranslucency == 1 && translucencyMode != 0 && texColour.a != 0 || discardTranslucency == 2 && (translucencyMode == 0 || texColour.a == 0)) {
if(discardTranslucency == 1 && translucent && texColour.a != 0 || discardTranslucency == 2 && (!translucent || texColour.a == 0)) {
discard;
}

outColour *= texColour;
} else {
// Untextured translucent primitives don't have a translucency bit so we always discard during the appropriate discard modes
if(discardTranslucency == 1 && translucencyMode != 0 || discardTranslucency == 2 && translucencyMode == 0) {
if(discardTranslucency == 1 && translucent || discardTranslucency == 2 && !translucent) {
discard;
}
}

outColour.rgb *= recolour;

// The or condition is to disable translucency if a texture's pixel has alpha disabled
if(translucencyMode == 1 && (!textured || outColour.a != 0)) { // (B+F)/2 translucency
if(translucencyMode == 0 && (!textured || outColour.a != 0)) { // (B+F)/2 translucency
outColour.a = 0.5;
} else {
outColour.a = 1.0;
Expand Down
8 changes: 4 additions & 4 deletions gfx/shaders/tmd.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {

int translucencyMode = translucency;
if(translucent && !textured) {
translucencyMode = tmdTranslucency + 1;
translucencyMode = tmdTranslucency;
}

// Textured
Expand All @@ -71,22 +71,22 @@ void main() {
}

// If translucent primitive and texture pixel translucency bit is set, pixel is translucent so we defer rendering
if(discardTranslucency == 1 && translucencyMode != 0 && texColour.a != 0 || discardTranslucency == 2 && (translucencyMode == 0 || texColour.a == 0)) {
if(discardTranslucency == 1 && translucent && texColour.a != 0 || discardTranslucency == 2 && (!translucent || texColour.a == 0)) {
discard;
}

outColour *= texColour;
} else {
// Untextured translucent primitives don't have a translucency bit so we always discard during the appropriate discard modes
if(discardTranslucency == 1 && translucencyMode != 0 || discardTranslucency == 2 && translucencyMode == 0) {
if(discardTranslucency == 1 && translucent || discardTranslucency == 2 && !translucent) {
discard;
}
}

outColour.rgb *= recolour;

// The or condition is to disable translucency if a texture's pixel has alpha disabled
if(translucencyMode == 1 && (!textured || outColour.a != 0)) { // (B+F)/2 translucency
if(translucencyMode == 0 && (!textured || outColour.a != 0)) { // (B+F)/2 translucency
outColour.a = 0.5;
} else {
outColour.a = 1.0;
Expand Down

0 comments on commit 03a4746

Please sign in to comment.