Skip to content

Commit 75c393c

Browse files
juhdanadnerzhul
authored andcommittedMay 19, 2017
Fix alpha for liquid nodes (#5494)
1 parent 6744005 commit 75c393c

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed
 

‎src/nodedef.cpp

+29-22
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,18 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
469469
writeU8(os, legacy_wallmounted);
470470
}
471471

472-
void ContentFeatures::correctAlpha()
472+
void ContentFeatures::correctAlpha(TileDef *tiles, int length)
473473
{
474+
// alpha == 0 means that the node is using texture alpha
474475
if (alpha == 0 || alpha == 255)
475476
return;
476477

477-
for (u32 i = 0; i < 6; i++) {
478-
std::stringstream s;
479-
s << tiledef[i].name << "^[noalpha^[opacity:" << ((int)alpha);
480-
tiledef[i].name = s.str();
481-
}
482-
483-
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++) {
478+
for (int i = 0; i < length; i++) {
479+
if (tiles[i].name == "")
480+
continue;
484481
std::stringstream s;
485-
s << tiledef_special[i].name << "^[noalpha^[opacity:" << ((int)alpha);
486-
tiledef_special[i].name = s.str();
482+
s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha);
483+
tiles[i].name = s.str();
487484
}
488485
}
489486

@@ -668,6 +665,14 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
668665
if (tdef[j].name == "")
669666
tdef[j].name = "unknown_node.png";
670667
}
668+
// also the overlay tiles
669+
TileDef tdef_overlay[6];
670+
for (u32 j = 0; j < 6; j++)
671+
tdef_overlay[j] = tiledef_overlay[j];
672+
// also the special tiles
673+
TileDef tdef_spec[6];
674+
for (u32 j = 0; j < CF_SPECIAL_COUNT; j++)
675+
tdef_spec[j] = tiledef_special[j];
671676

672677
bool is_liquid = false;
673678

@@ -720,8 +725,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
720725
visual_solidness = 1;
721726
} else if (tsettings.leaves_style == LEAVES_SIMPLE) {
722727
for (u32 j = 0; j < 6; j++) {
723-
if (tiledef_special[j].name != "")
724-
tdef[j].name = tiledef_special[j].name;
728+
if (tdef_spec[j].name != "")
729+
tdef[j].name = tdef_spec[j].name;
725730
}
726731
drawtype = NDT_GLASSLIKE;
727732
solidness = 0;
@@ -759,12 +764,14 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
759764
break;
760765
}
761766

762-
if (is_liquid)
767+
if (is_liquid) {
768+
// Vertex alpha is no longer supported, correct if necessary.
769+
correctAlpha(tdef, 6);
770+
correctAlpha(tdef_overlay, 6);
771+
correctAlpha(tdef_spec, CF_SPECIAL_COUNT);
763772
material_type = (alpha == 255) ?
764773
TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
765-
766-
// Vertex alpha is no longer supported, correct if necessary.
767-
correctAlpha();
774+
}
768775

769776
u32 tile_shader[6];
770777
for (u16 j = 0; j < 6; j++) {
@@ -776,18 +783,18 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
776783
for (u16 j = 0; j < 6; j++) {
777784
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader[j],
778785
tsettings.use_normal_texture,
779-
tiledef[j].backface_culling, material_type);
780-
if (tiledef_overlay[j].name!="")
781-
fillTileAttribs(tsrc, &tiles[j].layers[1], &tiledef_overlay[j],
786+
tdef[j].backface_culling, material_type);
787+
if (tdef_overlay[j].name != "")
788+
fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j],
782789
tile_shader[j], tsettings.use_normal_texture,
783-
tiledef[j].backface_culling, material_type);
790+
tdef[j].backface_culling, material_type);
784791
}
785792

786793
// Special tiles (fill in f->special_tiles[])
787794
for (u16 j = 0; j < CF_SPECIAL_COUNT; j++) {
788-
fillTileAttribs(tsrc, &special_tiles[j].layers[0], &tiledef_special[j],
795+
fillTileAttribs(tsrc, &special_tiles[j].layers[0], &tdef_spec[j],
789796
tile_shader[j], tsettings.use_normal_texture,
790-
tiledef_special[j].backface_culling, material_type);
797+
tdef_spec[j].backface_culling, material_type);
791798
}
792799

793800
if (param_type_2 == CPT2_COLOR ||

‎src/nodedef.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ struct ContentFeatures
382382
void serializeOld(std::ostream &os, u16 protocol_version) const;
383383
void deSerializeOld(std::istream &is, int version);
384384
/*!
385-
* Since vertex alpha is no lnger supported, this method
386-
* adds instructions to the texture names to blend alpha there.
385+
* Since vertex alpha is no longer supported, this method
386+
* adds opacity directly to the texture pixels.
387387
*
388-
* tiledef, tiledef_special and alpha must be initialized
389-
* before calling this.
388+
* \param tiles array of the tile definitions.
389+
* \param length length of tiles
390390
*/
391-
void correctAlpha();
391+
void correctAlpha(TileDef *tiles, int length);
392392

393393
/*
394394
Some handy methods

0 commit comments

Comments
 (0)
Please sign in to comment.