I have created a CustomSceneNode on which I add 2 textures. (I chose to create a customSceneNode for learning purpose)
On the '0' layer I have a background texture and on the '1' layer I have a foreground texture with alpha channel.
Of course, I use the setMaterialTexture to do it.
Here are the code of the OnRegisterSceneNode(), render(), setMaterialTexture() functions of my CustomSceneNode
Code: Select all
void CIrrHexagoneSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
void CIrrHexagoneSceneNode::render()
{
u16 indices[] = { 0,1,2,3,4,5,6,1 };
irr::video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleFan(&Vertices[0], 7, &indices[0], 6);
}
void CIrrHexagoneSceneNode::setMaterialTexture(u32 textureLayer, video::ITexture* texture)
{
Material.setTexture(textureLayer, texture);
}
As Irrlicht can't do this I had to learn Shaders to blend the textures.
This is the onSetConstant() of my callBack
Code: Select all
void CShaderCallBack::OnSetConstants(video::IMaterialRendererServices* pServices, s32 userData)
{
// on récupère un pointeur sur VideoDriver
video::IVideoDriver* pDriver = pServices->getVideoDriver();
// Matrice WorldViewProj
core::matrix4 mWorldViewProj;
mWorldViewProj = pDriver->getTransform(video::ETS_PROJECTION);
mWorldViewProj *= pDriver->getTransform(video::ETS_VIEW);
mWorldViewProj *= pDriver->getTransform(video::ETS_WORLD);
// on l'envoie au GPU
pServices->setVertexShaderConstant("mWorldViewProj", mWorldViewProj.pointer(), 16);
}
Code: Select all
uniform float4x4 mWorldViewProj;
// Vertex shader output structure
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float2 TexCoord0 : TEXCOORD0; // tex 0 coords
float2 TexCoord1 : TEXCOORD1; // tex 1 coords
};
VS_OUTPUT vertexMain( in float4 vPosition : POSITION, float2 texCoord0 : TEXCOORD0, float2 texCoord1 : TEXCOORD1 )
{
VS_OUTPUT Output;
Output.Position = mul(vPosition, mWorldViewProj);
Output.TexCoord0 = texCoord0;
Output.TexCoord1 = texCoord1;
return Output;
}
uniform sampler2D texsol : register(s0);
uniform sampler2D texherbe : register(s1);
// Pixel shader output structure
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};
PS_OUTPUT pixelMain( VS_OUTPUT Input )
{
PS_OUTPUT Output;
float4 col0 = tex2D(texsol, Input.TexCoord0);
float4 col1 = tex2D(texherbe, Input.TexCoord1);
Output.RGBColor.rgb = col0.rgb * (1.0f - col1.a) + col1.rgb * col1.a;
Output.RGBColor.a =col0.a;
return Output;
}
I thonk the problems comes from my customSceneNode but I can't find it despite many help on another forum.
Maybe someone here can help me.