Create material at runtime for voxel terrain

I finally got some voxels working in lumberyard. I have hacked in a voxel terrain in cryengines main code base. I have the voxels generating/meshing and I am creating a RenderMesh for each of the chunks. I need to apply a material to the render mesh in order to get the textures showing.

The texture is generated at runtime by the voxel library, it generates a texture atlas based on the block types in use. I need to create a material with this texture so that the texture can then be rendered out on the block. What is the best way to handle this?

I have created the mesh with the texture uv set to the pixel locations needed on the texture. I attempted to load the material_terrain_default material and use it. However if I use it directly I just get white blocks. I tried to replace the texture by loading the material and swapping the texture via

    uint8 diffuseSlot=gEnv->p3DEngine->GetMaterialHelpers().FindTexSlot("Diffuse"); //Bumpmap, Specular

    SShaderItem &shaderItem=m_voxelMaterial->GetShaderItem();
    IRenderShaderResources *shaderResources=shaderItem.m_pShaderResources;
    TexturesResourcesMap *pTextureReourcesMap=shaderResources->GetTexturesResourceMap();
    SEfResTexture *textureResource=&(*pTextureReourcesMap)[diffuseSlot];

but something happened as I got

<11:10:32> [Error] Failed to create an input layout for material "materials/material_terrain_default".
The shader and the vertex formats may be incompatible.
Vertex format: "1".  Shader expects: "5".

I use SVF_P3F_C4B_T2F (which is eVF_P3F_C4B_T2F=1) on the RenderMeshes, eVF_P3S_N4B_C4B_T2S=5 so I am guessing the Terrian.Layer shader is likely not the best one to use, unless I want to stuff the normals.

Is there a better material to start with? What is the proper way to set the texture on the material? Is there a better way to do this?

I switched to using the Illum shader and replacing to the texture using the above and it seems to work for the moment.

That voxel system is triangles built inside cubes, correct? It is so inferior to what should be coded into Lumberyard, and it wouldn’t even take long. Soon as I can I’m going to code up a new voxel system which uses a coordinate system to draw polygons in a compressible format allowing less than 1 degree in any lateral direction and about 1.4d inclination. It will be difficult to see the imperfection, but there must be some imperfection if massive planet scale terrain blocks are to be compressible. The method of mining would certainly save a lot of data usage, so a mining machine that would mine straight lines would be ideal. Any pattern than can be repeated is easier to compress.
Keep in mind if you’re using someone else’s code, there are patents on code, like the most efficient way to compress voxel data, and you’d never be able to share your game publicly.