Static sprites

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Static sprites

Post by Rado1 »

Is there some simple possibility how to render sprites (or maybe also other components) that are static on the screen and do not react to 3D rotations of camera? Currently, I either use transformation of all these "static" bitmaps to fonts or create models having the same position as camera but opposite rotation and rendering all the "static" stuff (indicators, controllers, ...). Both techniques work, but require some overhead, especially if there are many such objects of different sizes on screen. Cannot ZGE provide some simpler mechanism?

My idea is to have, e.g., a variant (or a "2D" flag of) of the RenderTransformGroup/RenderTransform which would work in "camera's space", similarly to RenderText.
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Rado1,
Rado1 wrote:Is there some simple possibility how to render sprites that are static on the screen and do not react to 3D rotations of camera?
You probably mean 3D transformations, only countering the 3D rotations ( but not translation and scale ) will give you billboard sprites. Like the trees in Mario 64.

Image

Anyway, countering Camera transformations and the 2D mode of RenderText aren't the same thing. One will give you a orthographic projection, the other won't alter the projection of the active camera.

Rendering a GUI on top of a 3D game is usually done by overwriting the Projection and ModelView matrices. The only way to do this without extensions is by using two RenderPasses .. which is a bit inconvenient*, but you can always simply call glLoadMatrixf. Attached is a simple example.

*A ApplyCamera component that can be used in OnRender would be the best / easiest solution in my opinion.

K
Attachments
Layer2D.zgeproj
(24.55 KiB) Downloaded 646 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Kjell wrote:You probably mean 3D transformations, only countering the 3D rotations ( but not translation and scale ) will give you billboard sprites. Like the trees in Mario 64.
My explanation was not probably clear, I meant rendering of GUI components like gun sights, various controls (e.g., buttons), radarmaps, etc. for games, not "classical" billboard sprites put in scenes. See the attached screenshot.
Kjell wrote:Rendering a GUI on top of a 3D game is usually done by overwriting the Projection and ModelView matrices. The only way to do this without extensions is by using two RenderPasses .. which is a bit inconvenient*, but you can always simply call glLoadMatrixf.
I would like to avoid multiple render passes. Could you please give me an example of usage glLoadMatrixf for rendering "static sprites"? (I do not understand all this OpenGL transformations, yet.)
Kjell wrote:*A ApplyCamera component that can be used in OnRender would be the best / easiest solution in my opinion.
Sounds interesting. Can you please describe how to use such a component?
Attachments
Example of static GUI components
Example of static GUI components
scr.png (66.69 KiB) Viewed 15806 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Kjell - thanks for nice example. I see I must have a look at OpenGL transformations. This glMatrixMode(GL_PROJECTION) is the thing which does the trick I need. Thank you again.
User avatar
Ats
Posts: 614
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Hi, thanks for your example Kjell, very usefull for UI. Then I tried to play with it to obtain a billboard sprite.
I followed some tutorials here http://www.lighthouse3d.com/opengl/bill ... p?billSphe , without success...
I'm discovering 3D transformations and matrix so can you give me a hint ?
Thanks !
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,

What ( and how many ) will you be using it for? The easiest way is to use the negative rotation of the camera .. but this will kill performance in large quantities. Attached is a example regardless.

K
Attachments
Billboards.zgeproj
(2.21 KiB) Downloaded 648 times
Last edited by Kjell on Wed Oct 31, 2012 5:56 pm, edited 1 time in total.
User avatar
Ats
Posts: 614
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Thanks !!! I was so far away from what you did in your example...

I'm trying to create a planet hologram like that one:
Image
(Screenshot taken from Anastasyia)

I already managed to create a good one using a simple texture and a transparent grid, but I was testing to create one using fake voxels: a lot of little billboards. In fact, 128x64 = 8192 billboards... That's a lot, so maybe I'll stick to my simple texture...

Anyway, I'll surely use billboards for the next part of my tests so once again, thanks for your good snippets ;)
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,
Ats wrote:I'm trying to create a planet hologram
You really don't want to use the method I posted for something like that.

The easiest approach would be to render points instead of sprites, but points have a constant size ( they don't get bigger closer to the camera ) which is probably not what you want. The best technique would be to use geometry shaders, but you can get away with regular shaders if you pull some tricks ..

http://www.youtube.com/watch?v=Keu-p9-Wnsc

Not sure what hardware you're targeting though :)

K
User avatar
Ats
Posts: 614
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Whoa, that's exactly what I'm trying to do :shock:
As for the hardware, it's my PC because I'm still learning and trying things. I'm more efficient in programming gameplay than in shaders...
User avatar
Ats
Posts: 614
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Hi Kjell, I'm still trying to do the planet hologram from time to time...

Are you rendering the sphere using some efficient shader code, or do you place the points by hand on the sphere surface coordinates, and then making them facing the camera and scaling them with the distance ?

One more question, is your exemple working on a high-end GSM / android ?

Thanks!
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,
Ats wrote:Are you rendering the sphere using some efficient shader code?
The method shown in the video uses a static mesh ( so it only has to be uploaded to the GPU once ) containing the vertices for all sprites, but their coordinates are calculated by a vertex shader.
Ats wrote:Is your exemple working on a high-end GSM / android?
Yes, although not using ZGameEditor at the moment .. since ES 2.0 isn't supported yet. But even for ES 1.1 there are better techniques than using a model for each individual sprite.

K
Post Reply