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.
Post Reply
HAWK0987654321
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Decals applied to non-static meshes

Post by HAWK0987654321 »

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/v ... =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/v ... hp?t=39440
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: Decals applied to non-static meshes

Post by ACE247 »

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.
HAWK0987654321
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Post by HAWK0987654321 »

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

Post by HAWK0987654321 »

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?

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();
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Decals applied to non-static meshes

Post by gerdb »

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++;
}
HAWK0987654321
Posts: 6
Joined: Tue Apr 17, 2012 10:29 pm

Re: Decals applied to non-static meshes

Post by HAWK0987654321 »

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.
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Decals applied to non-static meshes

Post by gerdb »

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

Re: Decals applied to non-static meshes

Post by hybrid »

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.
Post Reply