Tile material: Add 'TILE_MATERIAL_OPAQUE', use for drawtype 'NDT_NORMAL'

Prevents normal drawtype nodes having transparency.
Avoids clients cheating by using 'x-ray' texture packs with transparent textures.
master
stujones11 2017-06-07 18:52:38 +01:00 committed by paramat
parent f3ad75691a
commit 6e5588c8e1
3 changed files with 35 additions and 27 deletions

View File

@ -156,7 +156,8 @@ enum MaterialType{
TILE_MATERIAL_LIQUID_TRANSPARENT, TILE_MATERIAL_LIQUID_TRANSPARENT,
TILE_MATERIAL_LIQUID_OPAQUE, TILE_MATERIAL_LIQUID_OPAQUE,
TILE_MATERIAL_WAVING_LEAVES, TILE_MATERIAL_WAVING_LEAVES,
TILE_MATERIAL_WAVING_PLANTS TILE_MATERIAL_WAVING_PLANTS,
TILE_MATERIAL_OPAQUE
}; };
// Material flags // Material flags
@ -216,6 +217,10 @@ struct TileLayer
void applyMaterialOptions(video::SMaterial &material) const void applyMaterialOptions(video::SMaterial &material) const
{ {
switch (material_type) { switch (material_type) {
case TILE_MATERIAL_OPAQUE:
case TILE_MATERIAL_LIQUID_OPAQUE:
material.MaterialType = video::EMT_SOLID;
break;
case TILE_MATERIAL_BASIC: case TILE_MATERIAL_BASIC:
case TILE_MATERIAL_WAVING_LEAVES: case TILE_MATERIAL_WAVING_LEAVES:
case TILE_MATERIAL_WAVING_PLANTS: case TILE_MATERIAL_WAVING_PLANTS:
@ -225,9 +230,6 @@ struct TileLayer
case TILE_MATERIAL_LIQUID_TRANSPARENT: case TILE_MATERIAL_LIQUID_TRANSPARENT:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break; break;
case TILE_MATERIAL_LIQUID_OPAQUE:
material.MaterialType = video::EMT_SOLID;
break;
} }
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
? true : false; ? true : false;

View File

@ -690,6 +690,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
switch (drawtype) { switch (drawtype) {
default: default:
case NDT_NORMAL: case NDT_NORMAL:
material_type = (alpha == 255) ?
TILE_MATERIAL_OPAQUE : TILE_MATERIAL_ALPHA;
solidness = 2; solidness = 2;
break; break;
case NDT_AIRLIKE: case NDT_AIRLIKE:
@ -786,6 +788,16 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
tile_shader[j] = shdsrc->getShader("nodes_shader", tile_shader[j] = shdsrc->getShader("nodes_shader",
material_type, drawtype); material_type, drawtype);
} }
u8 overlay_material = material_type;
if (overlay_material == TILE_MATERIAL_OPAQUE)
overlay_material = TILE_MATERIAL_BASIC;
else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE)
overlay_material = TILE_MATERIAL_LIQUID_TRANSPARENT;
u32 overlay_shader[6];
for (u16 j = 0; j < 6; j++) {
overlay_shader[j] = shdsrc->getShader("nodes_shader",
overlay_material, drawtype);
}
// Tiles (fill in f->tiles[]) // Tiles (fill in f->tiles[])
for (u16 j = 0; j < 6; j++) { for (u16 j = 0; j < 6; j++) {
@ -794,8 +806,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
tdef[j].backface_culling, material_type); tdef[j].backface_culling, material_type);
if (tdef_overlay[j].name != "") if (tdef_overlay[j].name != "")
fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j], fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j],
tile_shader[j], tsettings.use_normal_texture, overlay_shader[j], tsettings.use_normal_texture,
tdef[j].backface_culling, material_type); tdef[j].backface_culling, overlay_material);
} }
// Special tiles (fill in f->special_tiles[]) // Special tiles (fill in f->special_tiles[])

View File

@ -531,26 +531,19 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaderinfo.drawtype = drawtype; shaderinfo.drawtype = drawtype;
shaderinfo.material = video::EMT_SOLID; shaderinfo.material = video::EMT_SOLID;
switch (material_type) { switch (material_type) {
case TILE_MATERIAL_BASIC: case TILE_MATERIAL_OPAQUE:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
case TILE_MATERIAL_ALPHA:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
case TILE_MATERIAL_LIQUID_TRANSPARENT:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
case TILE_MATERIAL_LIQUID_OPAQUE: case TILE_MATERIAL_LIQUID_OPAQUE:
shaderinfo.base_material = video::EMT_SOLID; shaderinfo.base_material = video::EMT_SOLID;
break; break;
case TILE_MATERIAL_WAVING_LEAVES: case TILE_MATERIAL_ALPHA:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; case TILE_MATERIAL_LIQUID_TRANSPARENT:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break; break;
case TILE_MATERIAL_BASIC:
case TILE_MATERIAL_WAVING_LEAVES:
case TILE_MATERIAL_WAVING_PLANTS: case TILE_MATERIAL_WAVING_PLANTS:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break; break;
default:
break;
} }
bool enable_shaders = g_settings->getBool("enable_shaders"); bool enable_shaders = g_settings->getBool("enable_shaders");
@ -642,7 +635,8 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
"TILE_MATERIAL_LIQUID_TRANSPARENT", "TILE_MATERIAL_LIQUID_TRANSPARENT",
"TILE_MATERIAL_LIQUID_OPAQUE", "TILE_MATERIAL_LIQUID_OPAQUE",
"TILE_MATERIAL_WAVING_LEAVES", "TILE_MATERIAL_WAVING_LEAVES",
"TILE_MATERIAL_WAVING_PLANTS" "TILE_MATERIAL_WAVING_PLANTS",
"TILE_MATERIAL_OPAQUE"
}; };
for (int i = 0; i < 6; i++){ for (int i = 0; i < 6; i++){