Author Topic: Some issues about transparency sorting.  (Read 1418 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Some issues about transparency sorting.
« on: March 25, 2013, 11:12:47 am »
I 'am making a car-racing game. I made a road with some buildings, these buildings are just planes with alpha textures(png), and all the buildings are combinded to one mesh. The problem is: i could see the far buildings through the near buildings.

。。。。。。。。。。。。。。。。。。。
。                                                   。
。(far building)        (near building)。   <----- look at
。                                                   。
。。。。。。。。。。。。。。。。。。。
               


« Last Edit: March 25, 2013, 12:44:35 pm by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Some issues about transparency sorting.
« Reply #1 on: March 25, 2013, 07:06:09 pm »
There can't be any sorting if everything is one large object. You have split the parts you want to have sorted into different objects.
« Last Edit: March 26, 2013, 07:14:54 am by EgonOlsen »

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some issues about transparency sorting.
« Reply #2 on: March 26, 2013, 03:01:09 am »
The road is a ring, and some roads may be too complex to split( will cause many small objs). Any other solutions?

。。。。。。
。            。
。A          。    <--- look at
。。。。。。
building-ring

Could i discard the "A" by Z-buffer?



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Some issues about transparency sorting.
« Reply #3 on: March 26, 2013, 07:20:17 am »
Any other solutions?

Could i discard the "A" by Z-buffer?
No, because transparent objects don't write into the zbuffer. If they were, the transparent parts would be written into it too and that would cause gaps and holes in the scene where non should be.
To render transparent objects correctly, it has to be possible to sort them. If all is one large object, then it isn't possible to sort them. You don't have to split the road itself but the building somehow have to be split into several parts. I don't think that it's needed to split them per building though. Larger lumps should do fine.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some issues about transparency sorting.
« Reply #4 on: March 26, 2013, 09:03:33 am »
Thanks, i will try to split the buildings or make them opacity or add an opacity wall behind them.

Another question: Is there any difference of performance between one large mesh and many split ones?
« Last Edit: March 26, 2013, 09:23:06 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Some issues about transparency sorting.
« Reply #5 on: March 26, 2013, 09:39:24 am »
Yes. A large one will be faster in most cases because it requires less draw calls. This might change if it's very large and only a part of it will be visible. That that case, many smaller ones might be better.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some issues about transparency sorting.
« Reply #6 on: March 27, 2013, 09:42:39 am »
Can i do like this :

1, Rendering all opacity objs.

2, Sorting all transparent objs, then rendering them by 2 pass:
 a, pass 1:
     Disable alpha blend, enable alpha test, enable zBuffer, enable zBuffer-writable, only rending the pixel with alpha>=1(means 100% opacity ).

 b, pass 2:
     Enable alpha blend, enable alpha test, enable zBuffer, disable zBuffer-writable, only rending the pixel with alpha<1

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Some issues about transparency sorting.
« Reply #7 on: March 27, 2013, 10:20:17 am »
You would have to do that in your own code, because jPCT-AE doesn't support alpha tests. It will that way in OpenGL ES 1.1 only too, because alpha tests have been removed from OpenGL ES 2.0 anyway. It's also overly complicated IMHO. Why don't you simply split the transparent parts in smaller ones and all is fine!?

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some issues about transparency sorting.
« Reply #8 on: March 27, 2013, 10:43:13 am »
Oh, thanks! The reason are 3:

1, I want to study more (and not just make work done).

2, I hate to export/convert(to .ser)/import/add to world/manager plenty of objs...  I prefer to keep them as few as i can.

3, My artist partner hate splitting them(there are about 21 roads-scene).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Some issues about transparency sorting.
« Reply #9 on: March 27, 2013, 11:07:16 am »
You could try to find a way (using PolygonManager/IVertexController) to split them in code...