Sign in to follow this  
Adi_Jay

Scene Graph Question

Recommended Posts

Adi_Jay    123
I'm really sorry if this has been asked before. I've searched the forum and the internet a lot these past days but couldn't find anything to make me understand scene graphs better. For me it looks like a simple problem but I couldn't find an good answer to it myself. I'm trying to build my own scene graph. Right now it's just a simple tree with 3 types of nodes: base(it's sort of like a group node), geometry, and switch(I plan to use this one as a LOD or to change the geometry in the scene if i need it like if a car has a damaged door or something like that. In the future I think I'm going to separate these to functionalities). For testing i drew just a simple sphere and a box that spins around it. I noticed quite quickly that i wasn't doing something right because the cube was being drawn over the sphere at all time even when the cube was going around the back of the sphere. I know that this is because the render of the cube is called after the render of the sphere. My question is: how should I implement the render calls so that all the time it is called in the right order? Right now i just traverse the scene graph tree multiply the transform matrices of each node and then render the mesh. I was thinking of ordering the children of the grouping nodes by the distance between the position of the child and the position of the camera. But this seemed very costly in time. Also,after reading the posts from this forum and what i found on the internet about scene graphs, I was thinking of making another scene graph for rendering or maybe transferring the stuff that needs rendering into a queue ordered by the distance between the position of the camera and the position of the object that needs rendering. By making the queue i can also sort by render states. But this solution also seems inefficient as this structure would also need to be ordered all the time. What is the usual way to go about this? I think it's probably and easy solution because I didn't see it covered anywhere. I am using C++ and DirectX. Also I mention that I am quite new to DirectX so i might not know about all the possibilities of this API. So if this problem is solved by the API then I am sorry but i couldn't find the functionality that does this. Thank you very much in advance. Regards Adi.

Share this post


Link to post
Share on other sites
haegarr    7372
Sorting objects isn't that unusual. E.g. its a way to go when minimizing overhead of switching rendering states, or when rendering transparent objects (which are often rendered back to front). Several mechanisms are available to speed up sorting, e.g. temporal coherence (i.e. the camera and objects are assumed to be moved not so much that the order determined from the previous frame is totally wrong now), schemes of ordering (e.g. BSPs or octrees or hierarchical bounding-boxes or...).

However, the above mechanisms are working on objects, perhaps sub-objects, but not on a finer grain. But you've mentioned to render using D3D, so you've the graphics API typical depth test at hand. Look out for the documentation of z buffer (or depth buffer) and depth test, that allows you to ignore rendering order (as long as not dealing with transparent objects, state switching optimization, or pixel fill rate optimization).

[Edited by - haegarr on October 21, 2008 3:41:09 AM]

Share this post


Link to post
Share on other sites
Do you even need a scene graph?
Seems like an unnessary overhead. Each object could simply have a pointer to it's parent.
I assume your objects have transparent material?
Otherwise draw order could simply be sorted by the depth buffer.

Share this post


Link to post
Share on other sites
Adi_Jay    123
Thank you very much haegarr, I'll look up everything you talked about an try to figure out a solution.

The z buffer seems interesting. I've read very little on that because I didn't realize what it was for. As for transparent objects I'll think of a solution after I get a working scene graph so that I can get to other tasks of the project.

Sunnyflower thanks for the support I'll post my solution here as soon as I get to one. I hope to finish with this problem by the end of the week.

captainfreedom, the project I'm working on is a 3D game engine. So even if the example I gave seemed simple I hope that there will be more complex stuff going on soon. So in that case I will need a scene graph.

Share this post


Link to post
Share on other sites
Adi_Jay    123
Well I will use the scene graph only to establish a logical relation between the objects that I am drawing. It will help me transform he scene more easily.
For collision detection, frustum culling I will probably also use octtrees or k-d trees. The major part of that, I will design and implement later. I just have the outline right now on some pieces of paper somewhere.

Share this post


Link to post
Share on other sites
Adi_Jay    123
When I wrote this post I had a really big hunch that directx would solve my problem. It turns out I was right. As haegarr and captainfreedom suggested the depth buffer solves that problem quite easily.

This article explains it pretty well :

Link

Thank you all for your answers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this