shama/voxel-texture — pull request #21 by deathcap (2014-01-14 07:11:28+00:00)
Title: Add support for greedy meshing, 4-tap, reconfiguring, and non-atlas texturing

This isn't necessarily in a state ready to be pulled yet but I wanted to submit these changes for feedback – several major enhancements here:

**Non-atlas texturing**: restored from v0.4.0 as an option. Most of the time the atlas-based texturing is desirable but having the non-atlas implementation can be useful to switch to for comparison purposes, debugging problems with the atlas texturing, etc. Added as `TextureSimple`, along side the existing `Texture`; may include too much duplication at the moment, but it's there.

**Compatible API & reconfiguring**: to support switching between atlas/non-atlas, adds `getMesh()` and `paintMesh()`, compatible with both. With a change to voxel-engine https://github.com/deathcap/voxel-engine/commit/58967dba81734134f1ad8d52b18d7203eafc27c3 either implementation can be used; specified at initialization with new `useAtlas` or changed afterwards with `reconfigure`: https://github.com/deathcap/voxel-debug/commit/26d9149db9a3a24309cac631e5bc8846521cb743

**Support for greedy meshes / texture tiling**: the main problem with atlases in v0.5.7 is how the UV coordinates are set, per vertex, causing the same texture to be stretched across the entire face of a greedily-meshed voxel – requiring the use of the non-greedy culled mesher instead, but that's much slower to remesh. So I implemented the technique described in http://0fps.wordpress.com/2013/07/09/texture-atlases-wrapping-and-mip-mapping/ - using the fractional part of the position world coordinate as the tile UV. Unfortunately this not all that elegant to implement in three.js, had to use a custom `ShaderMaterial`, but merging in some of three.js's own shader code to support lighting and such. I'm also not entirely clear how one is meant to (or if it is even possible) to assign attributes per geometry (instead of per material, which all the examples use, but we want only one material), so I (ab/re)used three's `faceVertexUvs` for this purpose, it works at least, but perhaps there is a better way (or maybe this is another reason to switch to a more modular graphics library – ndarray/gl-now https://github.com/voxel/issues/issues/4 where adding these kinds of features is easier, or they are already implemented :) e.g. in https://github.com/mikolalysenko/ao-shader)

**4-tap sampling**: fixes the artifacts near the edges due to the above feature (from same article). Repeats the textures 2x2 and takes four samples in the fragment shader (wasn't able to use atlaspack `tilepad` since it pads by half, and this algorithm requires four copies), works very well to fix the texture edges. This feature can also be enabled/disabled by an option `useFourTap` (also configurable in https://github.com/deathcap/voxel-debug/commit/f71ef9ec0e46e93b9ba33b78c93b08031c6cfd3a), mainly for testing purposes.

cheers