I have been using Irrlicht on and off for a few years, but in the last few months I have really been diving into it. I did not have any familiarity with shaders before Irrlicht, so I have been getting familiar with them through the use of two illustrative examples, texture splatting and water.
I have successfully written a texture splatting shader that only uses 3 textures and a splatmap, but I am struggling with the multiple pass one.
I am using the Multitexturingmanager( from freetimcoder) viewtopic.php?f=9&t=38676&p=225314&hili ... re#p225314, and I understand how the shader part works, but I am struggling with the part that blends the passes together.
As you can see in the two images, the stone blends smoothly with the grass, because that is handled in the shader, i.e. they exist on the same splatmap. But, for the pebbles and grass, there is a alpha border in their blending region, which should be handled by the engine, not the shader, since they are part of different shader passes.
The texture still has regions with alpha less than 1.0, whereas I would think it should blend the textures together such that alpha is 1.0 everywhere. This is most obvious to see when my background filters through the terrain (I switch between a skybox and sky dome to see what areas are affected). I am pretty sure the culprit is the blending operations, but I am not very familiar with that, so I simply use the ones from this topic viewtopic.php?f=4&t=51151&p=296627&hili ... ng#p296627, which he says fixed his multi-texturing problems.
Initializing the shader
Code: Select all
const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_DEFAULT;
if (driverType == video::EDT_OPENGL) {
psFileName = "../shaders/TexSplatting_ps.glsl";
vsFileName = "../shaders/TexSplatting_vs.glsl";
//Create the shader material
shaderMaterial = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
vsFileName, "main", video::EVST_VS_1_1,
psFileName, "main", video::EPST_PS_1_1,
this, video::EMT_ONETEXTURE_BLEND, 0, shadingLanguage);
}
Code: Select all
for (u32 j = 0; j < array_Nodes[i].array_Passes.size(); j++) {
array_Nodes[i].Node->setMaterialTexture(0, array_Nodes[i].array_Passes[j]->splat_texture);
array_Nodes[i].Node->setMaterialTexture(1, array_Nodes[i].array_Passes[j]->red_texture);
array_Nodes[i].Node->setMaterialTexture(2, array_Nodes[i].array_Passes[j]->green_texture);
array_Nodes[i].Node->setMaterialTexture(3, array_Nodes[i].array_Passes[j]->blue_texture);
if (array_Nodes[i].Node->getType() == scene::ESNT_TERRAIN) {
video::SMaterial material = array_Nodes[i].Node->getMaterial(0);
material.MaterialType = (video::E_MATERIAL_TYPE)shaderMaterial;
material.BlendOperation = video::EBO_ADD;
material.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA);
driver->setMaterial(material);
driver->drawMeshBuffer(((scene::ITerrainSceneNode*)array_Nodes[i].Node)->getRenderBuffer());
}