Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (761)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (845)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  UI-Overlay on 3D scene  (Read 1696 times)
0 Members and 1 Guest are viewing this topic.
Offline buddyBro
« Posted 2018-01-01 22:00:34 »

I'm wondering what would be the preferred way to draw a 2d ui overlay on top of a 3d game. Some ideas I've seen online or am considering are:
1) draw the 3d frame, set projection/view uniform matrices to Identity, draw UI
2) draw 3d frame, set some uniform boolean value that tell shaders to skip the matrix transformations, draw ui, reset the boolean
3) draw 3d frame, switch to another shaderProgram, draw UI, switch back to 3d shaderProgram.

I'm not sure how expensive switching shader programs (3), but https://www.opengl.org/discussion_boards/showthread.php/173818-Best-way-to-handle-multiple-shaders suggests it shouldn't be a problem. Likewise, not sure how expensive checking a uniform boolean value for every single vertex (2) would be?
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 283
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2018-01-02 00:11:55 »

The best thing you can do is try all 3 approaches (in a little test program) and see which approach you like the best.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline bmanmcfly
« Reply #2 - Posted 2018-01-02 02:50:26 »

I think the best bet is to just use 2 cameras, in your case a projection camera, and a ortho cam for the hud.

whatever effects are going on with the projection cam should not impact the overlay.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elect

JGO Knight


Medals: 59



« Reply #3 - Posted 2018-01-03 14:41:17 »

I'm wondering what would be the preferred way to draw a 2d ui overlay on top of a 3d game. Some ideas I've seen online or am considering are:
1) draw the 3d frame, set projection/view uniform matrices to Identity, draw UI
2) draw 3d frame, set some uniform boolean value that tell shaders to skip the matrix transformations, draw ui, reset the boolean
3) draw 3d frame, switch to another shaderProgram, draw UI, switch back to 3d shaderProgram.

I'm not sure how expensive switching shader programs (3), but https://www.opengl.org/discussion_boards/showthread.php/173818-Best-way-to-handle-multiple-shaders suggests it shouldn't be a problem. Likewise, not sure how expensive checking a uniform boolean value for every single vertex (2) would be?

I did some tests about that:

Per second, I hit 105k framebuffer, 700k Program, 3.1M Texture Bindings, 3.4M Vertex Formats, 4.6M UBO Bindings, 6.3M Vertex Bindings and 15.2M Uniform Updates.

So by a performances point of view, option 1 is the best.

But practically it doesn't matter unless very specific condition. I'd go with the 3. Code clearer and more readable
Offline Riven
Administrator

« JGO Overlord »


Medals: 1341
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2018-01-03 16:56:16 »

The likeliness that you can reuse the same shaders for 3D and 2D rendering is very low anyway.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline buddyBro
« Reply #5 - Posted 2018-01-03 18:28:57 »

Thank you all. For now, I'll go with swapping shader programs for simplicity. If this becomes the bottle neck or gains a significant impact on performance, I'll try out the other options. Though based of eject's reply, it seems this shouldn't ever really be the bottleneck.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1341
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2018-01-03 19:46:59 »

You can do hundreds of shader switches per frame before you get even to a millisecond of overhead.

Premature optimization is bad Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (348 views)
2018-06-10 19:43:48

EgonOlsen (342 views)
2018-06-10 19:43:44

EgonOlsen (290 views)
2018-06-10 19:43:20

DesertCoockie (514 views)
2018-05-13 18:23:11

nelsongames (779 views)
2018-04-24 18:15:36

nelsongames (765 views)
2018-04-24 18:14:32

ivj94 (1229 views)
2018-03-24 14:47:39

ivj94 (393 views)
2018-03-24 14:46:31

ivj94 (1056 views)
2018-03-24 14:43:53

Solater (410 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!