Advertisement

Shader swapping problem

Started by June 26, 2018 02:51 PM
2 comments, last by CrazyCdn 6 years, 7 months ago

Hello. I've got a problem with swapping shaders in one render. I am rendering HUD (2d user inteface over previously rendered 3d scene). The structure is not complex, tree-like: there are multiple movable windows containing texture background and optinally some textboxes, buttons, radiobuttons and statictexts (each widget type having own dedicated shader). The gui windows may overlap eachother (one used last should be on top of previous).

So the rendering works like this - interate over the list of windows (which are sorted from back to front) and render each. Rendering single window - use button shader, set uniforms, render all buttons, then use textbox shader, set uniforms, render all texboxes, use statictext shader, set uniforms render all etc...

As you can see i am rebinding the same shader multiple multiple times during one render. But i kind of have to? I cannot find another solution. If i render all buttons first and then for example textboxes, the textbox from window behind can overwrite previously draw button from front window. The depth test is obviously disabled for HUD rendering (what i draw last is on front). Actually maybe that's the solution to use depth buffer in some tricky way (bumped onto it while writin the post)?

Thanks for all suggestions

 

You can create several layers. Let's say 10 and give each level a depth [0,1]. And then each widget is assigned the appropriate level. So you don't need to sort objects. And you can activate the widget by changing the depth value. Use perspective matrix

Advertisement

You don't mention what renderer you're using, but can you not render each "window" to it's own render target then just place them in the correct order over the game scene?  You're not likely to have to many windows open, so it really shouldn't be all that bad honestly.

 

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement