Problem with transparncy textures & nodes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Problem with transparncy textures & nodes

Post by codebaker »

hi at all,

i have the following problem. I hope i can describe it correctly. I have three textures (space, ship and clouds) all with alphashannel. When i texture Billboards it works all correctly. Now i have make my own SceneNode and than it dont work. Here two Pictures.
with billboards
Image

with my own scenenode
Image

if i change the Texture loading order than i take an different effect. this load order is: first ship than space than clouds. Here some Code from my scenenode where could be the problem is.

the constructor

Code: Select all

IMySceneNode::IMySceneNode(ISceneNode* _parent, scene::ISceneManager* _mgr, video::ITexture *_texture): 
scene::IMeshSceneNode(_parent, _mgr, -1) 
{
        _m_imageSize                    = _texture->getSize();
 
        indices[0] = 0;
        indices[1] = 2;
        indices[2] = 1;
        indices[3] = 0;
        indices[4] = 3;
        indices[5] = 2;
 
        vertices[0].Pos.set((f32)_m_imageSize.Width,-(f32)_m_imageSize.Height,0);
        vertices[0].TCoords.set(1.0f, 1.0f);
        vertices[0].Color = 0xffffffff;
 
        vertices[1].Pos.set((f32)_m_imageSize.Width,0,0);
        vertices[1].TCoords.set(1.0f, 0.0f);
        vertices[1].Color = 0xffffffff;
 
        vertices[2].Pos.set(0,0,0);
        vertices[2].TCoords.set(0.0f, 0.0f);
        vertices[2].Color = 0xffffffff;
 
        vertices[3].Pos.set(0,-(f32)_m_imageSize.Height,0);
        vertices[3].TCoords.set(0.0f, 1.0f);
        vertices[3].Color = 0xffffffff;
 
        bbox.reset(vertices[0].Pos);
        bbox.addInternalPoint(vertices[1].Pos);
        bbox.addInternalPoint(vertices[2].Pos);
        bbox.addInternalPoint(vertices[3].Pos);
 
        _m_material.setTexture(0, _texture);
        _m_material.setFlag(video::EMF_LIGHTING, false);
        _m_material.MaterialType = video::EMT_ONETEXTURE_BLEND;
        _m_material.MaterialTypeParam = video::pack_texureBlendFunc(
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA, 
                irr::video::EMFN_MODULATE_1X, 
                irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
}
 
register node

Code: Select all

void IMySceneNode::OnRegisterSceneNode() 
{
        if (IsVisible)
                SceneManager->registerNodeForRendering(this);
 
        ISceneNode::OnRegisterSceneNode();
}
 
render node

Code: Select all

void ISpriteSceneNode::render() 
{ 
        if(!IsVisible)
                return;
 
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->setMaterial(_m_material);
        driver->drawIndexedTriangleList(
                        vertices, 
                        4, 
                        indices, 
                        2);
}
 
I set the positions of the
ship-node to 0, 0, 30
cloud-node to 0, 0, 50
space-node to 0, 0, 90

(in both examples)

I hope someone can help me, please.

Sorry for my bad english :?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Problem with transparncy textures & nodes

Post by hybrid »

Did you implement the getMaterial methods properly? The scene manager uses them to check whether the material uses transparency.
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Re: Problem with transparncy textures & nodes

Post by codebaker »

Yes i do. This is the code.

Code: Select all

video::SMaterial &IMySceneNode::getMaterial(u32 _id) 
{
        return _m_material;
};
 
        
u32 IMySceneNode::getMaterialCount()
{
        return 1;
};
 
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Problem with transparncy textures & nodes

Post by hybrid »

Nope, that's not correct. You must define getMaterialCount as const, otherwise the default setting (0 materials) is used. Then it should work correctly.
BTW: Just for setting up a simple quad mesh you don't need to define a custom scene node. Those are just required if specialized render techniques are necessary.
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Re: Problem with transparncy textures & nodes

Post by codebaker »

many, many , many thanks.
NOW IT WORKS.
I love you. :lol:
I know it was simple.
hybrid wrote:BTW: Just for setting up a simple quad mesh you don't need to define a custom scene node. Those are just required if specialized render techniques are necessary.
yes I know. But I only have show you a small part of the code and is to be expanded later. Perhaps with spezialized render techniques. And it will be not limited mith a single quad ;) .
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Re: Problem with transparncy textures & nodes

