Using Shaders in Voxel Engines (With Procedural Meshes)

Hi all,

I’ve been making my own unique twist on a voxel game now. And one thing that’s confusing me is how I would go about using shaders.

The thing is, I have little experience with shaders. And I’m going to need to use shaders for all kinds of things (I assume lighting being one of them).

I use Shader Forge to make shaders. And I know in Unity you make a material and assign a shader to the material. And that’s about my knowledge right there.

Let’s say I’m not using Unity’s material system, and I’m generating meshes procedurally as is done in a voxel engine (where I define vertices, triangles, UVs). Now how on Earth would I go about using shaders on the blocks?

I read somewhere that it relates to UV mapping, or something of the sort. But I’m honestly clueless. How would I use UV mapping to work with a shader?

So what I’m asking for here is for you to give me a direction to go in. Even if you don’t give a detailed explanation, perhaps you could link me to something that will help me learn about this?

Thanks in advance, it’s much appreciated.

-Jason

PS: I have searched a lot for this answer, and I can’t seem to find much that answers the actual question I have. But if you know of an answer I missed, do let me know.

There isn’t anything to it, as long as you have a meshrenderer you can use any materials you want, no matter if the mesh is pre-fabricated or procedurally generated at runtime.

After generating your vertices, triangles, and uvs, you just pass the materials to the renderer:

renderer.material = material;//if using a single mesh with one material
renderer.materials = materialArray;//if using submeshes

If you want to use multiple materials, you need to have at least as many materials as there are submeshes. I suggest creating only as many submeshes as you need different materials.

check this thread, especially the linked page and following:

After playing minecraft…