Decal System / Manager

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Decal System / Manager

Post 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
Image
Image

Download
Download
IrrExt mirror

TODO
- Triangle clipping
Last edited by RdR on Sun Apr 01, 2012 3:37 pm, edited 5 times in total.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Decal System / Manager

Post 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. :wink:

PS: Triangle clipping is a bit trickier to get right.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Decal System / Manager

Post 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 :oops:
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 :wink:
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: Decal System / Manager

Post 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.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Decal System / Manager

Post 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 :D
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Decal System / Manager

Post by netpipe »

YAAAAaaaaaaa!! you rock!
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Decal System / Manager

Post 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.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Decal System / Manager

Post by RdR »

tecan wrote:YAAAAaaaaaaa!! you rock!
Glad you appreciate it :D

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.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Re: Decal System / Manager

Post by Virion »

awesome stuff you got there!! time to splat blood everywhere!! :twisted: :lol:
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Re: Decal System / Manager

Post by jorgerosa »

Sounds big and cool! Great work! Thanks for share it! I´ll try it asap! :)
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: Decal System / Manager

Post 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

Code: Select all

meshBuffer->drop();

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) 
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Decal System / Manager

Post 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

Code: Select all

meshBuffer->drop();

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!! :twisted: :lol:
Hehe
Image
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Decal System / Manager

Post by RdR »

Update:
- Fixed fade out tranparency
- Added some basic funtions
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Re: Decal System / Manager

Post 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 ;)
Image
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Re: Decal System / Manager

Post by Virion »

AWESOME!! :o
Post Reply