Hello Guest

Author Topic: Creating a 3d gui with StaticBatcher?  (Read 6548 times)

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Creating a 3d gui with StaticBatcher?
« on: September 18, 2013, 07:17:22 pm »
My goal is to create a 3d pause menu that floats above the game screen with a slight 3d rotation. Conceptually this isn't a problem- I just build a gui out of sprites and set the rotation of the gameobject to pop it out. All of this is filmed by a perspective camera with sort mode set to orthographic. The camera is set to appear on top in the camera stack.

However, the issue is that if I slightly rotate the menu, the objects near the back (in regards to z axis) will start to occlude objects in front. Here is an example:
http://i.imgur.com/H2d4R8B.png

In the picture you can see that the words on top are much darker. They should be the same as the white words, but the transparent 'backing' counts as closer to the camera than them at the angle, and so it appears on top.

Is it possible to make use of the static batcher (http://www.unikronsoftware.com/2dtoolkit/docs/2.20/advanced/scripting_static_sprite_batcher.html) so that the elements are all drawn together as one sprite, and always appear on top? My gui will consist of a mixture 2d sprites and 2d text meshes. Also keep in mind that the gui will change as the user cycles through the different choices.
« Last Edit: September 18, 2013, 07:19:15 pm by Afro-Ninja »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Creating a 3d gui with StaticBatcher?
« Reply #1 on: September 18, 2013, 11:06:59 pm »
In tk2d 2.2, you have an independent Order in Layer property which you can use to reorder sprites in a particular way without using Z. In effect, it changes the z order for sorting, but leaves sprites where they are. Your use case is pretty straightforward, you can "fix"  this by changing this property.

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: Creating a 3d gui with StaticBatcher?
« Reply #2 on: September 18, 2013, 11:50:53 pm »
Interesting, I didn't realize that 2.2 was out now. Will have to check this out. I assume this works properly even with a perspective camera as noted?

Also I'm curious, if you don't mind, what do you use to achieve this sorting effect? I know you can modify material.renderQueue in code, but this only affects the order of rendering, not the actual depth used to determine occlusion.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Creating a 3d gui with StaticBatcher?
« Reply #3 on: September 19, 2013, 12:09:17 am »
It modifies the meshes bounding box center. This fools the renderer into thinking its closer/further away than it physically is.

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: Creating a 3d gui with StaticBatcher?
« Reply #4 on: September 19, 2013, 08:28:03 am »
After some testing I got it to work, but my solution was a bit arbitrary.
Based on what you said, is this changing the sprite's position along the z axis in the direction of its normal? With the rotation I was working with I found that I had to set my top elements to a sorting order of 50, while changing my bottom element to a sorting order of -300. I also found that once I reached a sorting order of ~700 the object disappeared entirely (assuming that this put the object's virtual axis out of the range of the camera entirely)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Creating a 3d gui with StaticBatcher?
« Reply #5 on: September 19, 2013, 10:35:52 am »
Yup, thats exactly what is happening. Look at where it does the manipulation - you can pretty much persuade it to do anything you like there to get the sorting you need - eg. go negative to push things behind rather than pushing towards the camera to enforce sort order. Alternatively, if its just the background and foreground you need sorting correctly, then perhaps you could just use a material sort order.