Sprites renderer again...

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
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Sprites renderer again...

Post by Randajad »

Hello for all! I'm writing client for online game and have a problem.
Image

As it is on screenshot ONE frame consists of many images. If i at first render images to texture and then do billboard->setTexture(), then it have very, very poor perfomance. Because it's also need to rescale/rotate "basic" images. What can i do? I think there is way with matrixes when i set it, then draw basic image and so on.
Last edited by Randajad on Mon Sep 10, 2012 12:44 pm, edited 1 time in total.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

Oh, i forgot main question. Is it possible to disable z-buffer when one is rendering to draw one pixcure on another?
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Sprites renderer again...

Post by CuteAlien »

Maybe use a url for your image tag - seems the forum doesn't like the redirection on that server (or use imgur that usually works well).

You can affect z-buffer by setting a material. Values to affect it are SMaterial::ZBuffer and SMaterial:: ZWriteEnable. See http://irrlicht.sourceforge.net/docu/cl ... erial.html

Not sure if I got the other part of your question. The part of the texture used is affected by uv-coordinates for each vertex. Rotation can be done by setting a texture-matrix for the corresponding TextureLayer in your material: http://irrlicht.sourceforge.net/docu/cl ... layer.html

Hope that helps, otherwise just ask again :-)
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
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

Sorry, too many mistakes in my post above. I don't know how i wrote it.
I'm reupload image. :)

So. I had animation which consists of many frames. Each frame consists of "basic" images. Basic image have position, scale and rotate. I need to show frames. How i can render it better?
I try to make final frame by drawing basic images on iimage and creting itexture, then set this texture to billboard. But it's have poor perfomance. I think there is way to draw right basics images on screen and when node is rendering, disable zbuffer to draw one picture on another. Is there?
Last edited by Randajad on Mon Sep 10, 2012 1:44 pm, edited 1 time in total.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Sprites renderer again...

Post by CuteAlien »

Hm, first question - do you really need a billboard? Billboard is for putting an image in 3D ... this looks on first view like something you could do with 2d.

And if that would be sufficient you could use IVideoDriver 2d drawing functions. For rotation - please search around the forum for image rotation, I think there had been some solutions. I'm not certain on how I would do that myself, I guess I would try setting the world-matrix to some rotation matrix before using 2d drawing functions, but don't know if this works as I didn't try. Disabling zbuffer can be done as mentioned above by setting an SMaterial with ZBuffer and ZWriteEnable to whatever you need. And then use IVideoDriver::setMaterial before calling your draw functions.
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
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

Yes, i have 3d world with 2d sprites.
I think ZWriteEnable used only to render transparent objects, isn't it? I only need to avoid z-fightering.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Sprites renderer again...

Post by Mel »

maybe a draw3DSpriteBatch could be a nice addition to the video driver? or anything that did something similar to drawing a large amount of billboards, each of them with a custom texture fragment that could change on a per call basis.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Sprites renderer again...

Post by CuteAlien »

@ Randajad, no those flags are not only for transparency, transparency just also needs them. But you probably need to set ZBuffer and not ZWriteEnable in your case. And I suspect you have to set it to irr::video::ECFN_ALWAYS which sounds like write always to me.

@Mel: Yeah, I had hoped spritebanks would be extended to have more sprite functions one day. But not sure right now if Bitplane will ever get back to working on those... he's been a little quite lately :-(
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
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Sprites renderer again...

Post by smso »

You may also try combining the sprites into a large image and changing the texture matrix of the billboard instead.

Code: Select all

    while (device->run())
    if (device->isWindowActive())
    {
        core::matrix4 mat;
        //buildTextureTransform(f32 rotateRad, const core::vector2df &rotatecenter, const core::vector2df &translate, const core::vector2df &scale)
        mat.buildTextureTransform(...);
        billboard->getMaterial(0).setTextureMatrix(0, mat);
        
        driver->beginScene(true, true, 0);
        smgr->drawAll();
        driver->endScene();
    }
    else { device->yield(); }
Regards,
smso
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

Thanks very mush for this help, guys! It works, but i have another problem.

I'm only disable ZWriteEnable on the material and it's have effect that i expected.
But then i have trouble with object overlap.

Two screens:
Image
Image
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

Bump!
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Sprites renderer again...

Post by CuteAlien »

I'm not certain from this shots what the problem is. Should there be a full person above the shoes which is overlapped by the castle? Is the castle 3d or another sprite? If it is another sprite - what about the gras - is that the same sprite as the castle?

You must be a little more talkative - we don't see/know what's going on except for what you describe :-)
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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Sprites renderer again...

Post by hendu »

That's what's supposed to happen if you disable the Z buffer...

By doing that you're saying "I will handle the draw order myself".
Randajad
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Sprites renderer again...

Post by Randajad »

All world is 3d. Characters are sprites.
So, i think, then there is no way to resolve zbuffer trouble. Okay, i will try to find another way to do what i need.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Sprites renderer again...

Post by Mel »

Just don't disable the ZWrite, and use the Alpha Channel Ref. for Sprites, it can be the best solution.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply