voxel render 0.78; compile as C++, fix bad #else
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parent abf217d · Browse files · 3 files·+628 added−668 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+628 added−668 removed
- tests:+3 added−0 removed
- other:+625 added−668 removed
Provenance
- Commit
cd1d05b- Tree
3a430ab- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent
abf217d
3 files changed+628 added−668 removed
modified:tests/test_cpp_compilation.cpp+3 added
5 unmodified lines6 #define STB_DIVIDE_IMPLEMENTATION7 #define STB_IMAGE_IMPLEMENTATION8 #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION9 #define STB_RECT_PACK_IMPLEMENTATION10+#define STB_VOXEL_RENDER_IMPLEMENTATION11+#define STBVOX_CONFIG_MODE 112 13 #define STBI_MALLOC my_malloc14 #define STBI_FREE my_free15 #define STBI_REALLOC my_realloc10 unmodified lines26 #include "stb_dxt.h"27 #include "stb_c_lexer.h"28 #include "stb_divide.h"29 #include "stb_herringbone_wang_tile.h"30+#include "stb_voxel_render.h"31 32 #define STBTE_DRAW_RECT(x0,y0,x1,y1,color) do ; while(0)33 #define STBTE_DRAW_TILE(x,y,id,highlight,data) do ; while(0)34 #define STB_TILEMAP_EDITOR_IMPLEMENTATION1 unmodified linemodified:README.md+1 added-1 removed
11 unmodified lines1213141516161718192084 unmodified lines11 unmodified lines**stb_image_resize.h** | 0.90 | graphics | resize images larger/smaller with good quality**stb_rect_pack.h** | 0.05 | graphics | simple 2D rectangle packer with decent quality**stretchy_buffer.h** | 1.01 | utility | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++**stb_textedit.h** | 1.5 | UI | guts of a text editor for games etc implementing them from scratch**stb_voxel_render.h** | 0.77 | 3D graphics | Minecraft-esque voxel rendering "engine" with many more features**stb_voxel_render.h** | 0.78 | 3D graphics | Minecraft-esque voxel rendering "engine" with many more features**stb_dxt.h** | 1.04 | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor**stb_perlin.h** | 0.2 | 3D graphics | revised Perlin noise (3D input, 1D output)**stb_easy_font.h** | 0.5 | 3D graphics | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc**stb_tilemap_editor.h** | 0.30 | game development | embeddable tilemap editor84 unmodified linesmodified:stb_voxel_render.h+624 added-667 removed
1-// stb_voxel_render.h - v0.77 - Sean Barrett, 2015 - public domain1+// stb_voxel_render.h - v0.78 - Sean Barrett, 2015 - public domain2 //3 // This library helps render large-scale "voxel" worlds for games,4 // in this case, one with blocks that can have textures and that5 // can also be a few shapes other than cubes.65 unmodified lines71 // - indexed-by-texture-id scale factor (separate for texture #1 and texture #2)72 // - indexed-by-texture-#2-id blend mode (alpha composite or modulate/multiply);73 // the first is good for decals, the second for detail textures, "light maps",74 // etc; both modes are controlled by texture #2's alpha, scaled by the75-// per-vertex texture crossfade and the per-face color (if enabled on texture #2)75+// per-vertex texture crossfade and the per-face color (if enabled on texture #2);76+// modulate/multiply multiplies by an extra factor of 2.0 so that if you77+// make detail maps whose average brightness is 0.5 everything works nicely.78 //79 // - ambient lighting: half-lambert directional plus constant, all scaled by vertex ao80 // - face can be fullbright (emissive), controlled by per-face color81 // - installable lighting, with default single-point-light87 unmodified lines169 // CONTRIBUTORS170 //171 // Features Porting Bugfixes & Warnings172 // Sean Barrett github:r-leyh Jesus Fernandez171-// Miguel Lechon173+// Miguel Lechon github:Arbeiterunfallversicherungsgesetz174 //175 // VERSION HISTORY176 //177+// 0.78 bad "#else", compile as C++178 // 0.77 documentation tweaks, rename config var to STB_VOXEL_RENDER_STATIC179 // 0.76 typos, signed/unsigned shader issue, more documentation180 // 0.75 initial release181 //984 unmodified lines1166 #elif defined(STBVOX_ICONFIG_VERTEX_16_2) // mode=31167 typedef stbvox_uint16 stbvox_mesh_vertex;1168 #define stbvox_vertex_encode(x,y,z,ao,texlerp) \1169 ((stbvox_uint16) ((x)+((z)<<6))+((ao)<<10))1167-#else defined(STBVOX_ICONFIG_VERTEX_8)1170+#elif defined(STBVOX_ICONFIG_VERTEX_8)1171 typedef stbvox_uint8 stbvox_mesh_vertex;1172 #define stbvox_vertex_encode(x,y,z,ao,texlerp) \1173 ((stbvox_uint8) ((z)+((ao)<<6))1174 #else82 unmodified lines1257 1258 STBVF_count,1259 };1260 1258-// get opposite-facing normal & texgen for opposite face, used to map up-facing vheight data to down-facing data1259-static unsigned char stbvox_reverse_face[STBVF_count];1260-static float stbvox_default_texgen[2][32][3];1261-static float stbvox_default_normals[32][3];1262-static float stbvox_default_texscale[128][4];1261+/////////////////////////////////////////////////////////////////////////////1262+//1263+// tables -- i'd prefer if these were at the end of the file, but: C++1264+//1265+1266+static float stbvox_default_texgen[2][32][3] =1267+{1268+ { { 0, 1,0 }, { 0, 0, 1 }, { 0,-1,0 }, { 0, 0,-1 },1269+ { -1, 0,0 }, { 0, 0, 1 }, { 1, 0,0 }, { 0, 0,-1 },1270+ { 0,-1,0 }, { 0, 0, 1 }, { 0, 1,0 }, { 0, 0,-1 },1271+ { 1, 0,0 }, { 0, 0, 1 }, { -1, 0,0 }, { 0, 0,-1 },1272+1273+ { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 },1274+ { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 },1275+ { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 },1276+ { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 },1277+ },1278+ { { 0, 0,-1 }, { 0, 1,0 }, { 0, 0, 1 }, { 0,-1,0 },1279+ { 0, 0,-1 }, { -1, 0,0 }, { 0, 0, 1 }, { 1, 0,0 },1280+ { 0, 0,-1 }, { 0,-1,0 }, { 0, 0, 1 }, { 0, 1,0 },1281+ { 0, 0,-1 }, { 1, 0,0 }, { 0, 0, 1 }, { -1, 0,0 },1282+1283+ { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 },1284+ { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 },1285+ { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 },1286+ { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 },1287+ },1288+};1289+1290+#define STBVOX_RSQRT2 0.7071067811865f1291+#define STBVOX_RSQRT3 0.5773502691896f1292+1293+static float stbvox_default_normals[32][3] =1294+{1295+ { 1,0,0 }, // east1296+ { 0,1,0 }, // north1297+ { -1,0,0 }, // west1298+ { 0,-1,0 }, // south1299+ { 0,0,1 }, // up1300+ { 0,0,-1 }, // down1301+ { STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // east & up1302+ { STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // east & down1303+1304+ { STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // east & up1305+ { 0, STBVOX_RSQRT2, STBVOX_RSQRT2 }, // north & up1306+ { -STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // west & up1307+ { 0,-STBVOX_RSQRT2, STBVOX_RSQRT2 }, // south & up1308+ { STBVOX_RSQRT3, STBVOX_RSQRT3, STBVOX_RSQRT3 }, // ne & up1309+ { STBVOX_RSQRT3, STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // ne & down1310+ { 0, STBVOX_RSQRT2, STBVOX_RSQRT2 }, // north & up1311+ { 0, STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // north & down1312+1313+ { STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // east & down1314+ { 0, STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // north & down1315+ { -STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // west & down1316+ { 0,-STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // south & down1317+ { -STBVOX_RSQRT3, STBVOX_RSQRT3, STBVOX_RSQRT3 }, // NW & up1318+ { -STBVOX_RSQRT3, STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // NW & down1319+ { -STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // west & up1320+ { -STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // west & down1321+1322+ { STBVOX_RSQRT3, STBVOX_RSQRT3,STBVOX_RSQRT3 }, // NE & up crossed1323+ { -STBVOX_RSQRT3, STBVOX_RSQRT3,STBVOX_RSQRT3 }, // NW & up crossed1324+ { -STBVOX_RSQRT3,-STBVOX_RSQRT3,STBVOX_RSQRT3 }, // SW & up crossed1325+ { STBVOX_RSQRT3,-STBVOX_RSQRT3,STBVOX_RSQRT3 }, // SE & up crossed1326+ { -STBVOX_RSQRT3,-STBVOX_RSQRT3, STBVOX_RSQRT3 }, // SW & up1327+ { -STBVOX_RSQRT3,-STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // SW & up1328+ { 0,-STBVOX_RSQRT2, STBVOX_RSQRT2 }, // south & up1329+ { 0,-STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // south & down1330+};1331+1332+static float stbvox_default_texscale[128][4] =1333+{1334+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1335+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1336+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1337+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1338+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1339+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1340+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1341+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1342+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1343+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1344+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1345+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1346+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1347+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1348+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1349+ {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},1350+};1351+1352+static unsigned char stbvox_default_palette_compact[64][3] =1353+{1354+ { 255,255,255 }, { 238,238,238 }, { 221,221,221 }, { 204,204,204 },1355+ { 187,187,187 }, { 170,170,170 }, { 153,153,153 }, { 136,136,136 },1356+ { 119,119,119 }, { 102,102,102 }, { 85, 85, 85 }, { 68, 68, 68 },1357+ { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 },1358+ { 255,240,240 }, { 255,220,220 }, { 255,160,160 }, { 255, 32, 32 },1359+ { 200,120,160 }, { 200, 60,150 }, { 220,100,130 }, { 255, 0,128 },1360+ { 240,240,255 }, { 220,220,255 }, { 160,160,255 }, { 32, 32,255 },1361+ { 120,160,200 }, { 60,150,200 }, { 100,130,220 }, { 0,128,255 },1362+ { 240,255,240 }, { 220,255,220 }, { 160,255,160 }, { 32,255, 32 },1363+ { 160,200,120 }, { 150,200, 60 }, { 130,220,100 }, { 128,255, 0 },1364+ { 255,255,240 }, { 255,255,220 }, { 220,220,180 }, { 255,255, 32 },1365+ { 200,160,120 }, { 200,150, 60 }, { 220,130,100 }, { 255,128, 0 },1366+ { 255,240,255 }, { 255,220,255 }, { 220,180,220 }, { 255, 32,255 },1367+ { 160,120,200 }, { 150, 60,200 }, { 130,100,220 }, { 128, 0,255 },1368+ { 240,255,255 }, { 220,255,255 }, { 180,220,220 }, { 32,255,255 },1369+ { 120,200,160 }, { 60,200,150 }, { 100,220,130 }, { 0,255,128 },1370+};1371+1372 static float stbvox_default_ambient[4][4] =1373 {1374 { 0,0,1 ,0 }, // reversed lighting direction1375 { 0.5,0.5,0.5,0 }, // directional color1376 { 0.5,0.5,0.5,0 }, // constant color1377 { 0.5,0.5,0.5,1.0f/1000.0f/1000.0f }, // fog data for simple_fog1378 };1379 1271-static unsigned char stbvox_default_palette_compact[64][3];1380 static float stbvox_default_palette[64][4];1381 1382 static void stbvox_build_default_palette(void)1383 {104 unmodified lines1488 // rlerp is lerp but with t on the left, like god intended1489 #if defined(STBVOX_ICONFIG_GLSL)1490 "#define rlerp(t,x,y) mix(x,y,t)\n"1491 #elif defined(STBVOX_CONFIG_HLSL)1384- "#define rlerp(t,x,y) lerp(x,t,y)\n"1492+ "#define rlerp(t,x,y) lerp(x,y,t)\n"1493 #else1494 #error "need definition of rlerp()"1495 #endif1496 482 unmodified lines1979 face_data.face_info = (normal<<2) + facerot;1980 return face_data;1981 }1982 1983+// these are the types of faces each block can have1984+enum1985+{1986+ STBVOX_FT_none ,1987+ STBVOX_FT_upper ,1988+ STBVOX_FT_lower ,1989+ STBVOX_FT_solid ,1990+ STBVOX_FT_diag_012,1991+ STBVOX_FT_diag_023,1992+ STBVOX_FT_diag_013,1993+ STBVOX_FT_diag_123,1994+ STBVOX_FT_force , // can't be covered up, used for internal faces, also hides nothing1995+ STBVOX_FT_partial , // only covered by solid, never covers anything else1996+1997+ STBVOX_FT_count1998+};1999+2000 static unsigned char stbvox_face_lerp[6] = { 0,2,0,2,4,4 };2001 static unsigned char stbvox_vert3_lerp[5] = { 0,3,6,9,12 };2002 static unsigned char stbvox_vert_lerp_for_face_lerp[4] = { 0, 4, 7, 7 };2003 static unsigned char stbvox_face3_lerp[6] = { 0,3,6,9,12,14 };2004 static unsigned char stbvox_vert_lerp_for_simple[4] = { 0,2,5,7 };2005 static unsigned char stbvox_face3_updown[8] = { 0,2,5,7,0,2,5,7 }; // ignore top bit2006+2007 // vertex offsets for face vertices1882-static unsigned char stbvox_vertex_vector[6][4][3];1883-static stbvox_mesh_vertex stbvox_vmesh_delta_normal[6][4];1884-static stbvox_mesh_vertex stbvox_vmesh_pre_vheight[6][4];1885-static stbvox_mesh_vertex stbvox_vmesh_delta_half_z[6][4];1886-static stbvox_mesh_vertex stbvox_vmesh_crossed_pair[6][4];2008+static unsigned char stbvox_vertex_vector[6][4][3] =2009+{2010+ { { 1,0,1 }, { 1,1,1 }, { 1,1,0 }, { 1,0,0 } }, // east2011+ { { 1,1,1 }, { 0,1,1 }, { 0,1,0 }, { 1,1,0 } }, // north2012+ { { 0,1,1 }, { 0,0,1 }, { 0,0,0 }, { 0,1,0 } }, // west2013+ { { 0,0,1 }, { 1,0,1 }, { 1,0,0 }, { 0,0,0 } }, // south2014+ { { 0,1,1 }, { 1,1,1 }, { 1,0,1 }, { 0,0,1 } }, // up2015+ { { 0,0,0 }, { 1,0,0 }, { 1,1,0 }, { 0,1,0 } }, // down2016+};2017 2018 // stbvox_vertex_vector, but read coordinates as binary numbers, zyx1889-static unsigned char stbvox_vertex_selector[6][4];2019+static unsigned char stbvox_vertex_selector[6][4] =2020+{2021+ { 5,7,3,1 },2022+ { 7,6,2,3 },2023+ { 6,4,0,2 },2024+ { 4,5,1,0 },2025+ { 6,7,5,4 },2026+ { 0,1,3,2 },2027+};2028 2029+static stbvox_mesh_vertex stbvox_vmesh_delta_normal[6][4] =2030+{2031+ { stbvox_vertex_encode(1,0,1,0,0) , 2032+ stbvox_vertex_encode(1,1,1,0,0) ,2033+ stbvox_vertex_encode(1,1,0,0,0) ,2034+ stbvox_vertex_encode(1,0,0,0,0) },2035+ { stbvox_vertex_encode(1,1,1,0,0) ,2036+ stbvox_vertex_encode(0,1,1,0,0) ,2037+ stbvox_vertex_encode(0,1,0,0,0) ,2038+ stbvox_vertex_encode(1,1,0,0,0) },2039+ { stbvox_vertex_encode(0,1,1,0,0) ,2040+ stbvox_vertex_encode(0,0,1,0,0) ,2041+ stbvox_vertex_encode(0,0,0,0,0) ,2042+ stbvox_vertex_encode(0,1,0,0,0) },2043+ { stbvox_vertex_encode(0,0,1,0,0) ,2044+ stbvox_vertex_encode(1,0,1,0,0) ,2045+ stbvox_vertex_encode(1,0,0,0,0) ,2046+ stbvox_vertex_encode(0,0,0,0,0) },2047+ { stbvox_vertex_encode(0,1,1,0,0) ,2048+ stbvox_vertex_encode(1,1,1,0,0) ,2049+ stbvox_vertex_encode(1,0,1,0,0) ,2050+ stbvox_vertex_encode(0,0,1,0,0) },2051+ { stbvox_vertex_encode(0,0,0,0,0) ,2052+ stbvox_vertex_encode(1,0,0,0,0) ,2053+ stbvox_vertex_encode(1,1,0,0,0) ,2054+ stbvox_vertex_encode(0,1,0,0,0) }2055+};2056+2057+static stbvox_mesh_vertex stbvox_vmesh_pre_vheight[6][4] =2058+{2059+ { stbvox_vertex_encode(1,0,0,0,0) , 2060+ stbvox_vertex_encode(1,1,0,0,0) ,2061+ stbvox_vertex_encode(1,1,0,0,0) ,2062+ stbvox_vertex_encode(1,0,0,0,0) },2063+ { stbvox_vertex_encode(1,1,0,0,0) ,2064+ stbvox_vertex_encode(0,1,0,0,0) ,2065+ stbvox_vertex_encode(0,1,0,0,0) ,2066+ stbvox_vertex_encode(1,1,0,0,0) },2067+ { stbvox_vertex_encode(0,1,0,0,0) ,2068+ stbvox_vertex_encode(0,0,0,0,0) ,2069+ stbvox_vertex_encode(0,0,0,0,0) ,2070+ stbvox_vertex_encode(0,1,0,0,0) },2071+ { stbvox_vertex_encode(0,0,0,0,0) ,2072+ stbvox_vertex_encode(1,0,0,0,0) ,2073+ stbvox_vertex_encode(1,0,0,0,0) ,2074+ stbvox_vertex_encode(0,0,0,0,0) },2075+ { stbvox_vertex_encode(0,1,0,0,0) ,2076+ stbvox_vertex_encode(1,1,0,0,0) ,2077+ stbvox_vertex_encode(1,0,0,0,0) ,2078+ stbvox_vertex_encode(0,0,0,0,0) },2079+ { stbvox_vertex_encode(0,0,0,0,0) ,2080+ stbvox_vertex_encode(1,0,0,0,0) ,2081+ stbvox_vertex_encode(1,1,0,0,0) ,2082+ stbvox_vertex_encode(0,1,0,0,0) }2083+};2084+2085+static stbvox_mesh_vertex stbvox_vmesh_delta_half_z[6][4] =2086+{2087+ { stbvox_vertex_encode(1,0,2,0,0) , 2088+ stbvox_vertex_encode(1,1,2,0,0) ,2089+ stbvox_vertex_encode(1,1,0,0,0) ,2090+ stbvox_vertex_encode(1,0,0,0,0) },2091+ { stbvox_vertex_encode(1,1,2,0,0) ,2092+ stbvox_vertex_encode(0,1,2,0,0) ,2093+ stbvox_vertex_encode(0,1,0,0,0) ,2094+ stbvox_vertex_encode(1,1,0,0,0) },2095+ { stbvox_vertex_encode(0,1,2,0,0) ,2096+ stbvox_vertex_encode(0,0,2,0,0) ,2097+ stbvox_vertex_encode(0,0,0,0,0) ,2098+ stbvox_vertex_encode(0,1,0,0,0) },2099+ { stbvox_vertex_encode(0,0,2,0,0) ,2100+ stbvox_vertex_encode(1,0,2,0,0) ,2101+ stbvox_vertex_encode(1,0,0,0,0) ,2102+ stbvox_vertex_encode(0,0,0,0,0) },2103+ { stbvox_vertex_encode(0,1,2,0,0) ,2104+ stbvox_vertex_encode(1,1,2,0,0) ,2105+ stbvox_vertex_encode(1,0,2,0,0) ,2106+ stbvox_vertex_encode(0,0,2,0,0) },2107+ { stbvox_vertex_encode(0,0,0,0,0) ,2108+ stbvox_vertex_encode(1,0,0,0,0) ,2109+ stbvox_vertex_encode(1,1,0,0,0) ,2110+ stbvox_vertex_encode(0,1,0,0,0) }2111+};2112+2113+static stbvox_mesh_vertex stbvox_vmesh_crossed_pair[6][4] =2114+{2115+ { stbvox_vertex_encode(1,0,2,0,0) , 2116+ stbvox_vertex_encode(0,1,2,0,0) ,2117+ stbvox_vertex_encode(0,1,0,0,0) ,2118+ stbvox_vertex_encode(1,0,0,0,0) },2119+ { stbvox_vertex_encode(1,1,2,0,0) ,2120+ stbvox_vertex_encode(0,0,2,0,0) ,2121+ stbvox_vertex_encode(0,0,0,0,0) ,2122+ stbvox_vertex_encode(1,1,0,0,0) },2123+ { stbvox_vertex_encode(0,1,2,0,0) ,2124+ stbvox_vertex_encode(1,0,2,0,0) ,2125+ stbvox_vertex_encode(1,0,0,0,0) ,2126+ stbvox_vertex_encode(0,1,0,0,0) },2127+ { stbvox_vertex_encode(0,0,2,0,0) ,2128+ stbvox_vertex_encode(1,1,2,0,0) ,2129+ stbvox_vertex_encode(1,1,0,0,0) ,2130+ stbvox_vertex_encode(0,0,0,0,0) },2131+ // not used, so we leave it non-degenerate to make sure it doesn't get gen'd accidentally2132+ { stbvox_vertex_encode(0,1,2,0,0) ,2133+ stbvox_vertex_encode(1,1,2,0,0) ,2134+ stbvox_vertex_encode(1,0,2,0,0) ,2135+ stbvox_vertex_encode(0,0,2,0,0) },2136+ { stbvox_vertex_encode(0,0,0,0,0) ,2137+ stbvox_vertex_encode(1,0,0,0,0) ,2138+ stbvox_vertex_encode(1,1,0,0,0) ,2139+ stbvox_vertex_encode(0,1,0,0,0) }2140+};2141+2142+#define STBVOX_MAX_GEOM 162143+#define STBVOX_NUM_ROTATION 42144+2145+// this is used to determine if a face is ever generated at all2146+static unsigned char stbvox_hasface[STBVOX_MAX_GEOM][STBVOX_NUM_ROTATION] =2147+{2148+ { 0,0,0,0 }, // empty2149+ { 0,0,0,0 }, // knockout2150+ { 63,63,63,63 }, // solid2151+ { 63,63,63,63 }, // transp2152+ { 63,63,63,63 }, // slab2153+ { 63,63,63,63 }, // slab2154+ { 1|2|4|48, 8|1|2|48, 4|8|1|48, 2|4|8|48, }, // floor slopes2155+ { 1|2|4|48, 8|1|2|48, 4|8|1|48, 2|4|8|48, }, // ceil slopes2156+ { 47,47,47,47 }, // wall-projected diagonal with down face2157+ { 31,31,31,31 }, // wall-projected diagonal with up face2158+ { 63,63,63,63 }, // crossed-pair has special handling, but avoid early-out2159+ { 63,63,63,63 }, // force2160+ { 63,63,63,63 },2161+ { 63,63,63,63 },2162+ { 63,63,63,63 },2163+ { 63,63,63,63 },2164+};2165+2166+// this determines which face type above is visible on each side of the geometry2167+static unsigned char stbvox_facetype[STBVOX_GEOM_count][6] =2168+{2169+ { 0, }, // STBVOX_GEOM_empty2170+ { STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid }, // knockout2171+ { STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid }, // solid2172+ { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force }, // transp2173+2174+ { STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_solid, STBVOX_FT_force },2175+ { STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_force, STBVOX_FT_solid },2176+ { STBVOX_FT_diag_123, STBVOX_FT_solid, STBVOX_FT_diag_023, STBVOX_FT_none, STBVOX_FT_force, STBVOX_FT_solid },2177+ { STBVOX_FT_diag_012, STBVOX_FT_solid, STBVOX_FT_diag_013, STBVOX_FT_none, STBVOX_FT_solid, STBVOX_FT_force },2178+2179+ { STBVOX_FT_diag_123, STBVOX_FT_solid, STBVOX_FT_diag_023, STBVOX_FT_force, STBVOX_FT_none, STBVOX_FT_solid },2180+ { STBVOX_FT_diag_012, STBVOX_FT_solid, STBVOX_FT_diag_013, STBVOX_FT_force, STBVOX_FT_solid, STBVOX_FT_none },2181+ { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, 0,0 }, // crossed pair2182+ { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force }, // GEOM_force2183+2184+ { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_force, STBVOX_FT_solid }, // floor vheight, all neighbors forced2185+ { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_force, STBVOX_FT_solid }, // floor vheight, all neighbors forced2186+ { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_solid, STBVOX_FT_force }, // ceil vheight, all neighbors forced2187+ { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_solid, STBVOX_FT_force }, // ceil vheight, all neighbors forced2188+};2189+2190+// This table indicates what normal to use for the "up" face of a sloped geom2191+// @TODO this could be done with math given the current arrangement of the enum, but let's not require it2192+static unsigned char stbvox_floor_slope_for_rot[4] =2193+{2194+ STBVF_su,2195+ STBVF_wu, // @TODO: why is this reversed from what it should be? this is a north-is-up face, so slope should be south&up2196+ STBVF_nu,2197+ STBVF_eu,2198+};2199+2200+static unsigned char stbvox_ceil_slope_for_rot[4] =2201+{2202+ STBVF_sd,2203+ STBVF_ed,2204+ STBVF_nd,2205+ STBVF_wd,2206+};2207+2208+// this table indicates whether, for each pair of types above, a face is visible.2209+// each value indicates whether a given type is visible for all neighbor types2210+static unsigned short stbvox_face_visible[STBVOX_FT_count] =2211+{2212+ // we encode the table by listing which cases cause *obscuration*, and bitwise inverting that2213+ // table is pre-shifted by 5 to save a shift when it's accessed2214+ (unsigned short) ((~0x07ff )<<5), // none is completely obscured by everything2215+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_upper) ))<<5), // upper2216+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_lower) ))<<5), // lower2217+ (unsigned short) ((~((1<<STBVOX_FT_solid) ))<<5), // solid is only completely obscured only by solid2218+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_013)))<<5), // diag012 matches diag0132219+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_123)))<<5), // diag023 matches diag1232220+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_012)))<<5), // diag013 matches diag0122221+ (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_023)))<<5), // diag123 matches diag0232222+ (unsigned short) ((~0 )<<5), // force is always rendered regardless, always forces neighbor2223+ (unsigned short) ((~((1<<STBVOX_FT_solid) ))<<5), // partial is only completely obscured only by solid2224+};2225+2226+// the vertex heights of the block types, in binary vertex order (zyx):2227+// lower: SW, SE, NW, NE; upper: SW, SE, NW, NE2228+static stbvox_mesh_vertex stbvox_geometry_vheight[8][8] =2229+{2230+ #define STBVOX_HEIGHTS(a,b,c,d,e,f,g,h) \2231+ { stbvox_vertex_encode(0,0,a,0,0), \2232+ stbvox_vertex_encode(0,0,b,0,0), \2233+ stbvox_vertex_encode(0,0,c,0,0), \2234+ stbvox_vertex_encode(0,0,d,0,0), \2235+ stbvox_vertex_encode(0,0,e,0,0), \2236+ stbvox_vertex_encode(0,0,f,0,0), \2237+ stbvox_vertex_encode(0,0,g,0,0), \2238+ stbvox_vertex_encode(0,0,h,0,0) }2239+2240+ STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),2241+ STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),2242+ STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),2243+ STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),2244+ STBVOX_HEIGHTS(1,1,1,1, 2,2,2,2),2245+ STBVOX_HEIGHTS(0,0,0,0, 1,1,1,1),2246+ STBVOX_HEIGHTS(0,0,0,0, 0,0,2,2),2247+ STBVOX_HEIGHTS(2,2,0,0, 2,2,2,2),2248+};2249+2250+// rotate vertices defined as [z][y][x] coords2251+static unsigned char stbvox_rotate_vertex[8][4] =2252+{2253+ { 0,1,3,2 }, // zyx=0002254+ { 1,3,2,0 }, // zyx=0012255+ { 2,0,1,3 }, // zyx=0102256+ { 3,2,0,1 }, // zyx=0112257+ { 4,5,7,6 }, // zyx=1002258+ { 5,7,6,4 }, // zyx=1012259+ { 6,4,5,7 }, // zyx=1102260+ { 7,6,4,5 }, // zyx=1112261+};2262+2263+#ifdef STBVOX_OPTIMIZED_VHEIGHT2264+// optimized vheight generates a single normal over the entire face, even if it's not planar2265+static stbvox_optimized_face_up_normal[4][4][4][4] =2266+{2267+ {2268+ {2269+ { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2270+ { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },2271+ { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_nu , },2272+ { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_nu , },2273+ },{2274+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2275+ { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2276+ { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },2277+ { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_nu , },2278+ },{2279+ { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },2280+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2281+ { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2282+ { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },2283+ },{2284+ { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },2285+ { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },2286+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2287+ { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2288+ },2289+ },{2290+ {2291+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },2292+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },2293+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },2294+ { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },2295+ },{2296+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2297+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },2298+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },2299+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },2300+ },{2301+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },2302+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2303+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },2304+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },2305+ },{2306+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },2307+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },2308+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2309+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },2310+ },2311+ },{2312+ {2313+ { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },2314+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },2315+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },2316+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },2317+ },{2318+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2319+ { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },2320+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },2321+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },2322+ },{2323+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2324+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2325+ { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },2326+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },2327+ },{2328+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2329+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2330+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2331+ { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },2332+ },2333+ },{2334+ {2335+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },2336+ { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },2337+ { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_nw_u, },2338+ { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nw_u, },2339+ },{2340+ { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },2341+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },2342+ { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },2343+ { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_nw_u, },2344+ },{2345+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2346+ { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },2347+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },2348+ { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },2349+ },{2350+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2351+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2352+ { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },2353+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },2354+ },2355+ },2356+};2357+#else2358+// which normal to use for a given vheight that's planar2359+// @TODO: this table was constructed by hand and may have bugs2360+// nw se sw2361+static stbvox_planar_face_up_normal[4][4][4] =2362+{ 2363+ { // sw,se,nw,ne; ne = se+nw-sw2364+ { STBVF_u , 0 , 0 , 0 }, // 0,0,0,0; 1,0,0,-1; 2,0,0,-2; 3,0,0,-3;2365+ { STBVF_u , STBVF_u , 0 , 0 }, // 0,1,0,1; 1,1,0, 0; 2,1,0,-1; 3,1,0,-2;2366+ { STBVF_wu , STBVF_nw_u, STBVF_nu , 0 }, // 0,2,0,2; 1,2,0, 1; 2,2,0, 0; 3,2,0,-1;2367+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nu }, // 0,3,0,3; 1,3,0, 2; 2,3,0, 1; 3,3,0, 0;2368+ },{2369+ { STBVF_u , STBVF_u , 0 , 0 }, // 0,0,1,1; 1,0,1, 0; 2,0,1,-1; 3,0,1,-2;2370+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, 0 }, // 0,1,1,2; 1,1,1, 1; 2,1,1, 0; 3,1,1,-1;2371+ { STBVF_sw_u, STBVF_u , STBVF_u , STBVF_ne_u }, // 0,2,1,3; 1,2,1, 2; 2,2,1, 1; 3,2,1, 0;2372+ { 0 , STBVF_wu , STBVF_nw_u, STBVF_nu }, // 0,3,1,4; 1,3,1, 3; 2,3,1, 2; 3,3,1, 1;2373+ },{2374+ { STBVF_su , STBVF_se_u, STBVF_eu , 0 }, // 0,0,2,2; 1,0,2, 1; 2,0,2, 0; 3,0,2,-1;2375+ { STBVF_sw_u, STBVF_u , STBVF_u , STBVF_ne_u }, // 0,1,2,3; 1,1,2, 2; 2,1,2, 1; 3,1,2, 0;2376+ { 0 , STBVF_sw_u, STBVF_u , STBVF_ne_u }, // 0,2,2,4; 1,2,2, 3; 2,2,2, 2; 3,2,2, 1;2377+ { 0 , 0 , STBVF_u , STBVF_u }, // 0,3,2,5; 1,3,2, 4; 2,3,2, 3; 3,3,2, 2;2378+ },{2379+ { STBVF_su , STBVF_se_u, STBVF_se_u, STBVF_eu }, // 0,0,3,3; 1,0,3, 2; 2,0,3, 1; 3,0,3, 0;2380+ { 0 , STBVF_su , STBVF_se_u, STBVF_eu }, // 0,1,3,4; 1,1,3, 3; 2,1,3, 2; 3,1,3, 1;2381+ { 0 , 0 , STBVF_u , STBVF_u }, // 0,2,3,5; 1,2,3, 4; 2,2,3, 3; 3,2,3, 2;2382+ { 0 , 0 , 0 , STBVF_u }, // 0,3,3,6; 1,3,3, 5; 2,3,3, 4; 3,3,3, 3;2383+ }2384+};2385+2386+// these tables were constructed automatically using a variant of the code2387+// below; however, they seem wrong, so who knows2388+static stbvox_face_up_normal_012[4][4][4] =2389+{2390+ {2391+ { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2392+ { STBVF_wu , STBVF_nu , STBVF_ne_u, STBVF_ne_u, },2393+ { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_ne_u, },2394+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nu , },2395+ },{2396+ { STBVF_su , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },2397+ { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },2398+ { STBVF_sw_u, STBVF_wu , STBVF_nu , STBVF_ne_u, },2399+ { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nu , },2400+ },{2401+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2402+ { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_ne_u, },2403+ { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },2404+ { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nu , },2405+ },{2406+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2407+ { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_eu , },2408+ { STBVF_sw_u, STBVF_sw_u, STBVF_su , STBVF_eu , },2409+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },2410+ }2411+};2412+2413+static stbvox_face_up_normal_013[4][4][4] =2414+{2415+ {2416+ { STBVF_u , STBVF_eu , STBVF_eu , STBVF_eu , },2417+ { STBVF_nw_u, STBVF_nu , STBVF_ne_u, STBVF_ne_u, },2418+ { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_ne_u, },2419+ { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },2420+ },{2421+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },2422+ { STBVF_wu , STBVF_u , STBVF_eu , STBVF_eu , },2423+ { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_ne_u, },2424+ { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },2425+ },{2426+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2427+ { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_eu , },2428+ { STBVF_wu , STBVF_wu , STBVF_u , STBVF_eu , },2429+ { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },2430+ },{2431+ { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },2432+ { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },2433+ { STBVF_sw_u, STBVF_sw_u, STBVF_su , STBVF_eu , },2434+ { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_u , },2435+ }2436+};2437+2438+static stbvox_face_up_normal_023[4][4][4] =2439+{2440+ {2441+ { STBVF_u , STBVF_nu , STBVF_nu , STBVF_nu , },2442+ { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },2443+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2444+ { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },2445+ },{2446+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },2447+ { STBVF_su , STBVF_u , STBVF_nu , STBVF_nu , },2448+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2449+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2450+ },{2451+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },2452+ { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },2453+ { STBVF_su , STBVF_su , STBVF_u , STBVF_nu , },2454+ { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },2455+ },{2456+ { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },2457+ { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },2458+ { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },2459+ { STBVF_su , STBVF_su , STBVF_su , STBVF_u , },2460+ }2461+};2462+2463+static stbvox_face_up_normal_123[4][4][4] =2464+{2465+ {2466+ { STBVF_u , STBVF_nu , STBVF_nu , STBVF_nu , },2467+ { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2468+ { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2469+ { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },2470+ },{2471+ { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },2472+ { STBVF_su , STBVF_u , STBVF_nu , STBVF_nu , },2473+ { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },2474+ { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },2475+ },{2476+ { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },2477+ { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },2478+ { STBVF_su , STBVF_su , STBVF_u , STBVF_nu , },2479+ { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },2480+ },{2481+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },2482+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },2483+ { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },2484+ { STBVF_su , STBVF_su , STBVF_su , STBVF_u , },2485+ }2486+};2487+#endif2488+2489 void stbvox_get_quad_vertex_pointer(stbvox_mesh_maker *mm, int mesh, stbvox_mesh_vertex **vertices, stbvox_mesh_face face)2490 {2491 char *p = mm->output_cur[mesh][0];2492 int step = mm->output_step[mesh][0];142 unmodified lines2635 }2636 }2637 2638 #ifndef STBVOX_OPTIMIZED_VHEIGHT2041-static stbvox_face_up_normal_012[4][4][4];2042-static stbvox_face_up_normal_013[4][4][4];2043-static stbvox_face_up_normal_023[4][4][4];2044-static stbvox_face_up_normal_123[4][4][4];2639+// get opposite-facing normal & texgen for opposite face, used to map up-facing vheight data to down-facing data2640+static unsigned char stbvox_reverse_face[STBVF_count] =2641+{2642+ STBVF_w, STBVF_s, STBVF_e, STBVF_n, STBVF_d , STBVF_u , STBVF_wd, STBVF_wu,2643+ 0, 0, 0, 0, STBVF_sw_d, STBVF_sw_u, STBVF_sd, STBVF_su,2644+ 0, 0, 0, 0, STBVF_se_d, STBVF_se_u, STBVF_ed, STBVF_eu,2645+ 0, 0, 0, 0, STBVF_ne_d, STBVF_ne_d, STBVF_nd, STBVF_nu2646+};2647 2648+2649 // render non-planar quads by splitting into two triangles, rendering each as a degenerate quad2650 static void stbvox_make_12_split_mesh_for_face(stbvox_mesh_maker *mm, stbvox_rotate rot, int face, int v_off, stbvox_pos pos, stbvox_mesh_vertex vertbase, stbvox_mesh_vertex *face_coord, unsigned char mesh, unsigned char *ht)2651 {2652 stbvox_mesh_vertex v[4];113 unmodified lines2766 // geometry, and then a table that tells us whether that type2767 // is hidden by a neighbor.2768 2769 2167-#define STBVOX_MAX_GEOM 162168-#define STBVOX_NUM_ROTATION 42169-2170-// this is used to determine if a face is ever generated at all2171-static unsigned char stbvox_hasface[STBVOX_MAX_GEOM][STBVOX_NUM_ROTATION];2172-2173-// this determines which face type above is visible on each side of the geometry2174-static unsigned char stbvox_facetype[STBVOX_GEOM_count][6];2175-2176-// This table indicates what normal to use for the "up" face of a sloped geom2177-static unsigned char stbvox_floor_slope_for_rot[4];2178-static unsigned char stbvox_ceil_slope_for_rot[4];2179-2180-// these are the types of faces each block can have2181-enum2182-{2183- STBVOX_FT_none ,2184- STBVOX_FT_upper ,2185- STBVOX_FT_lower ,2186- STBVOX_FT_solid ,2187- STBVOX_FT_diag_012,2188- STBVOX_FT_diag_023,2189- STBVOX_FT_diag_013,2190- STBVOX_FT_diag_123,2191- STBVOX_FT_force , // can't be covered up, used for internal faces, also hides nothing2192- STBVOX_FT_partial , // only covered by solid, never covers anything else2193-2194- STBVOX_FT_count2195-};2196-2197-// this table indicates whether, for each pair of types above, a face is visible.2198-// each value indicates whether a given type is visible for each neighbor type2199-static unsigned short stbvox_face_visible[STBVOX_FT_count];2200-2201-// the vertex heights of the block types, in binary vertex order (zyx):2202-// lower: SW, SE, NW, NE; upper: SW, SE, NW, NE2203-static stbvox_mesh_vertex stbvox_geometry_vheight[8][8];2204-2205-// rotate vertices defined as [z][y][x] coords2206-static unsigned char stbvox_rotate_vertex[8][4];2207-2208-#ifdef STBVOX_OPTIMIZED_VHEIGHT2209-static stbvox_optimized_face_up_normal[4][4][4][4];2210-#else2211-static stbvox_planar_face_up_normal[4][4][4];2212-#endif2213-2770 static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_pos pos, int v_off)2771 {2772 int ns_off = mm->y_stride_in_bytes;2773 int ew_off = mm->x_stride_in_bytes;644 unmodified lines3418 }3419 3420 /////////////////////////////////////////////////////////////////////////////3421 //2866-// tables2867-//2868-2869-// get opposite-facing normal & texgen for opposite face, used to map up-facing vheight data to down-facing data2870-static unsigned char stbvox_reverse_face[STBVF_count] =2871-{2872- STBVF_w, STBVF_s, STBVF_e, STBVF_n, STBVF_d , STBVF_u , STBVF_wd, STBVF_wu,2873- 0, 0, 0, 0, STBVF_sw_d, STBVF_sw_u, STBVF_sd, STBVF_su,2874- 0, 0, 0, 0, STBVF_se_d, STBVF_se_u, STBVF_ed, STBVF_eu,2875- 0, 0, 0, 0, STBVF_ne_d, STBVF_ne_d, STBVF_nd, STBVF_nu2876-};2877-2878-static float stbvox_default_texgen[2][32][3] =2879-{2880- { { 0, 1,0 }, { 0, 0, 1 }, { 0,-1,0 }, { 0, 0,-1 },2881- { -1, 0,0 }, { 0, 0, 1 }, { 1, 0,0 }, { 0, 0,-1 },2882- { 0,-1,0 }, { 0, 0, 1 }, { 0, 1,0 }, { 0, 0,-1 },2883- { 1, 0,0 }, { 0, 0, 1 }, { -1, 0,0 }, { 0, 0,-1 },2884-2885- { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 },2886- { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 },2887- { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 },2888- { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 },2889- },2890- { { 0, 0,-1 }, { 0, 1,0 }, { 0, 0, 1 }, { 0,-1,0 },2891- { 0, 0,-1 }, { -1, 0,0 }, { 0, 0, 1 }, { 1, 0,0 },2892- { 0, 0,-1 }, { 0,-1,0 }, { 0, 0, 1 }, { 0, 1,0 },2893- { 0, 0,-1 }, { 1, 0,0 }, { 0, 0, 1 }, { -1, 0,0 },2894-2895- { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 },2896- { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 },2897- { 0,-1, 0 }, { 1, 0,0 }, { 0, 1, 0 }, { -1, 0,0 },2898- { 0, 1, 0 }, { -1, 0,0 }, { 0,-1, 0 }, { 1, 0,0 },2899- },2900-};2901-2902-#define STBVOX_RSQRT2 0.7071067811865f2903-#define STBVOX_RSQRT3 0.5773502691896f2904-2905-static float stbvox_default_normals[32][3] =2906-{2907- { 1,0,0 }, // east2908- { 0,1,0 }, // north2909- { -1,0,0 }, // west2910- { 0,-1,0 }, // south2911- { 0,0,1 }, // up2912- { 0,0,-1 }, // down2913- { STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // east & up2914- { STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // east & down2915-2916- { STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // east & up2917- { 0, STBVOX_RSQRT2, STBVOX_RSQRT2 }, // north & up2918- { -STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // west & up2919- { 0,-STBVOX_RSQRT2, STBVOX_RSQRT2 }, // south & up2920- { STBVOX_RSQRT3, STBVOX_RSQRT3, STBVOX_RSQRT3 }, // ne & up2921- { STBVOX_RSQRT3, STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // ne & down2922- { 0, STBVOX_RSQRT2, STBVOX_RSQRT2 }, // north & up2923- { 0, STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // north & down2924-2925- { STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // east & down2926- { 0, STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // north & down2927- { -STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // west & down2928- { 0,-STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // south & down2929- { -STBVOX_RSQRT3, STBVOX_RSQRT3, STBVOX_RSQRT3 }, // NW & up2930- { -STBVOX_RSQRT3, STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // NW & down2931- { -STBVOX_RSQRT2,0, STBVOX_RSQRT2 }, // west & up2932- { -STBVOX_RSQRT2,0, -STBVOX_RSQRT2 }, // west & down2933-2934- { STBVOX_RSQRT3, STBVOX_RSQRT3,STBVOX_RSQRT3 }, // NE & up crossed2935- { -STBVOX_RSQRT3, STBVOX_RSQRT3,STBVOX_RSQRT3 }, // NW & up crossed2936- { -STBVOX_RSQRT3,-STBVOX_RSQRT3,STBVOX_RSQRT3 }, // SW & up crossed2937- { STBVOX_RSQRT3,-STBVOX_RSQRT3,STBVOX_RSQRT3 }, // SE & up crossed2938- { -STBVOX_RSQRT3,-STBVOX_RSQRT3, STBVOX_RSQRT3 }, // SW & up2939- { -STBVOX_RSQRT3,-STBVOX_RSQRT3,-STBVOX_RSQRT3 }, // SW & up2940- { 0,-STBVOX_RSQRT2, STBVOX_RSQRT2 }, // south & up2941- { 0,-STBVOX_RSQRT2, -STBVOX_RSQRT2 }, // south & down2942-};2943-2944-static float stbvox_default_texscale[128][4] =2945-{2946- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2947- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2948- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2949- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2950- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2951- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2952- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2953- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2954- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2955- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2956- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2957- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2958- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2959- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2960- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2961- {1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},{1,1,0,0},2962-};2963-2964-static unsigned char stbvox_default_palette_compact[64][3] =2965-{2966- { 255,255,255 }, { 238,238,238 }, { 221,221,221 }, { 204,204,204 },2967- { 187,187,187 }, { 170,170,170 }, { 153,153,153 }, { 136,136,136 },2968- { 119,119,119 }, { 102,102,102 }, { 85, 85, 85 }, { 68, 68, 68 },2969- { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 },2970- { 255,240,240 }, { 255,220,220 }, { 255,160,160 }, { 255, 32, 32 },2971- { 200,120,160 }, { 200, 60,150 }, { 220,100,130 }, { 255, 0,128 },2972- { 240,240,255 }, { 220,220,255 }, { 160,160,255 }, { 32, 32,255 },2973- { 120,160,200 }, { 60,150,200 }, { 100,130,220 }, { 0,128,255 },2974- { 240,255,240 }, { 220,255,220 }, { 160,255,160 }, { 32,255, 32 },2975- { 160,200,120 }, { 150,200, 60 }, { 130,220,100 }, { 128,255, 0 },2976- { 255,255,240 }, { 255,255,220 }, { 220,220,180 }, { 255,255, 32 },2977- { 200,160,120 }, { 200,150, 60 }, { 220,130,100 }, { 255,128, 0 },2978- { 255,240,255 }, { 255,220,255 }, { 220,180,220 }, { 255, 32,255 },2979- { 160,120,200 }, { 150, 60,200 }, { 130,100,220 }, { 128, 0,255 },2980- { 240,255,255 }, { 220,255,255 }, { 180,220,220 }, { 32,255,255 },2981- { 120,200,160 }, { 60,200,150 }, { 100,220,130 }, { 0,255,128 },2982-};2983-2984-static unsigned char stbvox_vertex_vector[6][4][3] =2985-{2986- { { 1,0,1 }, { 1,1,1 }, { 1,1,0 }, { 1,0,0 } }, // east2987- { { 1,1,1 }, { 0,1,1 }, { 0,1,0 }, { 1,1,0 } }, // north2988- { { 0,1,1 }, { 0,0,1 }, { 0,0,0 }, { 0,1,0 } }, // west2989- { { 0,0,1 }, { 1,0,1 }, { 1,0,0 }, { 0,0,0 } }, // south2990- { { 0,1,1 }, { 1,1,1 }, { 1,0,1 }, { 0,0,1 } }, // up2991- { { 0,0,0 }, { 1,0,0 }, { 1,1,0 }, { 0,1,0 } }, // down2992-};2993-2994-// stbvox_vertex_vector, but read coordinates as binary numbers, zyx2995-static unsigned char stbvox_vertex_selector[6][4] =2996-{2997- { 5,7,3,1 },2998- { 7,6,2,3 },2999- { 6,4,0,2 },3000- { 4,5,1,0 },3001- { 6,7,5,4 },3002- { 0,1,3,2 },3003-};3004-3005-static stbvox_mesh_vertex stbvox_vmesh_delta_normal[6][4] =3006-{3007- { stbvox_vertex_encode(1,0,1,0,0) , 3008- stbvox_vertex_encode(1,1,1,0,0) ,3009- stbvox_vertex_encode(1,1,0,0,0) ,3010- stbvox_vertex_encode(1,0,0,0,0) },3011- { stbvox_vertex_encode(1,1,1,0,0) ,3012- stbvox_vertex_encode(0,1,1,0,0) ,3013- stbvox_vertex_encode(0,1,0,0,0) ,3014- stbvox_vertex_encode(1,1,0,0,0) },3015- { stbvox_vertex_encode(0,1,1,0,0) ,3016- stbvox_vertex_encode(0,0,1,0,0) ,3017- stbvox_vertex_encode(0,0,0,0,0) ,3018- stbvox_vertex_encode(0,1,0,0,0) },3019- { stbvox_vertex_encode(0,0,1,0,0) ,3020- stbvox_vertex_encode(1,0,1,0,0) ,3021- stbvox_vertex_encode(1,0,0,0,0) ,3022- stbvox_vertex_encode(0,0,0,0,0) },3023- { stbvox_vertex_encode(0,1,1,0,0) ,3024- stbvox_vertex_encode(1,1,1,0,0) ,3025- stbvox_vertex_encode(1,0,1,0,0) ,3026- stbvox_vertex_encode(0,0,1,0,0) },3027- { stbvox_vertex_encode(0,0,0,0,0) ,3028- stbvox_vertex_encode(1,0,0,0,0) ,3029- stbvox_vertex_encode(1,1,0,0,0) ,3030- stbvox_vertex_encode(0,1,0,0,0) }3031-};3032-3033-static stbvox_mesh_vertex stbvox_vmesh_pre_vheight[6][4] =3034-{3035- { stbvox_vertex_encode(1,0,0,0,0) , 3036- stbvox_vertex_encode(1,1,0,0,0) ,3037- stbvox_vertex_encode(1,1,0,0,0) ,3038- stbvox_vertex_encode(1,0,0,0,0) },3039- { stbvox_vertex_encode(1,1,0,0,0) ,3040- stbvox_vertex_encode(0,1,0,0,0) ,3041- stbvox_vertex_encode(0,1,0,0,0) ,3042- stbvox_vertex_encode(1,1,0,0,0) },3043- { stbvox_vertex_encode(0,1,0,0,0) ,3044- stbvox_vertex_encode(0,0,0,0,0) ,3045- stbvox_vertex_encode(0,0,0,0,0) ,3046- stbvox_vertex_encode(0,1,0,0,0) },3047- { stbvox_vertex_encode(0,0,0,0,0) ,3048- stbvox_vertex_encode(1,0,0,0,0) ,3049- stbvox_vertex_encode(1,0,0,0,0) ,3050- stbvox_vertex_encode(0,0,0,0,0) },3051- { stbvox_vertex_encode(0,1,0,0,0) ,3052- stbvox_vertex_encode(1,1,0,0,0) ,3053- stbvox_vertex_encode(1,0,0,0,0) ,3054- stbvox_vertex_encode(0,0,0,0,0) },3055- { stbvox_vertex_encode(0,0,0,0,0) ,3056- stbvox_vertex_encode(1,0,0,0,0) ,3057- stbvox_vertex_encode(1,1,0,0,0) ,3058- stbvox_vertex_encode(0,1,0,0,0) }3059-};3060-3061-static stbvox_mesh_vertex stbvox_vmesh_delta_half_z[6][4] =3062-{3063- { stbvox_vertex_encode(1,0,2,0,0) , 3064- stbvox_vertex_encode(1,1,2,0,0) ,3065- stbvox_vertex_encode(1,1,0,0,0) ,3066- stbvox_vertex_encode(1,0,0,0,0) },3067- { stbvox_vertex_encode(1,1,2,0,0) ,3068- stbvox_vertex_encode(0,1,2,0,0) ,3069- stbvox_vertex_encode(0,1,0,0,0) ,3070- stbvox_vertex_encode(1,1,0,0,0) },3071- { stbvox_vertex_encode(0,1,2,0,0) ,3072- stbvox_vertex_encode(0,0,2,0,0) ,3073- stbvox_vertex_encode(0,0,0,0,0) ,3074- stbvox_vertex_encode(0,1,0,0,0) },3075- { stbvox_vertex_encode(0,0,2,0,0) ,3076- stbvox_vertex_encode(1,0,2,0,0) ,3077- stbvox_vertex_encode(1,0,0,0,0) ,3078- stbvox_vertex_encode(0,0,0,0,0) },3079- { stbvox_vertex_encode(0,1,2,0,0) ,3080- stbvox_vertex_encode(1,1,2,0,0) ,3081- stbvox_vertex_encode(1,0,2,0,0) ,3082- stbvox_vertex_encode(0,0,2,0,0) },3083- { stbvox_vertex_encode(0,0,0,0,0) ,3084- stbvox_vertex_encode(1,0,0,0,0) ,3085- stbvox_vertex_encode(1,1,0,0,0) ,3086- stbvox_vertex_encode(0,1,0,0,0) }3087-};3088-3089-static stbvox_mesh_vertex stbvox_vmesh_crossed_pair[6][4] =3090-{3091- { stbvox_vertex_encode(1,0,2,0,0) , 3092- stbvox_vertex_encode(0,1,2,0,0) ,3093- stbvox_vertex_encode(0,1,0,0,0) ,3094- stbvox_vertex_encode(1,0,0,0,0) },3095- { stbvox_vertex_encode(1,1,2,0,0) ,3096- stbvox_vertex_encode(0,0,2,0,0) ,3097- stbvox_vertex_encode(0,0,0,0,0) ,3098- stbvox_vertex_encode(1,1,0,0,0) },3099- { stbvox_vertex_encode(0,1,2,0,0) ,3100- stbvox_vertex_encode(1,0,2,0,0) ,3101- stbvox_vertex_encode(1,0,0,0,0) ,3102- stbvox_vertex_encode(0,1,0,0,0) },3103- { stbvox_vertex_encode(0,0,2,0,0) ,3104- stbvox_vertex_encode(1,1,2,0,0) ,3105- stbvox_vertex_encode(1,1,0,0,0) ,3106- stbvox_vertex_encode(0,0,0,0,0) },3107- // not used, so we leave it non-degenerate to make sure it doesn't get gen'd accidentally3108- { stbvox_vertex_encode(0,1,2,0,0) ,3109- stbvox_vertex_encode(1,1,2,0,0) ,3110- stbvox_vertex_encode(1,0,2,0,0) ,3111- stbvox_vertex_encode(0,0,2,0,0) },3112- { stbvox_vertex_encode(0,0,0,0,0) ,3113- stbvox_vertex_encode(1,0,0,0,0) ,3114- stbvox_vertex_encode(1,1,0,0,0) ,3115- stbvox_vertex_encode(0,1,0,0,0) }3116-};3117-3118-3119-// this is used to determine if a face is ever generated at all3120-static unsigned char stbvox_hasface[STBVOX_MAX_GEOM][STBVOX_NUM_ROTATION] =3121-{3122- { 0,0,0,0 }, // empty3123- { 0,0,0,0 }, // knockout3124- { 63,63,63,63 }, // solid3125- { 63,63,63,63 }, // transp3126- { 63,63,63,63 }, // slab3127- { 63,63,63,63 }, // slab3128- { 1|2|4|48, 8|1|2|48, 4|8|1|48, 2|4|8|48, }, // floor slopes3129- { 1|2|4|48, 8|1|2|48, 4|8|1|48, 2|4|8|48, }, // ceil slopes3130- { 47,47,47,47 }, // wall-projected diagonal with down face3131- { 31,31,31,31 }, // wall-projected diagonal with up face3132- { 63,63,63,63 }, // crossed-pair has special handling, but avoid early-out3133- { 63,63,63,63 }, // force3134- { 63,63,63,63 },3135- { 63,63,63,63 },3136- { 63,63,63,63 },3137- { 63,63,63,63 },3138-};3139-3140-// this determines which face type above is visible on each side of the geometry3141-static unsigned char stbvox_facetype[STBVOX_GEOM_count][6] =3142-{3143- { 0, }, // STBVOX_GEOM_empty3144- { STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid }, // knockout3145- { STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid, STBVOX_FT_solid }, // solid3146- { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force }, // transp3147-3148- { STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_upper, STBVOX_FT_solid, STBVOX_FT_force },3149- { STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_lower, STBVOX_FT_force, STBVOX_FT_solid },3150- { STBVOX_FT_diag_123, STBVOX_FT_solid, STBVOX_FT_diag_023, STBVOX_FT_none, STBVOX_FT_force, STBVOX_FT_solid },3151- { STBVOX_FT_diag_012, STBVOX_FT_solid, STBVOX_FT_diag_013, STBVOX_FT_none, STBVOX_FT_solid, STBVOX_FT_force },3152-3153- { STBVOX_FT_diag_123, STBVOX_FT_solid, STBVOX_FT_diag_023, STBVOX_FT_force, STBVOX_FT_none, STBVOX_FT_solid },3154- { STBVOX_FT_diag_012, STBVOX_FT_solid, STBVOX_FT_diag_013, STBVOX_FT_force, STBVOX_FT_solid, STBVOX_FT_none },3155- { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, 0,0 }, // crossed pair3156- { STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force, STBVOX_FT_force }, // GEOM_force3157-3158- { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_force, STBVOX_FT_solid }, // floor vheight, all neighbors forced3159- { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_force, STBVOX_FT_solid }, // floor vheight, all neighbors forced3160- { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_solid, STBVOX_FT_force }, // ceil vheight, all neighbors forced3161- { STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial,STBVOX_FT_partial, STBVOX_FT_solid, STBVOX_FT_force }, // ceil vheight, all neighbors forced3162-};3163-3164-// This table indicates what normal to use for the "up" face of a sloped geom3165-// @TODO this could be done with math given the current arrangement of the enum, but let's not require it3166-static unsigned char stbvox_floor_slope_for_rot[4] =3167-{3168- STBVF_su,3169- STBVF_wu, // @TODO: why is this reversed from what it should be? this is a north-is-up face, so slope should be south&up3170- STBVF_nu,3171- STBVF_eu,3172-};3173-3174-static unsigned char stbvox_ceil_slope_for_rot[4] =3175-{3176- STBVF_sd,3177- STBVF_ed,3178- STBVF_nd,3179- STBVF_wd,3180-};3181-3182-// this table indicates whether, for each pair of types above, a face is visible.3183-// each value indicates whether a given type is visible for all neighbor types3184-static unsigned short stbvox_face_visible[STBVOX_FT_count] =3185-{3186- // we encode the table by listing which cases cause *obscuration*, and bitwise inverting that3187- // table is pre-shifted by 5 to save a shift when it's accessed3188- (unsigned short) ((~0x07ff )<<5), // none is completely obscured by everything3189- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_upper) ))<<5), // upper3190- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_lower) ))<<5), // lower3191- (unsigned short) ((~((1<<STBVOX_FT_solid) ))<<5), // solid is only completely obscured only by solid3192- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_013)))<<5), // diag012 matches diag0133193- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_123)))<<5), // diag023 matches diag1233194- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_012)))<<5), // diag013 matches diag0123195- (unsigned short) ((~((1<<STBVOX_FT_solid) | (1<<STBVOX_FT_diag_023)))<<5), // diag123 matches diag0233196- (unsigned short) ((~0 )<<5), // force is always rendered regardless, always forces neighbor3197- (unsigned short) ((~((1<<STBVOX_FT_solid) ))<<5), // partial is only completely obscured only by solid3198-};3199-3200-// the vertex heights of the block types, in binary vertex order (zyx):3201-// lower: SW, SE, NW, NE; upper: SW, SE, NW, NE3202-static stbvox_mesh_vertex stbvox_geometry_vheight[8][8] =3203-{3204- #define STBVOX_HEIGHTS(a,b,c,d,e,f,g,h) \3205- { stbvox_vertex_encode(0,0,a,0,0), \3206- stbvox_vertex_encode(0,0,b,0,0), \3207- stbvox_vertex_encode(0,0,c,0,0), \3208- stbvox_vertex_encode(0,0,d,0,0), \3209- stbvox_vertex_encode(0,0,e,0,0), \3210- stbvox_vertex_encode(0,0,f,0,0), \3211- stbvox_vertex_encode(0,0,g,0,0), \3212- stbvox_vertex_encode(0,0,h,0,0) }3213-3214- STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),3215- STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),3216- STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),3217- STBVOX_HEIGHTS(0,0,0,0, 2,2,2,2),3218- STBVOX_HEIGHTS(1,1,1,1, 2,2,2,2),3219- STBVOX_HEIGHTS(0,0,0,0, 1,1,1,1),3220- STBVOX_HEIGHTS(0,0,0,0, 0,0,2,2),3221- STBVOX_HEIGHTS(2,2,0,0, 2,2,2,2),3222-};3223-3224-// rotate vertices defined as [z][y][x] coords3225-static unsigned char stbvox_rotate_vertex[8][4] =3226-{3227- { 0,1,3,2 }, // zyx=0003228- { 1,3,2,0 }, // zyx=0013229- { 2,0,1,3 }, // zyx=0103230- { 3,2,0,1 }, // zyx=0113231- { 4,5,7,6 }, // zyx=1003232- { 5,7,6,4 }, // zyx=1013233- { 6,4,5,7 }, // zyx=1103234- { 7,6,4,5 }, // zyx=1113235-};3236-3237-#ifdef STBVOX_OPTIMIZED_VHEIGHT3238-// optimized vheight generates a single normal over the entire face, even if it's not planar3239-static stbvox_optimized_face_up_normal[4][4][4][4] =3240-{3241- {3242- {3243- { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3244- { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },3245- { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_nu , },3246- { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_nu , },3247- },{3248- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3249- { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3250- { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },3251- { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_nu , },3252- },{3253- { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },3254- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3255- { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3256- { STBVF_nw_u, STBVF_nu , STBVF_nu , STBVF_ne_u, },3257- },{3258- { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },3259- { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },3260- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3261- { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3262- },3263- },{3264- {3265- { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },3266- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },3267- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },3268- { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },3269- },{3270- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3271- { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },3272- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },3273- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },3274- },{3275- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },3276- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3277- { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },3278- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_nu , },3279- },{3280- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },3281- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },3282- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3283- { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },3284- },3285- },{3286- {3287- { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },3288- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },3289- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },3290- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },3291- },{3292- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3293- { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },3294- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },3295- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },3296- },{3297- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3298- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3299- { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },3300- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nu , },3301- },{3302- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3303- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3304- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3305- { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },3306- },3307- },{3308- {3309- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },3310- { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },3311- { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_nw_u, },3312- { STBVF_wu , STBVF_wu , STBVF_nw_u, STBVF_nw_u, },3313- },{3314- { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },3315- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },3316- { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },3317- { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_nw_u, },3318- },{3319- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3320- { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },3321- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },3322- { STBVF_sw_u, STBVF_wu , STBVF_wu , STBVF_nw_u, },3323- },{3324- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3325- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3326- { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },3327- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },3328- },3329- },3330-};3331-#else3332-// which normal to use for a given vheight that's planar3333-// @TODO: this table was constructed by hand and may have bugs3334-// nw se sw3335-static stbvox_planar_face_up_normal[4][4][4] =3336-{ 3337- { // sw,se,nw,ne; ne = se+nw-sw3338- { STBVF_u , 0 , 0 , 0 }, // 0,0,0,0; 1,0,0,-1; 2,0,0,-2; 3,0,0,-3;3339- { STBVF_u , STBVF_u , 0 , 0 }, // 0,1,0,1; 1,1,0, 0; 2,1,0,-1; 3,1,0,-2;3340- { STBVF_wu , STBVF_nw_u, STBVF_nu , 0 }, // 0,2,0,2; 1,2,0, 1; 2,2,0, 0; 3,2,0,-1;3341- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nu }, // 0,3,0,3; 1,3,0, 2; 2,3,0, 1; 3,3,0, 0;3342- },{3343- { STBVF_u , STBVF_u , 0 , 0 }, // 0,0,1,1; 1,0,1, 0; 2,0,1,-1; 3,0,1,-2;3344- { STBVF_sw_u, STBVF_u , STBVF_ne_u, 0 }, // 0,1,1,2; 1,1,1, 1; 2,1,1, 0; 3,1,1,-1;3345- { STBVF_sw_u, STBVF_u , STBVF_u , STBVF_ne_u }, // 0,2,1,3; 1,2,1, 2; 2,2,1, 1; 3,2,1, 0;3346- { 0 , STBVF_wu , STBVF_nw_u, STBVF_nu }, // 0,3,1,4; 1,3,1, 3; 2,3,1, 2; 3,3,1, 1;3347- },{3348- { STBVF_su , STBVF_se_u, STBVF_eu , 0 }, // 0,0,2,2; 1,0,2, 1; 2,0,2, 0; 3,0,2,-1;3349- { STBVF_sw_u, STBVF_u , STBVF_u , STBVF_ne_u }, // 0,1,2,3; 1,1,2, 2; 2,1,2, 1; 3,1,2, 0;3350- { 0 , STBVF_sw_u, STBVF_u , STBVF_ne_u }, // 0,2,2,4; 1,2,2, 3; 2,2,2, 2; 3,2,2, 1;3351- { 0 , 0 , STBVF_u , STBVF_u }, // 0,3,2,5; 1,3,2, 4; 2,3,2, 3; 3,3,2, 2;3352- },{3353- { STBVF_su , STBVF_se_u, STBVF_se_u, STBVF_eu }, // 0,0,3,3; 1,0,3, 2; 2,0,3, 1; 3,0,3, 0;3354- { 0 , STBVF_su , STBVF_se_u, STBVF_eu }, // 0,1,3,4; 1,1,3, 3; 2,1,3, 2; 3,1,3, 1;3355- { 0 , 0 , STBVF_u , STBVF_u }, // 0,2,3,5; 1,2,3, 4; 2,2,3, 3; 3,2,3, 2;3356- { 0 , 0 , 0 , STBVF_u }, // 0,3,3,6; 1,3,3, 5; 2,3,3, 4; 3,3,3, 3;3357- }3358-};3359-3360-// these tables were constructed automatically using a variant of the code3361-// below; however, they seem wrong, so who knows3362-static stbvox_face_up_normal_012[4][4][4] =3363-{3364- {3365- { STBVF_u , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3366- { STBVF_wu , STBVF_nu , STBVF_ne_u, STBVF_ne_u, },3367- { STBVF_wu , STBVF_nw_u, STBVF_nu , STBVF_ne_u, },3368- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nu , },3369- },{3370- { STBVF_su , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },3371- { STBVF_sw_u, STBVF_u , STBVF_ne_u, STBVF_ne_u, },3372- { STBVF_sw_u, STBVF_wu , STBVF_nu , STBVF_ne_u, },3373- { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nu , },3374- },{3375- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3376- { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_ne_u, },3377- { STBVF_sw_u, STBVF_sw_u, STBVF_u , STBVF_ne_u, },3378- { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nu , },3379- },{3380- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3381- { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_eu , },3382- { STBVF_sw_u, STBVF_sw_u, STBVF_su , STBVF_eu , },3383- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_u , },3384- }3385-};3386-3387-static stbvox_face_up_normal_013[4][4][4] =3388-{3389- {3390- { STBVF_u , STBVF_eu , STBVF_eu , STBVF_eu , },3391- { STBVF_nw_u, STBVF_nu , STBVF_ne_u, STBVF_ne_u, },3392- { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_ne_u, },3393- { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },3394- },{3395- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_eu , },3396- { STBVF_wu , STBVF_u , STBVF_eu , STBVF_eu , },3397- { STBVF_nw_u, STBVF_nw_u, STBVF_nu , STBVF_ne_u, },3398- { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },3399- },{3400- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3401- { STBVF_sw_u, STBVF_su , STBVF_eu , STBVF_eu , },3402- { STBVF_wu , STBVF_wu , STBVF_u , STBVF_eu , },3403- { STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, STBVF_nu , },3404- },{3405- { STBVF_su , STBVF_su , STBVF_su , STBVF_eu , },3406- { STBVF_sw_u, STBVF_su , STBVF_su , STBVF_su , },3407- { STBVF_sw_u, STBVF_sw_u, STBVF_su , STBVF_eu , },3408- { STBVF_wu , STBVF_wu , STBVF_wu , STBVF_u , },3409- }3410-};3411-3412-static stbvox_face_up_normal_023[4][4][4] =3413-{3414- {3415- { STBVF_u , STBVF_nu , STBVF_nu , STBVF_nu , },3416- { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },3417- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3418- { STBVF_eu , STBVF_eu , STBVF_eu , STBVF_eu , },3419- },{3420- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },3421- { STBVF_su , STBVF_u , STBVF_nu , STBVF_nu , },3422- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3423- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3424- },{3425- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },3426- { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },3427- { STBVF_su , STBVF_su , STBVF_u , STBVF_nu , },3428- { STBVF_su , STBVF_su , STBVF_eu , STBVF_eu , },3429- },{3430- { STBVF_wu , STBVF_nw_u, STBVF_nw_u, STBVF_nw_u, },3431- { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },3432- { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },3433- { STBVF_su , STBVF_su , STBVF_su , STBVF_u , },3434- }3435-};3436-3437-static stbvox_face_up_normal_123[4][4][4] =3438-{3439- {3440- { STBVF_u , STBVF_nu , STBVF_nu , STBVF_nu , },3441- { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3442- { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3443- { STBVF_eu , STBVF_ne_u, STBVF_ne_u, STBVF_ne_u, },3444- },{3445- { STBVF_sw_u, STBVF_wu , STBVF_nw_u, STBVF_nw_u, },3446- { STBVF_su , STBVF_u , STBVF_nu , STBVF_nu , },3447- { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },3448- { STBVF_eu , STBVF_eu , STBVF_ne_u, STBVF_ne_u, },3449- },{3450- { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },3451- { STBVF_sw_u, STBVF_sw_u, STBVF_wu , STBVF_nw_u, },3452- { STBVF_su , STBVF_su , STBVF_u , STBVF_nu , },3453- { STBVF_su , STBVF_eu , STBVF_eu , STBVF_ne_u, },3454- },{3455- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },3456- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },3457- { STBVF_sw_u, STBVF_sw_u, STBVF_sw_u, STBVF_wu , },3458- { STBVF_su , STBVF_su , STBVF_su , STBVF_u , },3459- }3460-};3461-#endif3462-3463-/////////////////////////////////////////////////////////////////////////////3464-//3422 // offline computation of tables3423 //3424 3425 #if 0108 unmodified lines