Re-added Matt's changes which I deleted by mistake.
This commit is contained in:
parent
d7e24afdec
commit
8ccfb46d97
@ -15,7 +15,7 @@ Traditionally meshes are textured by providing a pair of UV texture coordinates
|
||||
By reading this document you should learn how to work around the above problems, though you will almost certainly need to follow provided links and do some further reading as we have only summarised the key ideas here.
|
||||
|
||||
Mapping textures to mesh geometry
|
||||
================================
|
||||
=================================
|
||||
The lack of UV coordinates means some lateral thinking is requried in order to apply texture maps to meshes. But before we get to that, we will first try to explain the rational behind PolyVox not providing UV coordinates in the first place. This rational is different for the smooth voxel meshes vs the cubic voxel meshes.
|
||||
|
||||
Rational
|
||||
@ -30,6 +30,7 @@ Triplanar Texturing
|
||||
-------------------
|
||||
The most common approach to texture mapping smooth voxel terrain is to use *triplanar texturing*. The basic idea is to project a texture along all three main axes and blend between the three texture samples according to the surface normal. As an example, suppose that we wish to write a fragment shader to apply a single texture to our terrain, and assume that we have access to both the world space position of the fragment and also its normalised surface normal. Also, note that your textures should be set to wrap because the world space position will quickly go outside the bounds of 0.0-1.0. The world space position will need to have been passed through from earlier in the pipeline while the normal can be computed using one of the approaches in the lighting (link) document. The shader code would then look something like this [footnote: code is untested as is simplified compared to real world code. hopefully it compiles, but if not it should still give you an idea of how it works]:
|
||||
|
||||
.. code-block:: c++
|
||||
// Take the three texture samples
|
||||
vec4 sampleX = texture2d(inputTexture, worldSpacePos.yz); // Project along x axis
|
||||
vec4 sampleY = texture2d(inputTexture, worldSpacePos.xz); // Project along y axis
|
||||
@ -42,6 +43,7 @@ Note that this approach will lead to the texture repeating once every world unit
|
||||
|
||||
This idea of triplanar texturing can be applied to the cubic meshes as well, and in some ways it can be considered to be even simpler. With cubic meshes the normal always points exactly along one of the main axes, and so it is not necessary to sample the texture three times nor to blend the results. Instead you can use conditional branching in the fragment shader to determine which pair of values out of {x,y,z} should be used as the texture coordintes. Something like:
|
||||
|
||||
.. code-block:: c++
|
||||
vec4 sample = vec4(0, 0, 0, 0); // We'll fill this in below
|
||||
// Assume the normal is normalised.
|
||||
if(normal.x > 0.9) // x must be one while y and z are zero
|
||||
@ -64,6 +66,7 @@ Both the CubicSurfaceExtractor and the MarchingCubesSurfacExtractor understand t
|
||||
|
||||
The following code snippet assumes that you have passed the material identifier to your shaders and that you can access it in the fragment shader. It then chooses which colour to draw the polygon based on this identifier:
|
||||
|
||||
.. code-block:: c++
|
||||
vec4 fragmentColour = vec4(1, 1, 1, 1); // Default value
|
||||
if(materialId < 0.5) //Avoid '==' when working with floats.
|
||||
{
|
||||
@ -142,7 +145,7 @@ However, the biggest problem with texture atlases is that they causes problems w
|
||||
It is possible to combat these problems but the solution are non-trivial. You will want to limit the number of miplevels which you use, and probably provide custom shader code to handle the wrapping of texture coordinates, the sampling of MIP maps, and the calculation of interpolated values. You can also try adding a border around all your packed textures, perhaps by duplicating each texture and offsetting by half its size. Even so, it's not clear to us at this point whether the the various artefacts can be completely removed. Minecraft handles it by completely disabling texture filtering and using the resulting pixelated look as part of its asthetic.
|
||||
|
||||
3D texture slices
|
||||
-------------
|
||||
-----------------
|
||||
The idea here is similar to the texture atlas approach, but rather than packing texture side-by-side in an atlas they are instead packed as slices in a 3D texture. We haven't actually tested this but in theory it may have a couple of benefits. Firstly, it simplifies the addressing of the texture as there is no need to offset/scale the UV coordinates, and the W coordinate (the slice index) can be more easily computed from the material identifier. Secondly, a single volume texture will usually be able to hold more texels than a single 2D texture (for example, 512x512x512 is bigger than 4096x4096). Lastly, it should simplify the filtering problem as packed textures are no longer tiled and so should wrap correctly.
|
||||
|
||||
However, MIP mapping will probably be more complex than the texture atlas case because even the first MIP level will involve combining adjacent slices. Volume textures are also not so widely supported and may be particularly problematic on mobile hardware.
|
||||
|
@ -64,4 +64,4 @@ It might be useful to provide a thread safe wrapper around the volume classes, a
|
||||
|
||||
OpenMP
|
||||
------
|
||||
This is a standard for extending C++ with compiler directives which allow the compiler to automatically parallise sections of code. Most likely this could be used to parallise some of the loops which occur in image processing tasks.
|
||||
This is a standard for extending C++ with compiler directives which allow the compiler to automatically parallise sections of code. Most likely this could be used to parallelise some of the loops which occur in image processing tasks.
|
@ -6,10 +6,17 @@ Contents:
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Prerequisites
|
||||
install
|
||||
principles
|
||||
Lighting
|
||||
TextureMapping
|
||||
ModifyingTerrain
|
||||
LevelOfDetail
|
||||
Threading
|
||||
tutorial1
|
||||
changelog
|
||||
FAQ
|
||||
|
||||
|
||||
Indices and tables
|
||||
|
Loading…
x
Reference in New Issue
Block a user