Decals applied to non-static meshes

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.

Decals applied to non-static meshes

Postby HAWK0987654321 » Mon May 07, 2012 8:57 pm

I have a question about decals and non-static geometry. I originally asked this question over in another thread, but because that wasn't really the place for the question, I started this thread. So, here's the carry-over from http://irrlicht.sourceforge.net/forum/viewtopic.php?f=9&t=45604
HAWK0987654321 wrote:Hello
Thanks for releasing this code, it's the best decal system I have seen for Irrlicht. :D

I am wondering if there is a way to use these decals with non static meshes, as with the F.E.A.R. games where blood decals are created at bullet hits.

Example image from http://www.tweakguides.com/FEAR_8.html
Image

How would I do this?

I'm relatively new to Irrlicht.

serengeor wrote:Maybe those aren't decals, but rather another texture layer? (Just a guess)


That was my original idea for decals, but getting the decals in the right spot and the right size may be a bit tricky...also, normal maps would be a challenge as Irrlicht only has two texture layers.
They had discussed something similar in the forums here: http://irrlicht.sourceforge.net/forum/viewtopic.php?t=39440
HAWK0987654321
 
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Postby ACE247 » Mon May 07, 2012 10:16 pm

Irrlicht has more than two texture layers....
Also from what I guess its likely an adaptation of a terrain texture 'splatting' type pixel shader whereby the decals are painted on the uv from a sprite sheet.
H8L6L5M4G3H5M7N8S7N9O1R8J1P5M7N9O4P2Q5R6T7U4M3N8X6S5T8W (If you want the secret, why not 'TRY' decrypting it? )
This Door's lock doesn't need a key, the Lock is the key to open the Lock and you don't know how to turn the key...
Link: My Blog :)
User avatar
ACE247
 
Posts: 695
Joined: Tue Mar 16, 2010 12:31 am
Location: Namibia

Re: Decals applied to non-static meshes

Postby HAWK0987654321 » Tue May 08, 2012 2:08 am

Thanks for replying, guys.
Ok, I see. At first I thought it only had 2 because of intellisenes in MSVC(and I hadn't noticed anything in the API docs saying otherwise).

I don't know that much about shaders yet, but I think I'm starting to understand them a bit.
I think I may be able to figure out the UV coords and how to paint. I'll post back with either finished code or questions sometime later.

Thanks
HAWK0987654321
 
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Postby HAWK0987654321 » Tue May 08, 2012 6:57 pm

Ok, what would I use to retrieve UV coords from selected triangles?

And, I have tried editing an image, but without success.
In this test I'm just trying to set half the texture colors.
What am I doing wrong?
cpp Code: Select all
//My test texture is a 24 bit bitmap
 
line3d<f32> ray = coll->getRayFromScreenCoordinates(vector2di(TEvent.MouseInput.X, TEvent.MouseInput.Y));
vector3df point;
triangle3df triangle;
ISceneNode *colNode=coll->getSceneNodeAndCollisionPointFromRay(ray, point, triangle);
 
u32 *a=(u32*)colNode->getMaterial(0).getTexture(0)->lock();
 
int p=colNode->getMaterial(0).getTexture(0)->getSize().Height*colNode->getMaterial(0).getTexture(0)->getSize().Width;
 
for(int b=0;b<=p/2;b++)
{
        a[p]=0;
}
 
colNode->getMaterial(0).getTexture(0)->unlock();
colNode->getMaterial(0).getTexture(0)->regenerateMipMapLevels();
HAWK0987654321
 
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Postby gerdb » Tue May 08, 2012 7:48 pm

u32 *a=(u32*)colNode->getMaterial(0).getTexture(0)->lock();


theres no guarantee that the texture is 32bit without checking it;

int p=colNode->getMaterial(0).getTexture(0)->getSize().Height*colNode->getMaterial(0).getTexture(0)->getSize().Width;

for(int b=0;b<=p/2;b++)
{
a[p]=0;
}


theres no guarantee that the texture has a pitch of zero.

also maybe you want

a[b]=0;

also i would do

u32* ptr = a;

for(int b=0;b<=p/2;b++)
{
*ptr=0; // set color transparent black
ptr++;
}
gerdb
 
Posts: 167
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Decals applied to non-static meshes

Postby HAWK0987654321 » Tue May 08, 2012 9:00 pm

Ah, there we go. Thanks :D
I missed that typo...and that would be why I wasn't noticing a change in texture. Changing one pixel 65,536 times to the same value...just doesn't do much. ;)
What is texture pitch exactly? I checked the API docs and it says the pitch is the amount of bytes in a row of the texture. I called getPitch() and it returned a value of 1024.
HAWK0987654321
 
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Postby gerdb » Tue May 08, 2012 10:05 pm

some graphics-cards do not support EVDF_NON_SQUARE_TEXTURES and EVDF_NON_POWER_OF_2_TEXTURES (or similar)

i.e. a texture 500x500 only fits in a VRAM block of 512x512 so per row are 12 pixel zeroed out (should always be zero)

so to traverse lines (rows) of the texture you have to increment the pointer by the pitch before going to the next row-start

if you do not you jump the pitch bytes you'll have odd results (most likely some stair effect, because you always forget 12 pixel * u32 per row).
gerdb
 
Posts: 167
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Decals applied to non-static meshes

Postby hybrid » Wed May 09, 2012 8:40 am

Well, actually textures usually don't have a pitch, and those gpus that don't support NPOT will scale the texture to 512x512. Because otherwise a texture coord of 1 would have to be scaled on each access, or would lead to wrong results. But images can have a pitch, as well as framebuffers (only useful for software implementations, though). It just means that you have additional pixels, which you have to skip and which do not count as part of the image. PItch can also help defining a sub-image on a larger image.
hybrid
Admin
 
Posts: 13942
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest