READ THE RULES: Click here

Follow us on Facebook: :)

Drawing a voxel mesh with multiple materials

Get your graphics formats figures out here! Got details for others? Post here!
Post Reply
Posts: 1
Joined: Mon Aug 05, 2019 10:25 am

Drawing a voxel mesh with multiple materials

Post by Berlin77 » Mon Aug 05, 2019 10:30 am

I'm currently working on a voxel renderer in which I have chunks of voxels (16x16x16) for which I create a single mesh. I will do so by adding all the visible block faces to a mesh and combining neighboring quads that use the same material to reduce the triangle count.

Normally I would use something like an array texture or texture atlas to account for the different textures on each triangle. That would allow me to draw the entire mesh in a single draw call. Unfortunately, I want to use a material struct which also holds information such as color and specularity.

My initial plan was to create multiple index buffers for the mesh sorted by material. That would allow me to bind the mesh once. I would then loop over the index buffer / material pairs and set the material uniform before drawing this part of the mesh. The downside is that I would need to do a draw call for each individual material. I am not sure how much this would slow down, but I imagine it can't be very performant right?
Another idea I played around with, is to use uniform arrays of materials in the shader. If I could store the correct index of the material to use in each vertex. I would only need a single draw call as long as long as my material count doesn't exceed the maximum size of the uniform array. I would do the same thing for my textures using sampler2D arrays.xnxx xxx
Last edited by Berlin77 on Tue Aug 06, 2019 8:44 pm, edited 1 time in total.

Posts: 125
Joined: Fri Oct 16, 2015 8:05 pm
Has thanked: 3 times
Been thanked: 64 times

Re: Drawing a voxel mesh with multiple materials

Post by episoder » Mon Aug 05, 2019 11:35 am

not exactly the correct forum section.

minecraft type of rendering? use a general shader with specular enabled and specular textures. it's easier to manage. also, if you use a texture2d array like a stack of same size textures you essentially have a easy way of indexing the textures by material id aka the depth in the stack.

the other way you could do it without the spec texture is if you would preprocess the quads (2 triangle)s and add a specular value into a 'per face' instance buffer while the vertices still have the simple data. that means if that works. usually when using instances (in dx9 it's SetStreamSourceFreq), the same faces are rendered multiple times. that's the other way around.
no pm requests. diy.

Post Reply