smooth texture
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Well, what compiler are you using? Easiest bet to test it, would be to take one of the existing materials, and comment the code for it out, and the replace it with this code. For example, in CD3D9MaterialRenderer.h change this -
to this -
Here's the code I used to test this( not i'm using RAW format images for the alpha layer, which is only available in IrrSpintz, you'll have to create a PNG or TGA texture with alpha to use in Irrlicht, since it doesn't support RAW image loading. )
I'm doing some more testing, it's basically blending but for some reason, the 2nd texture( in the 3rd stage ) isn't being blended in properly, I'm looking at it.
Code: Select all
//! Solid 2 layer material renderer
class CD3D9MaterialRenderer_SOLID_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
};
Code: Select all
//! Solid 2 layer material renderer
class CD3D9MaterialRenderer_SOLID_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
//virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
// bool resetAllRenderstates, IMaterialRendererServices* services)
//{
// if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
// {
// pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
// pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
// pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
// pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
// pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
// pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// }
// services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
//}
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 );
}
};
Here's the code I used to test this( not i'm using RAW format images for the alpha layer, which is only available in IrrSpintz, you'll have to create a PNG or TGA texture with alpha to use in Irrlicht, since it doesn't support RAW image loading. )
Code: Select all
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNodeRAW( "D:\\Terrain\\FreeWorldExports\\terrain\\heightmap16bit.raw" );
terrain->setMaterialFlag( video::EMF_LIGHTING, false );
terrain->setMaterialTexture( 0, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Base.bmp" ) );
driver->setRAWImagerLoaderParams( 512, 512, 8 );
terrain->setMaterialTexture( 1, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Alpha_alpha.raw" ) );
terrain->setMaterialTexture( 2, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Alpha.bmp" ) );
terrain->setMaterialType( video::EMT_TEXTURE_SPLAT_2 );
I'm doing some more testing, it's basically blending but for some reason, the 2nd texture( in the 3rd stage ) isn't being blended in properly, I'm looking at it.
you mean this was all code needed? i going to check it out, in the dll right?
man irrlicht needs this in next release i quess
[edit] owh you posted more thnx
man irrlicht needs this in next release i quess
[edit] owh you posted more thnx
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
i got a terrain without light enabled and the model uses only yhe 3rd texture. the strangest is that with more than 6 lights the program crashes since this change.
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
crash fixed, but i still have that or the 2nd texture (alpha map) won't work or that 3rd texture is placed over everything.
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
and how can i do that?
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
i have under :
DirectX Graphics Adapters >
RADEON 9600 SERIES >
D3D Device Types >
Reference >
Caps >
PrimitiveMiscCaps
what i do the 3rd texture stays ontop. i use an tga, do i have to set it first with transparency before applying on the terrain?
DirectX Graphics Adapters >
RADEON 9600 SERIES >
D3D Device Types >
Reference >
Caps >
PrimitiveMiscCaps
what i do the 3rd texture stays ontop. i use an tga, do i have to set it first with transparency before applying on the terrain?
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
after changing some stuff i get this:
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
and to exlude other coords i did
but that doesn't work, i get than a gray surface
Code: Select all
node->getMaterial(0).Texture1 = texture1;
node->getMaterial(0).Texture2 = texture2;
node->getMaterial(0).Texture3 = texture3;
node->getMaterial(0).MaterialType = video::EMT_SOLID_2_LAYER;
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
that screenshot looks like its working. It looks like you scaled the texture coordinates of your alpha layer. Oh, I can't believe I forgot about texture coords. What scenenode/mesh are you using to render that stuff???? Problem is, we're using a material which has 3 texture stages but Irrlicht meshes only support 1 or 2 texture coordinates. You can, in DX tell a texture stage to use texture coordinates of another texture stage. I don't have DX on this laptop I'm on at work yet( just got a new laptop ), I'll try to look the call up on the web and let you know.
i use IScenenode and IAnimatedMeshSceneNode's,
the second ( alpha mapping ) needs to fit in the model, the 3rd is allowed to be tiled
the second ( alpha mapping ) needs to fit in the model, the 3rd is allowed to be tiled
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99