First of all I should say that from the point of view of PolyVox there is no single correct way to handle multiple materials in a smooth voxel terrain. PolyVox provides you with vertices with a material identifier attached but how you use this is completely up to you. So all of these ideas do have some merit.
The solution I described in the Game Engine Gems article does work quite well, but I'll be interested to see whether I can come up with a better approach which requires less messing around with the geometry (duplicating/splitting triangles, etc). The solution was also limited to a single matieral identifier per voxel so I might try and raise this limit. If it goes well I hope to write another article in the future as there doesn't seem to be much published material on this topic.
DJDD wrote:
Hey David, in regards to material blending I found this article on Stencil Mapping to be extremely helpful:
http://archive.gamedev.net/archive/refe ... le934.htmlInteresting, but have you actually tried implementing something like this on a smooth voxel terrain? It looks like you need to define quite a lot of transition textures, and it seems quite specific to tile based maps. I can imagine a variation on this scheme might work on Mincraft style terrain and this is something I'd never considered. The transitions certainly look more natural and the precedence idea is nice.
Kaveh Rassoulzadegan wrote:
I may be severely mistaken since you probably already did an extensive homework to end up by duplicating triangles + alpha tests(cf. your doc), but would it be possible to pass atlas offsets or texture ID's(if testing with reasonable number of texture units) instead of alpha values, fetch in and mix them in your gpu's fragment pipeline ? (hereby turning off alpha blending + using a single face)
Yes, it is possible to use a single pass approach which mixes textures in the fragment shader and avoids the need for blending. We have
some code in the Wiki which does something like this but I didn't write it myself and so I'm not very familier with it. It still has to handle the scenario where a given triangle has a different material identifier for each vertex, and in this solution a lot of per-vertex data and triangle duplication is performed to handle this. It might be that the solution can be trimmed down but I haven't looked at this in detail.
Kaveh Rassoulzadegan wrote:
I am not sure to understand why you need an alpha value unless you possibly want your gradient to take place somehow more progressively, over more than between two vertices ? But if all vertices share the same ID, you said in the doc that you set alpha to full ?
If all three vertices of a given triangle have the same material (the article calls this a
uniform triangle) then there's no need to make use of the alpha or blending at all. If the article appears to say something different then please give an exact quote and I'll try to clarify.
The difficult case is when a triangle has a different matierial identifier at each vertex (a
non-uniform triangle). It is in this case that you need to render the triangle three times and make use of the alpha values to combine the resulting fragments correctly.
Kaveh Rassoulzadegan wrote:
Do you really need different blending values (other than 0.5) for vertices of faces sharing different textures and faces dupes ?
I'm not sure I fully understand this point. But if you have a non-uniform triangle which has (for example) 'rock', 'sand', and 'grass' as its materials then the rendered result should not just be a mix of these three but should instead be a smooth transition between them.
Kaveh Rassoulzadegan wrote:
Sorry if I misunderstood and if these are ultra-noob questions but I have just quickly visited your thermite cg code and for sure probably ignore further polyvox core implications.
It's good to challenge the assumptions I have made as this system has not been widely reviewed (and I haven't used it myself since writing the article so my memory is a little hazy). It's quite possible that there are some clever tricks I'm missing. If you do want to think about material support for your dual contouring implementation then you might also find
Section 5.3 of Eric Lengyel's PhD thesis interesting.