Code: Select all
float4x4 matViewProjection;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 inTxr1 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 inTxr1 : TEXCOORD0;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( Input.Position, matViewProjection );
Output.inTxr1 = Input.inTxr1;
return( Output );
}
// The constants
float minHeight1 = 0.0f;
float maxHeight1 = 0.7f;
float minHeight2 = 0.3f;
float maxHeight2 = 1.0f;
// Calculate percentage1
float Percentage1(float height, float minHeight, float maxHeight)
{
// The percentage
float p = 0.0f;
// Check to see if it's in the boundaries
if(height<=maxHeight)
{
// Calculate percentage
p = 1.0f - (height/(maxHeight - minHeight));
}
// Return it
return p;
}
// Calculate percentage2
float Percentage2(float height, float minHeight, float maxHeight)
{
// The percentage
float p = 0.0f;
// Check to see if it's in the boundaries
if(height>=minHeight)
{
// Calculate percentage
p = (height - minHeight)/(maxHeight - minHeight);
}
// Return it
return p;
}
// Ground texture
sampler Texture0 : register(s0)
{
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
// Grass texture
sampler Texture1 : register(s1)
{
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
// Heightmap texture
sampler Texture2 : register(s2)
{
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
float4 ps_main(float2 inTxr1 : TEXCOORD0) : COLOR0
{
// Get the height from heightmap
float height = tex2D(Texture2, inTxr1).x;
// The percentages
float p1 = Percentage1(height, minHeight1, maxHeight1);
float p2 = Percentage2(height, minHeight2, maxHeight2);
return clamp( (p1 * tex2D(Texture0, inTxr1)) + (p2 * tex2D(Texture1, inTxr1)), 0, 1);
}
This works fine in RenderMonkey. But when I use these in Irrlicht :
Code: Select all
// Add a terrain node and set its properties
scene::ITerrainSceneNode *terrain = m_Smgr->addTerrainSceneNode("E:\\Program Files\\Mitsos\\irrlicht-1.2\\media\\terrain-heightmap.bmp");
terrain->setScale(core::vector3df(10.0f, 0.3f, 10.0f));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, m_Driver->getTexture("E:\\Program Files\\Mitsos\\irrlicht-1.2\\media\\texture-ground1.bmp"));
terrain->setMaterialTexture(1, m_Driver->getTexture("E:\\Program Files\\Mitsos\\irrlicht-1.2\\media\\drygrass.bmp"));
terrain->setMaterialTexture(2, m_Driver->getTexture("E:\\Program Files\\Mitsos\\irrlicht-1.2\\media\\terrain-heightmap.bmp"));
terrain->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
terrain->scaleTexture(10.0f, 10.0f);