Author Topic: Runtime baking widgets into textures  (Read 5704 times)

alexv

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 1
  • Posts: 22
    • View Profile
Runtime baking widgets into textures
« on: October 18, 2014, 01:28:40 AM »
Hi Michael,

I was wondering if its possible to bake a widget into a texture, for using it as UITexture instead.

why? well, I target mobile platforms, so I'm using an allways constrained UIRoot, where I draw some card widget which uses 5 draw calls each (1 drawcall for painting the bg with an atlas, and 4 more drawcalls for the UILabels which renders 4 different unity dynamic fonts faces with keepcrisp=allways and hinted-smooth  rendering mode).

I use up to a maximum of 10 of these widget cards simultaneously, each with their own text contents, and each card have to be stacked over the other at different depths, so I add a panel to each and get a total of 50 draw calls just for drawing 10 of these stacked cards at once.

the benefits: I get razor sharp font edges at all resolutions and pixel densities, but performance is not the best (hinted smooth, allways keep crips, 50 drawcalls...)

I don't like the idea of using any method that blurs my fonts, you know the font I use is quite small, but still readable because it's so razo-sharp with the hinted mode and keep crisp options), so I can't consider a blurred font solution.

so, I was hoping to reduce 50 drawcalls to 10 calls if I could "cache" or "bake" each widget into a big texture and display 10 of those as UITexture, after all, once the widget is created, it never changes/resizes nor scales again, I just animate the transform, so UITexture could fit really well!

do you think it is possible? or maybe you know any trick or workaround to reduce the draw calls while keeping the fonts crisp on constrained uiroot ?

thanks for the help!!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Runtime baking widgets into textures
« Reply #1 on: October 18, 2014, 09:00:45 AM »
There is no way to do this using the GPU because of how alpha is handled. Basically if you write to a pixel, you also have to write the alpha, and it doesn't append the alpha -- it replaces what's there. So each new widget with transparency will overwrite the alpha written by the widget that came before it. There *may* be a way around it, but I am not aware of one.

The only other alternative is to do the mixing yourself on the CPU, and that's very slow.

alexv

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: Runtime baking widgets into textures
« Reply #2 on: October 18, 2014, 10:35:05 AM »
thanks for the reply! I didn't know that about transparency, but, what if the widgets are fully opaque? I'm not using transparency on any of their elements, or am I missing the big picture ? would you elaborate if it is?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Runtime baking widgets into textures
« Reply #3 on: October 19, 2014, 11:10:01 AM »
I'm sure you do use transparency, unless every single one of your sprites is a perfect square without any alpha usage.

alexv

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: Runtime baking widgets into textures
« Reply #4 on: October 19, 2014, 11:13:46 AM »
ah got it!

Maybe I could render-to-texture each widget into a single texture at runtime and assign it to a UITexture.

thanks for the responses!