Transparency and speed of rendering

Hi all,
I implemented the transparency in OpenGL (all triangles in my figure are semitransparent)using the depth sorting, but I have to rebuild the bsp tree after each rotation and I draw them with
glBegin(GL_TRIANGLES);
glEnd();
It’s very slow. 40 times drop in speed comparing to the version where I used no transparency. I tried to make each time the array to use glVertexPointer, glDrawArrays and other stuff,but it became even slower.
Please could you tell me how to increase the speed of rendering.
Thank you in advance.

Hi!
I guess rebuilding the bsp every frame is the problem. Why do you do that? Is your scene not static? If it is static there´s no need to rebuild the bsp every frame and if it is not static you should try another algo or sort your array of transparent polys simply with qsort() or something like that.

Greets, XBTC!

Originally posted by XBCT:
[b]Hi!
I guess rebuilding the bsp every frame is the problem. Why do you do that? Is your scene not static? If it is static there´s no need to rebuild the bsp every frame and if it is not static you should try another algo or sort your array of transparent polys simply with qsort() or something like that.

Greets, XBTC![/b]

XBCT’s right. Rebuilding a BSP/Octree is almost certainly unbearably slow. You should probably only use the BSP for static geometry (i.e. level data) and use another method, such as bounding sphere/frustum culling for dynamic object data. I use a static Octree + the sphere/frustum culling and it’s quite fast… I think stuffing all the data each frame into the Octree would give me nightmares

[This message has been edited by soupnazi (edited 02-01-2001).]

Actually my point of view is staic while objects move in the world but the relation between objects, number of objects and other stuff doesn’t change. So after each rotation I have to rebuild the bsp tree because I don’t know how to make minor changes in the bsp-tree and make it correct again for depth sorting.I understand that probably it’s the main reason for drop in speed but how can I reuse the depth sorted triangles in previous frame for next frame?

BTW I build the bsp-tree using stl multimaps and depth sort them by using as a key the distance from the centre of medians to the point of view. Is it correct?

I don’t know how you build your bsp, but I could imagine that this would mean to allocate memory dynamically etc.
If you simply sort them every frame (build a list of indices) that could be done faster I think. There were some discussions running about depth testing here, you can take a look at them. This would not mean to dynamically create a linked tree every frame, which should be a lot faster. The only problem is that this would lead to errors when two transparent faces intersect.

So, your objects moves around a static viewpoint. The relation between all objects are always the same. Isn’t this EXACTLY the same as a fix scene with a moving viewpoint?

Think of it, moving the viewpoint towards an object, is the same as moving the object away from the viewpoint.

A scene can be static even though it moves. A static scene is a scene that never moves internally. A spaceship for example. It’s interior is always looking the same, even though it’s not moving, moving at near-light speed, turning, docking with another spaceship, and so on.

As long as there is no eathquake that modifies the way the scene look, you shouldn’t have to rebuild the tree, if done correctly that is.

OK I build one time bsp tree but and traversing the tree from back to front I can achieve the proper transparency, but what should I do when I rotate the scene. The bsp tree that I build for previous frame basing on the transformed coordinates of rotation and translation matrices is no longer valid because the matrices are now different. So I have to recalculate the distances and rebuild the bsp tree.
How can I reuse the bsp tree built for one rotation and translation matrices for other matrices?

I don’t really understand. The scene is static, but the camera moves. A BSP only has info about the relative position between the polys.
You want to traverse the tree this way:

  1. Go to root node
  2. Look if you’re looking from the front or the back on the root face (plane)
  3. If from back, take the relative front child node, if from front take relative back of childnode
  4. Do that (recursively) until you reach the least node
  5. Start drawing

As you can see, I’m not totally into that BSP stuff. What’s the trick to draw the stuff depth sorted?

Just curious, are you rotating the model or the view? If you are rotating the model, then I could see why you would need to rebuild the tree. But if you are rotating the view, then there is no need to rebuild the tree. So, if you are rotating the model, stop doing so. Instead rotate the view.

It helps if you spell BSP out

Binary Separating Plane…
really binary space partitioning

the point is that each poly separatees the world in half via the plane eqn

You do not depth sort you test on which side of the poly (plane) you are in.

You do this by solving the plane equation for your point… if it is neg you are behind if it is pos you are in front… if 0 you are on…

you sort the polys like this too except you have to know if the split etc…

depth sorting may work, but not in general…

look up bsp tree on this board and on google and you will find your answer…

concentrate on plane eqn

[This message has been edited by frogger (edited 02-02-2001).]

rotating the modell and the camera is the same thing…

No it isn’t. If you rotate the model, then you are also rotating (and possibly translating) the planes of the bsp. Therefore you end up with a new bsp that gets traversed differently. Think of a transparent rotating brush in Quake for example (ignore that fact that brushes didn’t rotate in Quake). It is described by a bsp. Now even if I’m standing still, since the brush is rotating, then either it’s tree must be recalculated so that the transparent parts get depth sorted correctly when walking the tree, or you must transform my view point to a virtual view point, and walk the tree using the virtual point.