Decal System / Manager

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki

Decal System / Manager

Postby RdR » Wed Oct 12, 2011 10:51 am

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

Re: Decal System / Manager

Postby shadowslair » Wed Oct 12, 2011 11:04 am

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..."
User avatar
shadowslair
 
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Decal System / Manager

Postby RdR » Wed Oct 12, 2011 11:20 am

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

Re: Decal System / Manager

Postby Lonesome Ducky » Wed Oct 12, 2011 6:49 pm

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

Re: Decal System / Manager

Postby RdR » Wed Oct 12, 2011 8:41 pm

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

Re: Decal System / Manager

Postby tecan » Thu Oct 13, 2011 1:35 am

YAAAAaaaaaaa!! you rock!
Live long and phosphor!
-- https://github.com/tecan/Luna Status 85%
User avatar
tecan
 
Posts: 345
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada

Re: Decal System / Manager

Postby hybrid » Thu Oct 13, 2011 8:08 am

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.
hybrid
Admin
 
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Re: Decal System / Manager

Postby RdR » Thu Oct 13, 2011 11:05 am

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

Re: Decal System / Manager

Postby Virion » Thu Oct 13, 2011 6:04 pm

awesome stuff you got there!! time to splat blood everywhere!! :twisted: :lol:
User avatar
Virion
Competition winner
 
Posts: 2141
Joined: Mon Dec 18, 2006 5:04 am

Re: Decal System / Manager

Postby jorgerosa » Sun Oct 16, 2011 1:51 pm

Sounds big and cool! Great work! Thanks for share it! I´ll try it asap! :)
User avatar
jorgerosa
Competition winner
 
Posts: 104
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal

Re: Decal System / Manager

Postby tbw » Mon Oct 17, 2011 8:02 pm

Really awesome! Thanks for sharing!
btw I got some memory leaks. I fixed them by changing

cpp Code: Select all
DecalSceneNode::~DecalSceneNode()
{
        if (this->mesh)
                this->mesh->drop();
}


and by adding

cpp Code: Select all
meshBuffer->drop();

before
cpp Code: Select all
batchingMesh->finalize();
return batchingMesh;

in
cpp Code: Select all
irr::scene::IMesh* DecalManager::createMesh(irr::core::aabbox3df box, irr::core::matrix4 rotationMatrix)
tbw
 
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: Decal System / Manager

Postby RdR » Mon Oct 17, 2011 8:28 pm

tbw wrote:Really awesome! Thanks for sharing!
btw I got some memory leaks. I fixed them by changing

cpp Code: Select all
DecalSceneNode::~DecalSceneNode()
{
        if (this->mesh)
                this->mesh->drop();
}


and by adding

cpp Code: Select all
meshBuffer->drop();

before
cpp Code: Select all
batchingMesh->finalize();
return batchingMesh;

in
cpp 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
User avatar
RdR
Competition winner
 
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm

Re: Decal System / Manager

Postby RdR » Wed Oct 19, 2011 12:07 pm

Update:
- Fixed fade out tranparency
- Added some basic funtions
User avatar
RdR
Competition winner
 
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm

Re: Decal System / Manager

Postby Masterhawk » Fri Oct 28, 2011 3:48 pm

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
User avatar
Masterhawk
 
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY

Re: Decal System / Manager

Postby Virion » Fri Oct 28, 2011 5:26 pm

AWESOME!! :o
User avatar
Virion
Competition winner
 
Posts: 2141
Joined: Mon Dec 18, 2006 5:04 am

Next

Return to Project Announcements

Who is online

Users browsing this forum: No registered users and 1 guest