Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Rendering static images over game

Started by RobM Jan 20, 2013 at 8:21 PM 3 replies 1.3k views
Original Post
RobM
RobM
Hi

When you want to show something like a health bar, a map, score or number of lives etc, I thought you might have to setup a specific view projection matrix, etc, but I just 'accidentally' did it by creating the graphic bounds using interpolated view projected vertices, e.g., the whole screen would be x and y -1,-1 to 1,1 respectively. In the vertex shader I just don't use a matrix to transform it and it works.

Is this how it's normally done anyway? Seems it would be quicker than doing it with matrices
L. Spiro
L. Spiro

It’s not “normal” (as in not a lot of people are doing this) but it is the best way to go in terms of efficiency for some things.

If it is for the HUD and, as you say, static objects, yes, this is best.

For moving objects, you would have to convert from pixel coordinates to normalized screen coordinates manually on the CPU, which will likely be slower to do than on the GPU, especially for batch rendering.

For your case of static objects, omitting the matrix transform (which just transforms things into -1 to 1 anyway) is the best way to go. Not only does it save on cycles but also on bandwidth, as there is less to send to the shaders.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
RobM
RobM
Great, thanks
RobM
RobM
Another quick question on this, is this how sprites are also usually done? Or would you generally use point sprites - I'm using DX9.

The reason I'm asking is because for my level editor (which will just use the c++ game engine from a c# front end) I'm going to need to overlay sprite-type icons on objects/zones, etc. this way seems pretty convenient to me

Although I guess this kind of changes the title to non-static graphics!

Thanks
L. Spiro
L. Spiro

Updating vertex buffers and calculating the normalized coordinates of vertices is slow. You have to decide based on your usage.

If it doesn’t move or moves rarely, use this method. If it moves a lot, use matrices.

HUD elements are just sprites, so there is no single answer. Use this to decide when you should use matrices and when you should not.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.