Page 1 of 3
Decal System / Manager
Posted: Wed Oct 12, 2011 10:51 am
by RdR
Because there was no decent decal system / manager around here I wrote my own. You can easily add new decals and decalable meshes (or how do you call it)
Features
- Multiple 'decalable' meshes
- Decal size, orientation & rotation
- Decal Max distance
- Decal Lifetime
- Decal Fade out + fade out time
How to use
Code: Select all
// Create decal manager
DecalManager* decalManager = new DecalManager(smgr);
// Set terrain and add some meshes where decals can be placed
decalManager->setTerrain(terrain);
decalManager->addMesh(wallNode);
decalManager->addMesh(rockNode);
// Create a decal
irr::core::vector3df position = irr::core::vector3df(123, 10, 123); // Position to place the decal
irr::core::vector3df dimension = irr::core::vector3df(2, 2, 2); // Dimension of decal
irr::core::vector3df normal = irr::core::vector3df(0, 1, 0); // Orientation of the decal
irr::f32 textureRotation = 45; // Rotation in degrees
irr::scene::ISceneNode* parent = 0; // Parent
irr::f32 lifeTime = 0; // Time to life
irr::f32 distance = 250; // Max viewing distance
decalManager->addDecal("mydecal.png", position, dimension, normal, textureRotation, parent, lifeTime, distance);
Screenshot
Download
Download
IrrExt mirror
TODO
- Triangle clipping
Re: Decal System / Manager
Posted: Wed Oct 12, 2011 11:04 am
by shadowslair
Looks like your build is libgcc.dll dependent. Despite that the code looks very clean and well organised. Well, maybe except for the java brackets. But very nice overall. Will take a look at the actual methods you use when I find some time. Thanks for sharing.
PS: Triangle clipping is a bit trickier to get right.
Re: Decal System / Manager
Posted: Wed Oct 12, 2011 11:20 am
by RdR
shadowslair wrote:Looks like your build is libgcc.dll dependent..
Ah thanks for noticing, added the libs so should be working now.
shadowslair wrote:
PS: Triangle clipping is a bit trickier to get right
Hehe yep it is, that's why its not done yet
shadowslair wrote:
Despite that the code looks very clean and well organised. Well, maybe except for the java brackets.
Haha that are the code conventions of our project

Re: Decal System / Manager
Posted: Wed Oct 12, 2011 6:49 pm
by Lonesome Ducky
How do you get around z fighting? Do you move the decal triangles out or do you do some z-buffer fiddling?
Triangle clipping really shouldn't be that hard. If a triangle is not fully inside, find the points where the lines forming the the triangle intersect the box, and use them as the vertices for the new triangles.
Re: Decal System / Manager
Posted: Wed Oct 12, 2011 8:41 pm
by RdR
Lonesome Ducky wrote:How do you get around z fighting? Do you move the decal triangles out or do you do some z-buffer fiddling?
I move the triangles out by using the original triangle normal.
Is there a better way to do this?
Lonesome Ducky wrote:
Triangle clipping really shouldn't be that hard. If a triangle is not fully inside, find the points where the lines forming the the triangle intersect the box, and use them as the vertices for the new triangles.
Yeah but still have to keep in mind which intersection belongs to the previous triangle.
If 2 of the 3 vertexes are outside of the box, you get 3 triangles in return.
Any comments for improvements are welcome

Re: Decal System / Manager
Posted: Thu Oct 13, 2011 1:35 am
by netpipe
YAAAAaaaaaaa!! you rock!
Re: Decal System / Manager
Posted: Thu Oct 13, 2011 8:08 am
by hybrid
RdR wrote:Lonesome Ducky wrote:How do you get around z fighting? Do you move the decal triangles out or do you do some z-buffer fiddling?
I move the triangles out by using the original triangle normal.
Is there a better way to do this?
I'm not sure if Irrlicht 1.7 supports it, but at least for 1.8 we have the depth bias setting in materials. There you can define some kind of an add-on value for rendered meshes. The mesh is automatically displaced by that value on the GPU.
Re: Decal System / Manager
Posted: Thu Oct 13, 2011 11:05 am
by RdR
tecan wrote:YAAAAaaaaaaa!! you rock!
Glad you appreciate it
hybrid wrote:[I'm not sure if Irrlicht 1.7 supports it, but at least for 1.8 we have the depth bias setting in materials. There you can define some kind of an add-on value for rendered meshes. The mesh is automatically displaced by that value on the GPU.
Ah nice, we moved to Irrlicht 1.8 (trunk) earlier this week so ill take a look at that.
Re: Decal System / Manager
Posted: Thu Oct 13, 2011 6:04 pm
by Virion
awesome stuff you got there!! time to splat blood everywhere!!

Re: Decal System / Manager
Posted: Sun Oct 16, 2011 1:51 pm
by jorgerosa
Sounds big and cool! Great work! Thanks for share it! I´ll try it asap!

Re: Decal System / Manager
Posted: Mon Oct 17, 2011 8:02 pm
by tbw
Really awesome! Thanks for sharing!
btw I got some memory leaks. I fixed them by changing
Code: Select all
DecalSceneNode::~DecalSceneNode()
{
if (this->mesh)
this->mesh->drop();
}
and by adding
before
Code: Select all
batchingMesh->finalize();
return batchingMesh;
in
Code: Select all
irr::scene::IMesh* DecalManager::createMesh(irr::core::aabbox3df box, irr::core::matrix4 rotationMatrix)
Re: Decal System / Manager
Posted: Mon Oct 17, 2011 8:28 pm
by RdR
tbw wrote:Really awesome! Thanks for sharing!
btw I got some memory leaks. I fixed them by changing
Code: Select all
DecalSceneNode::~DecalSceneNode()
{
if (this->mesh)
this->mesh->drop();
}
and by adding
before
Code: Select all
batchingMesh->finalize();
return batchingMesh;
in
Code: Select all
irr::scene::IMesh* DecalManager::createMesh(irr::core::aabbox3df box, irr::core::matrix4 rotationMatrix)
Thanks for noticing!
I added it to the source
Virion wrote:awesome stuff you got there!! time to splat blood everywhere!!

Hehe

Re: Decal System / Manager
Posted: Wed Oct 19, 2011 12:07 pm
by RdR
Update:
- Fixed fade out tranparency
- Added some basic funtions
Re: Decal System / Manager
Posted: Fri Oct 28, 2011 3:48 pm
by Masterhawk
Nice snippet

This would have been the next task for me to create a decal system on my own for my editor. Now you saved me a lot of time. Thx

Re: Decal System / Manager
Posted: Fri Oct 28, 2011 5:26 pm
by Virion
AWESOME!!
