The Screenshot is here:
http://lcgamestudio.spaces.live.com/pho ... 2D45F!120/
And can download code:
http://uploader.polorix.net//files/1431 ... atting.zip
and modified engine code here:
http://uploader.polorix.net//files/1431 ... 20Code.zip
And I want to implement it with Irrlicht and without pixel shader.
Here is the code:
1. I added the CD3D9MaterialRenderer_SPLATTING class in CD3D9MaterialRenderer.h file:
Code: Select all
//! For texture splatting without pixelshader
class CD3D9MaterialRenderer_SPLATTING : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SPLATTING(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
// Do some normal state settings
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
pID3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
// Allow multiple passes to blend together correctly
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pID3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// Prevent some ugliness with the alphamaps
pID3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
pID3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
pID3DDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// Alphamap: take the alpha from the alphamap, we don't care about the color
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
// Texture: take the color from the texture, take the alpha from the previous stage
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
}
}
};
Code: Select all
{
// create D3D9 material renderers
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_SOLID(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_SOLID_2_LAYER(pID3DDevice, this));
// add the same renderer for all lightmap types
CD3D9MaterialRenderer_LIGHTMAP* lmr = new CD3D9MaterialRenderer_LIGHTMAP(pID3DDevice, this);
addMaterialRenderer(lmr); // for EMT_LIGHTMAP:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_ADD:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M2:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M4:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M2:
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M4:
lmr->drop();
// add remaining fixed function pipeline material renderers
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_DETAIL_MAP(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_SPHERE_MAP(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_REFLECTION_2_LAYER(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_TRANSPARENT_ADD_COLOR(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(pID3DDevice, this));
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(pID3DDevice, this));
// add normal map renderers
s32 tmp = 0;
video::IMaterialRenderer* renderer = 0;
renderer = new CD3D9NormalMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_SOLID].Renderer);
renderer->drop();
renderer = new CD3D9NormalMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer);
renderer->drop();
renderer = new CD3D9NormalMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer);
renderer->drop();
// add parallax map renderers
renderer = new CD3D9ParallaxMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_SOLID].Renderer);
renderer->drop();
renderer = new CD3D9ParallaxMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer);
renderer->drop();
renderer = new CD3D9ParallaxMapRenderer(pID3DDevice, this, tmp,
MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer);
renderer->drop();
// add basic 1 texture blending
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_ONETEXTURE_BLEND(pID3DDevice, this));
//===========================Added by Locosoftware=================================
// add texture splatting (Added by Locosoftware)
addAndDropMaterialRenderer(new CD3D9MaterialRenderer_SPLATTING(pID3DDevice, this));
//=================================================================================
}
Code: Select all
enum E_MATERIAL_TYPE
{
//! Standard solid material. Only first texture is used, which is
//! supposed to be the diffuse material.
EMT_SOLID = 0,
........
........
........
//===========================Added by Locosoftware=================================
//! Texture splatting effect without pixelshader. The vertex format must include
//! two texture coordinates. (Only for Direct3D 9 and 8 now)
EMT_TEXTURE_SPLATTING ,
//=================================================================================
//! This value is not used. It only forces this enumeration to compile in 32 bit.
EMT_FORCE_32BIT = 0x7fffffff
};
Code: Select all
//! Array holding the built in material type names
const char* const sBuiltInMaterialTypeNames[] =
{
"solid",
"solid_2layer",
"lightmap",
"lightmap_add",
"lightmap_m2",
"lightmap_m4",
"lightmap_light",
"lightmap_light_m2",
"lightmap_light_m4",
"detail_map",
"sphere_map",
"reflection_2layer",
"trans_add",
"trans_alphach",
"trans_alphach_ref",
"trans_vertex_alpha",
"trans_reflection_2layer",
"normalmap_solid",
"normalmap_trans_add",
"normalmap_trans_vertexalpha",
"parallaxmap_solid",
"parallaxmap_trans_add",
"parallaxmap_trans_vertexalpha",
"onetexture_blend",
"texture_splatting", // added for texture splatting by locosoftware
0
};