Post by codebaker »

hmmmm,

I will not annoy but now there is a similar problem. This time even with a billboard test. I dont know, is this a bug? Or I'm to stupid? :?

Here again a screenshot
Image
and the code.

Code: Select all

 
#include <irrlicht.h>
using namespace irr;
 
IrrlichtDevice                  *g_pDevice;
video::IVideoDriver             *g_pDriver;
scene::ISceneManager    *g_pSMng;
 
int main()
{
    g_pDevice = createDevice(video::EDT_DIRECT3D9, core::dimension2d<u32>(640, 480), 32);
    if (g_pDevice == 0)
        return 1;
    
        g_pDriver = g_pDevice->getVideoDriver();
        
        g_pSMng         = g_pDevice->getSceneManager();
 
        scene::ISceneNode *node = g_pSMng->addEmptySceneNode();
        node->setPosition(core::vector3df(-320, 240, 0));
 
        scene::ICameraSceneNode *cam = g_pSMng->addCameraSceneNode();
        cam->setPosition(core::vector3df(0, 0, -15));
        core::matrix4   orthProj;
        orthProj.buildProjectionMatrixOrthoLH(
                640, 480, 1.0f, 200.0f);
        cam->setProjectionMatrix(orthProj);
 
        video::ITexture *img;
        
        img = g_pDriver->getTexture("spaceship.png");
        scene::IBillboardSceneNode *bill2 = g_pSMng->addBillboardSceneNode(node, core::dimension2df(60, 60));
        bill2->setPosition(core::vector3df(320, -400, 30));
        bill2->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
        bill2->getMaterial(0).setFlag(video::EMF_BACK_FACE_CULLING, false);
        bill2->getMaterial(0).setTexture(0, img);
        bill2->getMaterial(0).MaterialType = video::EMT_ONETEXTURE_BLEND;
        bill2->getMaterial(0).MaterialTypeParam = video::pack_texureBlendFunc(
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA, 
                irr::video::EMFN_MODULATE_1X, 
                irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
 
        img = g_pDriver->getTexture("twb.png");
        scene::IBillboardSceneNode *bill0 = g_pSMng->addBillboardSceneNode(node, core::dimension2df(640, 480));
        bill0->setPosition(core::vector3df(320, -240, 90));
        bill0->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
        bill0->getMaterial(0).setFlag(video::EMF_BACK_FACE_CULLING, false);
        bill0->getMaterial(0).setTexture(0, img);
        bill0->getMaterial(0).MaterialType = video::EMT_ONETEXTURE_BLEND;
        bill0->getMaterial(0).MaterialTypeParam = video::pack_texureBlendFunc(
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA, 
                irr::video::EMFN_MODULATE_1X, 
                irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
 
        img = g_pDriver->getTexture("wolken.png");
        scene::IBillboardSceneNode *bill1 = g_pSMng->addBillboardSceneNode(node, core::dimension2df(640, 480));
        bill1->setColor(0x7fffffff);
        bill1->setPosition(core::vector3df(320, -240, 60));
        bill1->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
        bill1->getMaterial(0).setFlag(video::EMF_BACK_FACE_CULLING, false);
        bill1->getMaterial(0).setTexture(0, img);
        bill1->getMaterial(0).MaterialType = video::EMT_ONETEXTURE_BLEND;
        bill1->getMaterial(0).MaterialTypeParam = video::pack_texureBlendFunc(
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA, 
                irr::video::EMFN_MODULATE_1X, 
                irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
 
    while (g_pDevice->run())
    {
                g_pDriver->beginScene(true, true, video::SColor(100, 32, 32, 64));
                g_pSMng->drawAll();
                g_pDriver->endScene();
    };
 
    g_pDevice->drop();
 
    return 0;
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Problem with transparncy textures & nodes

Post by hybrid »

Which version of Irrlicht? Does this happen with all drivers?
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Re: Problem with transparncy textures & nodes

Post by codebaker »

hmm, under OpenGL it work fine.

using Irrlicht 1.7.2
Post Reply