From 17827fe8a62493809435028c9a1cdc32ea8eb7c2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Sep 2012 00:20:42 +0200 Subject: [PATCH] Tidying up documentation files. --- documentation/ModifyingTerrain.rst | 4 +++- documentation/TextureMapping.rst | 20 +++++++++++++------- documentation/index.rst | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/documentation/ModifyingTerrain.rst b/documentation/ModifyingTerrain.rst index a3760bfd..7bc06a15 100644 --- a/documentation/ModifyingTerrain.rst +++ b/documentation/ModifyingTerrain.rst @@ -1 +1,3 @@ -Placeholder. \ No newline at end of file +================= +Modifying Terrain +================= \ No newline at end of file diff --git a/documentation/TextureMapping.rst b/documentation/TextureMapping.rst index f3c7691c..78ee992f 100644 --- a/documentation/TextureMapping.rst +++ b/documentation/TextureMapping.rst @@ -4,13 +4,16 @@ Texture Mapping The PolyVox library is only concerned with operations on volume data (such as extracting a mesh from from a volume) and deliberatly avoids the issue of rendering any resulting polygon meshes. This means PolyVox is not tied to any particular graphics API or rendering engine, and makes it much easier to integrate PolyVox with existing technology, because in general a PolyVox mesh can be treated the same as any other mesh. However, the texturing of a PolyVox mesh is usually handled a little differently, and so the purpose of this document is to provide some ideas about where to start with this process. This document is aimed at readers in one of two positions: -1) You are trying to texture 'Minecraft-style' terrain with cubic blocks and a number of different materials. -2) You are trying to texture smooth terrain produced by the Marching Cubes (or similar) algoritm. + +1. You are trying to texture 'Minecraft-style' terrain with cubic blocks and a number of different materials. +2. You are trying to texture smooth terrain produced by the Marching Cubes (or similar) algoritm. + These are certainly not the limit of PolyVox, and you can choose much more advanced texturing approaches if you wish. For example, in the past we have texture mapped a voxel Earth from a cube map and used an animated *procedural* texture (based on Perlin noise) for the magma at the center of the Earth. However, if you are aiming for such advanced techniques then we assume you understand the basics in this document and have enough knowledge to expand the ideas yourself. But do feel free to drop by and ask questions on our forum. Traditionally meshes are textured by providing a pair of UV texture coordinates for each vertex, and these UV coordinates determine which parts of a texture maps to each vertex. The process of texturing PolyVox meshes is more complex for a couple of reasons: -1) PolyVox does not provide UV coordinates for each vertex. -2) Voxel terrain (particulaly Minecraft-style) often involves many more textures than the GPU can read at a time. + +1. PolyVox does not provide UV coordinates for each vertex. +2. Voxel terrain (particulaly Minecraft-style) often involves many more textures than the GPU can read at a time. 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. @@ -30,7 +33,8 @@ 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++ +.. code-block:: glsl + // 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 @@ -43,7 +47,8 @@ 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++ +.. code-block:: glsl + 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 @@ -66,7 +71,8 @@ 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++ +.. code-block:: glsl + vec4 fragmentColour = vec4(1, 1, 1, 1); // Default value if(materialId < 0.5) //Avoid '==' when working with floats. { diff --git a/documentation/index.rst b/documentation/index.rst index e88fb3b2..4512d077 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -1,10 +1,10 @@ Welcome to PolyVox's documentation! =================================== -Contents: +User Guide: .. toctree:: - :maxdepth: 2 + :maxdepth: 1 Prerequisites install @@ -14,7 +14,20 @@ Contents: ModifyingTerrain LevelOfDetail Threading + + +Examples: + +.. toctree:: + :maxdepth: 1 + tutorial1 + +Other Information: + +.. toctree:: + :maxdepth: 1 + changelog FAQ