Skip to content

Commit 882a89d

Browse files
sofarparamat
authored andcommittedJan 20, 2016
Allow per-tiles culling.
Backface culling is enabled by default for all tiles, as this is how the lua parser initializes each tiledef. We revert to always using the value from the tiledef since it is always read and serialized. Mods that wish to enable culling for e.g. mesh nodes, now can specify the following to enable backface culling: tiles = {{ name = "tex.png", backface_culling = true }}, Note the double '{' and use of 'name' key here! In the same fashion, backface_culling can be disabled for any node now. I've tested this against the new door models and this properly allows me to disable culling per node. I've also tested this against my crops mod which uses mesh nodes where culling needs to be disabled, and tested also with plantlike drawtype nodes where we want this to continue to be disabled. No default setting has changed. The defaults are just migrated from nodedef.cpp to c_content.cpp.
1 parent 9f988e3 commit 882a89d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed
 

Diff for: ‎doc/lua_api.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ Definition tables
33583358
* `{name="image.png", animation={Tile Animation definition}}`
33593359
* `{name="image.png", backface_culling=bool, tileable_vertical=bool,
33603360
tileable_horizontal=bool}`
3361-
* backface culling only supported in special tiles.
3361+
* backface culling enabled by default for most nodes
33623362
* tileable flags are info for shaders, how they should treat texture
33633363
when displacement mapping is used
33643364
Directions are from the point of view of the tile texture,

Diff for: ‎src/nodedef.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,7 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
843843
assert(f->liquid_type == LIQUID_SOURCE);
844844
if (opaque_water)
845845
f->alpha = 255;
846-
if (new_style_water){
847-
f->solidness = 0;
848-
} else {
849-
f->solidness = 1;
850-
f->backface_culling = false;
851-
}
846+
f->solidness = new_style_water ? 0 : 1;
852847
is_liquid = true;
853848
break;
854849
case NDT_FLOWINGLIQUID:
@@ -899,17 +894,14 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
899894
break;
900895
case NDT_PLANTLIKE:
901896
f->solidness = 0;
902-
f->backface_culling = false;
903897
if (f->waving == 1)
904898
material_type = TILE_MATERIAL_WAVING_PLANTS;
905899
break;
906900
case NDT_FIRELIKE:
907-
f->backface_culling = false;
908901
f->solidness = 0;
909902
break;
910903
case NDT_MESH:
911904
f->solidness = 0;
912-
f->backface_culling = false;
913905
break;
914906
case NDT_TORCHLIKE:
915907
case NDT_SIGNLIKE:
@@ -941,7 +933,7 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
941933
// Tiles (fill in f->tiles[])
942934
for (u16 j = 0; j < 6; j++) {
943935
fillTileAttribs(tsrc, &f->tiles[j], &tiledef[j], tile_shader[j],
944-
use_normal_texture, f->backface_culling, f->alpha, material_type);
936+
use_normal_texture, f->tiledef[j].backface_culling, f->alpha, material_type);
945937
}
946938

947939
// Special tiles (fill in f->special_tiles[])

Diff for: ‎src/script/common/c_content.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,31 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
294294
index = lua_gettop(L) + 1 + index;
295295

296296
TileDef tiledef;
297-
bool default_tiling = (drawtype == NDT_PLANTLIKE || drawtype == NDT_FIRELIKE)
298-
? false : true;
297+
298+
bool default_tiling = true;
299+
bool default_culling = true;
300+
switch (drawtype) {
301+
case NDT_PLANTLIKE:
302+
case NDT_FIRELIKE:
303+
default_tiling = false;
304+
// "break" is omitted here intentionaly, as PLANTLIKE
305+
// FIRELIKE drawtype both should default to having
306+
// backface_culling to false.
307+
case NDT_MESH:
308+
case NDT_LIQUID:
309+
default_culling = false;
310+
break;
311+
default:
312+
break;
313+
}
314+
299315
// key at index -2 and value at index
300316
if(lua_isstring(L, index)){
301317
// "default_lava.png"
302318
tiledef.name = lua_tostring(L, index);
303319
tiledef.tileable_vertical = default_tiling;
304320
tiledef.tileable_horizontal = default_tiling;
321+
tiledef.backface_culling = default_culling;
305322
}
306323
else if(lua_istable(L, index))
307324
{
@@ -310,7 +327,7 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
310327
getstringfield(L, index, "name", tiledef.name);
311328
getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat.
312329
tiledef.backface_culling = getboolfield_default(
313-
L, index, "backface_culling", true);
330+
L, index, "backface_culling", default_culling);
314331
tiledef.tileable_horizontal = getboolfield_default(
315332
L, index, "tileable_horizontal", default_tiling);
316333
tiledef.tileable_vertical = getboolfield_default(

0 commit comments

Comments
 (0)
Please sign in to comment.