how do i create that effect with irrlicht ? i thought 3 layers but that
didn't worked, and to greate 1 big texture for the ground is a easy
but not nice for preformance.
you see here between the grass and the road
![Image](http://www.terragame.com/images/games/big53.jpg)
and here:
![Image](http://www.gamona.de/static/handler-image_generator/hash-47a6d93ef671901338c14989fb819d1b.jpg)
Code: Select all
//! material renderer to perform texture splatting
class CD3D9MaterialRenderer_TEXTURE_SPLAT : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TEXTURE_SPLAT(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial()
{
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR );
}
};
Code: Select all
class COpenGLMaterialRenderer_TEXTURE_SPLAT : public COpenGLMaterialRenderer
{
public:
COpenGLMaterialRenderer_TEXTURE_SPLAT(video::COpenGLDriver* d)
: COpenGLMaterialRenderer(d) {}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures( 2 );
if( Driver->queryFeature( EVDF_MULTITEXTURE ) )
{
Driver->extGlActiveTextureARB( GL_TEXTURE1_ARB );
// texture
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE );
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS );
Driver->extGlActiveTextureARB( GL_TEXTURE0 );
}
// alpha map
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial()
{
if( Driver->queryFeature( EVDF_MULTITEXTURE ) )
{
Driver->extGlActiveTextureARB( GL_TEXTURE1 );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE );
Driver->extGlActiveTextureARB( GL_TEXTURE0 );
}
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE );
glDisable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ZERO );
}
};
Code: Select all
//! material renderer to perform texture splatting
class CD3D9MaterialRenderer_TEXTURE_SPLAT_2 : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TEXTURE_SPLAT_2(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
// base texture( texture stage 0, normal operations, but save them to the temp register )
pID3DDevice->SetTextureStageState( 0, D3DTSS_RESULTARG, D3DTA_TEMP );
// alpha texture( texture stage 1, we just need to grab the alpha value from the texture at this stage
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
// this the the blend texture, we want to blend this color with the color from texture stage 0( which is
// in the temp register ) using the alpha we got from texture stage 1.
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TEMP );
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial()
{
// base texture( texture stage 0, return the target to current, rather than the temp register )
pID3DDevice->SetTextureStageState( 0, D3DTSS_RESULTARG, D3DTA_CURRENT );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );
}
};