Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / [Debate]: Painting a decal on the texture

Author
Message
zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 9th Feb 2012 13:31 Edited at: 9th Feb 2012 13:33
Hi guys.
I've reached a stage in my project in which I can afford to spend some time working on effects and a little eye candy. Right now I want to add decals (bullet holes) at collision points between the bullet and the wall. I'm still at work, so I can't code it, but I came out with an approach on how to do it. I still have 6 hours left till I go home, so I wanted to ask you guys what approach you use when it comes to using decals. What I plan on doing is this:

Retrieve our object’s width and height.


Get texture width, height.



Get our Obj/Texture ratio:



Now we check out where the bullet collided with the object


We know at what position the bullet collided with the wall object. Now let’s check where on the object it hit. We can do this by checking the wall’s position, size, with the bullet’s position and size.


We then substract the Objects Position from the Decal position to know the offset of the decal on that object.
Now everything is just a matter of converting those position to the texture coordinates.



Now we offset the decal image to the right position on the wall.


What do you guys think? Do you see a flaw in my logic? Any idea if there is a better approach to it?

P.S. when I prototyped the game, I would create a plane object, with the bullet_hole texture at the collision point. But I had two problems: The rotation of the plane, which was set to the bullet's rotation on impact with the wall, and that if the bullet collided with a corner, half the decal would just "float", being offseted outside the wall.

Looking forward to your suggestions.
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 9th Feb 2012 15:49 Edited at: 9th Feb 2012 15:53
Well, as you already discovered for yourself, if you do it like this all these calculations would just lead to the same effect you get with doing it the old-school way (simply placing decal planes at the collision point, pointing away from the underlying wall)!

If you want to let the decals clip precisely at the wall edges you would have to do some more complicated stuff.
Some ideas are...
1) making a duplicate of the wall polygon with the decal texture at the right spot,
2) add a texture layer to all walls and find a way how to precisely draw your decals on this,
3) using shaders and doing something like depth testing or texture projection.

I would probably go with approach 2) because once you have this working you could draw anything on the walls permanently. The hard part is to figure out how to store all these extra textures. I think this would work almost like light mapper tools create light maps (each polygon has a reserved space on a large master texture). The result would be having something like a "decal map" that works just like a light map (could even be saved to a file).

But either way, doing correct decals is not as easy as it seams...
Good luck!

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 9th Feb 2012 16:02
@_Pauli_ Well, option number 2) is what I presented above, by drawing the decal texture on the wall texture (not using a 3D plain). This way, even if the texture reaches outside the wall, it won't matter, since I will only retrieve the same width and height of the normal texture, excluding the part that is outside.

My only concern with this approach is that it could be slow, especially when it comes to having multiple bullets.
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 9th Feb 2012 18:42 Edited at: 9th Feb 2012 18:42
Ok sorry, then I slightly misunderstood your post.

But you're right, I could be rather slow.
Have to think about some optimizations then...

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 9th Feb 2012 19:07
Well, one thing I could do is just add the bullet as another layer over the normal texture, and keep a texture count. Once it reaches more then 10+ textures applied, I delete the first one. This way, I'll only have a maximum of 10 textures/decals in memory!

I got home, gonna start implementing it right now. I'll keep you all updated!

Login to post a reply

Server time is: 2024-04-26 19:21:59
Your offset time is: 2024-04-26 19:21:59