I need some explanation of bins and CullBinManager.
As far as I understand objects which you don’t assign to bins are assigned to “opaque” or transparent" bins which are sorted automatcally by Panda (by using the depth buffer.
Each bin seems to have a sort value.
Bin Name Sort Type
-------------- ---- ----------------
"background" 10 BT_fixed
"opaque" 20 BT_state_sorted
"transparent" 30 BT_back_to_front
"fixed" 40 BT_fixed
"unsorted" 50 BT_unsorted
Does this mean each bin is always rendered after the previous one? So if I assign a node to “background” it will always render behind your usual nodes and if you assign it to “fixed” it will always render in front of them?
I want to render some objects one after another and then the rest of the scene on top of them.
Should I assign them to “background”? What is the range of the sort values? Do they have anything to do with the bin’s sort value?
From what I understand “background” and “fixed” don’t use the depth buffer so you can safely disable depth write and depth test?
Yes, but “behind” and “in front of” is not exactly correct. You should really say “before” and “after”. Because of the depth buffer, it’s possible for things to be drawn last, but still appear to be behind other things that were drawn previously. Of course, if you disable the depth buffer, then “behind” and “in front of” is accurate.
That is the purpose of the background bin, so yes.
Do you mean the second parameter to setBin()? That can be any integer. It has nothing to do with the bin’s sort value.
The way it works is: during cull, all objects are grouped in the bin they are assigned to. During draw, all bins are visited in order according to the bin sort number. For each bin, the objects assigned to that bin are drawn in the order specified by the bin type. If the bin type is BT_fixed, this means the objects are drawn in the order according to their setBin() second parameter, with the smaller numbers being drawn first. If the bin type is anything other than BT_fixed, the setBin() second parameter is ignored.
This sentence seems a little confused. The depth buffer has nothing to do with bins, not really. But many people disable the depth buffer for things in the “background” or “fixed” bins, because they want things in these bins to appear behind or in front of the rest of the scene, and they don’t want the depth buffer interfering with that. Note that this trick only works if the items you’re drawing don’t require the use of the depth buffer to draw themselves correctly (i.e. they’re flats or otherwise not self-occluding).
Note that you can also create your own bins, or change the sort values of these default bins, if you want.
I might be confused about how the depth buffer and BT_fixed bins work with each other. I guessed since you can explicitly assign nodes sort orders in those bins, that the depth buffer is ignored for them.
I thought the small value of "background"s sort would already make nodes assigned to it be drawn first.