Texture clipping (hiding part of a texture) on a billboard.

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
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Texture clipping (hiding part of a texture) on a billboard.

Post by MartinVee »

I'm using a texture transform matrix to load and display different sprite from a texture atlas (see my previous post). It works perfectly, as long as each texture has the same size as the billboard on which its displayed. Unfortunately, we're using Texture Packer as a tool to generate out texture atlas, and it's automatically trimming away the transparent outter pixels. So, it's possible, for example, for a 64x64 animation to have some (or all!) frames that are smaller than 64x64.

I can create a texture matrix that maps perfectly to any sprite of my spritesheet (or texture atlas, if you prefer), but the problem I'm having is that since Texture Packer packs all the sprites together (as close as possible) to optimize the texture atlas size, when I display a smaller frame on a billboard, I can see part of another frame (or an entierly other animation). I can't seem to find a way to correct this problem.

How can I clip the texture (hide a part of) on the billboard? Should I be also resizing the billboard to prevent this problem? What's the best way to correct this?

I know "draw2DImage" can do it, but I can't figure out how to do it with a billboard.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Texture clipping (hiding part of a texture) on a billboa

Post by CuteAlien »

Hm, you need to work with uv's on the billboard for that I guess. Unfortunately it doesn't seem to offer direct access to it's vertices. I don't see a away around that right now, so my solution would be to copy the code of that billboard node into a new class of your own. And then you can modify the uv-coordinates directly.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Texture clipping (hiding part of a texture) on a billboa

Post by Mel »

There are many ways. I myself would create all the billboards by hand, unless you're wishing to render thousands over thousands of billboards, doing them by hand is perfectly affordable, in your case the problem is that the size of the sprites isn't costant anymore, so you have to resize your billboards until they meet the proper size, i.e. if your 64x64 sprite uses a 1x1 unit long billboard, a 96x64 sprite should use a 1.5x1 units long billboard, it is taking your problem the oposite direction, you want to clip a part of your texture, i tell you to fit the part you need into a billboard of the proper size. Make your texture matrix so you map the texture portion you need into the normalized texture space and resize your billboard accordingly
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Texture clipping (hiding part of a texture) on a billboa

Post by MartinVee »

I came to the same conclusion. CuteAlien, I tried to fiddle with the UV-coordinates (in fact, when I say Billboard, I really mean my own IBIllboard-derived class), but I could come to a solution where the texture wasn't stretched, and part of another sprite wasn't showing.

Do you think it's still affordable if I resize a Billboard each time I'm showing a frame? Does it incur too much overhead?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Texture clipping (hiding part of a texture) on a billboa

Post by CuteAlien »

Resizing should be pretty cheap. As vertices are send to graphic card each frame anyway (doesn't matter for 4 vertices).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Texture clipping (hiding part of a texture) on a billboa

Post by MartinVee »

Excellent, thank you very much!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Texture clipping (hiding part of a texture) on a billboa

Post by Mel »

I would take a look at the particle systems code to learn how to render many quads in 3D at a time, that would allow you to render very fast many sprites that shared the same sprite atlas.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Texture clipping (hiding part of a texture) on a billboa

Post by MartinVee »

Good call, Mel! Will do! Thank you!
Post Reply