From 1a31473db826af86ddf8ce8a2cf224fe9a43d406 Mon Sep 17 00:00:00 2001 From: guitarfreak Date: Sat, 8 Oct 2016 01:59:11 +0200 Subject: [PATCH 1/4] Added block_selector --- stb_voxel_render.h | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/stb_voxel_render.h b/stb_voxel_render.h index c49aa40..17c8fbc 100644 --- a/stb_voxel_render.h +++ b/stb_voxel_render.h @@ -2902,7 +2902,9 @@ static void stbvox_make_mesh_for_block(stbvox_mesh_maker *mm, stbvox_pos pos, in if (mm->input.selector) mesh = mm->input.selector[v_off]; - + else if (mm->input.block_selector) + mesh = mm->input.block_selector[mm->input.blocktype[v_off]]; + // check if we're going off the end if (mm->output_cur[mesh][0] + mm->output_size[mesh][0]*6 > mm->output_end[mesh][0]) { mm->full = 1; @@ -3008,6 +3010,18 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po nrot[5] = (mm->input.selector[v_off - 1] >> 4) & 3; } #endif + } else if (mm->input.block_selector) { + #ifndef STBVOX_CONFIG_ROTATION_IN_LIGHTING + if (mm->input.packed_compact == NULL) { + rot = (mm->input.block_selector[bt ] >> 4) & 3; + nrot[0] = (mm->input.block_selector[nbt[0]] >> 4) & 3; + nrot[1] = (mm->input.block_selector[nbt[1]] >> 4) & 3; + nrot[2] = (mm->input.block_selector[nbt[2]] >> 4) & 3; + nrot[3] = (mm->input.block_selector[nbt[3]] >> 4) & 3; + nrot[4] = (mm->input.block_selector[nbt[4]] >> 4) & 3; + nrot[5] = (mm->input.block_selector[nbt[5]] >> 4) & 3; + } + #endif } else { #ifndef STBVOX_CONFIG_ROTATION_IN_LIGHTING if (mm->input.packed_compact == NULL) { @@ -3111,7 +3125,9 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po mesh = mm->default_mesh; if (mm->input.selector) mesh = mm->input.selector[v_off]; - + else if (mm->input.block_selector) + mesh = mm->input.block_selector[bt]; + if (geo <= STBVOX_GEOM_ceil_slope_north_is_bottom) { // this is the simple case, we can just use regular block gen with special vmesh calculated with vheight stbvox_mesh_vertex basevert; @@ -3132,7 +3148,9 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po basevert = stbvox_vertex_encode(pos.x, pos.y, pos.z << STBVOX_CONFIG_PRECISION_Z, 0,0); if (mm->input.selector) { mesh = mm->input.selector[v_off]; - } + } else if (mm->input.block_selector) + mesh = mm->input.block_selector[bt]; + // check if we're going off the end if (mm->output_cur[mesh][0] + mm->output_size[mesh][0]*6 > mm->output_end[mesh][0]) { @@ -3328,7 +3346,7 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po rotate.overlay = (val >> 2) & 3; //rotate.tex2 = (val >> 4) & 3; rotate.ecolor = (val >> 6) & 3; - } else if (mm->input.selector) { + } else if (mm->input.selector || mm->input.block_selector) { rotate.block = rotate.overlay = rotate.ecolor = simple_rot; } @@ -3352,6 +3370,10 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po mesh = mm->input.selector[v_off]; simple_rot = mesh >> 4; mesh &= 15; + } else if (mm->input.block_selector) { + mesh = mm->input.block_selector[bt]; + simple_rot = mesh >> 4; + mesh &= 15; } // check if we're going off the end @@ -3366,7 +3388,7 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po rot.overlay = (val >> 2) & 3; //rot.tex2 = (val >> 4) & 3; rot.ecolor = (val >> 6) & 3; - } else if (mm->input.selector) { + } else if (mm->input.selector || mm->input.block_selector) { rot.block = rot.overlay = rot.ecolor = simple_rot; } rot.facerot = 0; From 5fcd181fae6d5e318bf897473a2ee5a9e2259a51 Mon Sep 17 00:00:00 2001 From: guitarfreak Date: Sat, 8 Oct 2016 04:10:23 +0200 Subject: [PATCH 2/4] Update stb_voxel_render.h --- stb_voxel_render.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/stb_voxel_render.h b/stb_voxel_render.h index 17c8fbc..46a4726 100644 --- a/stb_voxel_render.h +++ b/stb_voxel_render.h @@ -3010,18 +3010,6 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po nrot[5] = (mm->input.selector[v_off - 1] >> 4) & 3; } #endif - } else if (mm->input.block_selector) { - #ifndef STBVOX_CONFIG_ROTATION_IN_LIGHTING - if (mm->input.packed_compact == NULL) { - rot = (mm->input.block_selector[bt ] >> 4) & 3; - nrot[0] = (mm->input.block_selector[nbt[0]] >> 4) & 3; - nrot[1] = (mm->input.block_selector[nbt[1]] >> 4) & 3; - nrot[2] = (mm->input.block_selector[nbt[2]] >> 4) & 3; - nrot[3] = (mm->input.block_selector[nbt[3]] >> 4) & 3; - nrot[4] = (mm->input.block_selector[nbt[4]] >> 4) & 3; - nrot[5] = (mm->input.block_selector[nbt[5]] >> 4) & 3; - } - #endif } else { #ifndef STBVOX_CONFIG_ROTATION_IN_LIGHTING if (mm->input.packed_compact == NULL) { @@ -3346,7 +3334,7 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po rotate.overlay = (val >> 2) & 3; //rotate.tex2 = (val >> 4) & 3; rotate.ecolor = (val >> 6) & 3; - } else if (mm->input.selector || mm->input.block_selector) { + } else if (mm->input.selector) { rotate.block = rotate.overlay = rotate.ecolor = simple_rot; } @@ -3388,7 +3376,7 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po rot.overlay = (val >> 2) & 3; //rot.tex2 = (val >> 4) & 3; rot.ecolor = (val >> 6) & 3; - } else if (mm->input.selector || mm->input.block_selector) { + } else if (mm->input.selector) { rot.block = rot.overlay = rot.ecolor = simple_rot; } rot.facerot = 0; From 6a29bcf2a1c00b100558d6b0366fa64f4c0929c7 Mon Sep 17 00:00:00 2001 From: guitarfreak Date: Sat, 8 Oct 2016 04:23:52 +0200 Subject: [PATCH 3/4] Update stb_voxel_render.h --- stb_voxel_render.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stb_voxel_render.h b/stb_voxel_render.h index 46a4726..32d581c 100644 --- a/stb_voxel_render.h +++ b/stb_voxel_render.h @@ -3358,10 +3358,9 @@ static void stbvox_make_mesh_for_block_with_geo(stbvox_mesh_maker *mm, stbvox_po mesh = mm->input.selector[v_off]; simple_rot = mesh >> 4; mesh &= 15; - } else if (mm->input.block_selector) { + } + if (mm->input.block_selector) { mesh = mm->input.block_selector[bt]; - simple_rot = mesh >> 4; - mesh &= 15; } // check if we're going off the end From fd912b5d936c98b6087c768d4473662803b4590b Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Fri, 3 Mar 2017 09:52:42 -0800 Subject: [PATCH 4/4] version number, doc tweaks --- stb_voxel_render.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/stb_voxel_render.h b/stb_voxel_render.h index 8469464..514ed99 100644 --- a/stb_voxel_render.h +++ b/stb_voxel_render.h @@ -1,4 +1,4 @@ -// stb_voxel_render.h - v0.84 - Sean Barrett, 2015 - public domain +// stb_voxel_render.h - v0.85 - Sean Barrett, 2015 - public domain // // This library helps render large-scale "voxel" worlds for games, // in this case, one with blocks that can have textures and that @@ -13,7 +13,7 @@ // It works by creating triangle meshes. The library includes // // - converter from dense 3D arrays of block info to vertex mesh -// - shader for the vertex mesh +// - vertex & fragment shaders for the vertex mesh // - assistance in setting up shader state // // For portability, none of the library code actually accesses @@ -24,8 +24,9 @@ // yourself. However, you could also try making a game with // a small enough world that it's fully loaded rather than // streaming. Currently the preferred vertex format is 20 bytes -// per quad. There are plans to allow much more compact formats -// with a slight reduction in shader features. +// per quad. There are designs to allow much more compact formats +// with a slight reduction in shader features, but no roadmap +// for actually implementing them. // // // USAGE @@ -108,7 +109,7 @@ // and avoids a potential slow path (gathering non-uniform // data from uniforms) on some hardware. // -// In the future I hope to add additional modes that have significantly +// In the future I might add additional modes that have significantly // smaller meshes but reduce features, down as small as 6 bytes per quad. // See elsewhere in this file for a table of candidate modes. Switching // to a mode will require changing some of your mesh creation code, but @@ -187,10 +188,11 @@ // Sean Barrett github:r-leyh Jesus Fernandez // Miguel Lechon github:Arbeiterunfallversicherungsgesetz // Thomas Frase James Hofmann -// Stephen Olsen +// Stephen Olsen github:guitarfreak // // VERSION HISTORY // +// 0.85 (2017-03-03) add block_selector (by guitarfreak) // 0.84 (2016-04-02) fix GLSL syntax error on glModelView path // 0.83 (2015-09-13) remove non-constant struct initializers to support more compilers // 0.82 (2015-08-01) added input.packed_compact to store rot, vheight & texlerp efficiently @@ -262,7 +264,7 @@ extern "C" { // modes 0,1,20,21, Z in the mesh can extend to 511 instead // of 255. However, half-height blocks cannot be used. // -// All of the following just #ifdef tested so need no values, and are optional. +// All of the following are just #ifdef tested so need no values, and are optional. // // STBVOX_CONFIG_BLOCKTYPE_SHORT // use unsigned 16-bit values for 'blocktype' in the input instead of 8-bit values @@ -302,7 +304,7 @@ extern "C" { // // STBVOX_CONFIG_DISABLE_TEX2 // This disables all processing of texture 2 in the shader in case -// you don't use it. Eventually this will be replaced with a mode +// you don't use it. Eventually this could be replaced with a mode // that omits the unused data entirely. // // STBVOX_CONFIG_TEX1_EDGE_CLAMP