Jump to content

  • Log In with Google      Sign In   
  • Create Account


Seperation of Render and SceneSystem.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 korvax   Members   -  Reputation: 304

Like
0Likes
Like

Posted 20 June 2012 - 01:49 PM

Hi,
im try to write my own render engine as a hobby so its nothing fancy. Im trying to seperate scence graphics and graphics objects from the Rendering part of engine.

Lets say i have a object that contains the Geometry, lets call the one DX11Geometry. It contains stuff like DX11buffers and other DX11 related stuff. This object does only exist in the rendersystem..

in the SceneManagment i have a scenobject that repesent the actuall object in the ending, it contain the stuff like translation, rotation..


Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..

I was think that SceneObjectcould have some kind uID that points to a DX11Gemotry object in the RenderSystem..
like RenderSystem->RenderGeometry(int uid). Im not sure how efficent this methody is, when because i would need some kind of array in the RendetrSystem to store all the DX11Gemotry object..

any thoughts on this are more then welcome.. im quite new to this kind of graphics programing.

Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
1Likes
Like

Posted 20 June 2012 - 02:21 PM

In my engine I do this:
class Scene
  Object[] objects
class Object
  vec3 pos
  Quaterion rot
  Model *model
  virtual void draw()
class Renderer
  vec3 cameraPos
  Scene *scene //draws scene at cameraPos
  virtual void draw()

class Model
  vec3 verts,norms,etc
  virtual void process()
  void load(string path)
    do stuff
    process()
 
I then make custom implementations of Model and Renderer for each API (and even rendering technique, deferred vs forward, etc). You can have a load that's API independant and then subclass Model to make a DX11Model that would store any necessary info and override process() to handle uploading the data to the GPU, and have different subclasses of Renderer that override draw() to handle the different APIs, etc

#3 Digitalfragment   Members   -  Reputation: 827

Like
3Likes
Like

Posted 20 June 2012 - 07:34 PM

Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..


Create a data bridge type that links a SceneObject to a DX11GeometryObject, SceneObject doesnt know about DX11GeoObject and vice-versa. std::pair<SceneObject*,DX11GeometryObject*> fits well for that. Then you have a process that goes through the pairs and copies the appropriate data across from SceneObject (transforms etc) into your DX11 constant buffers. The object is a two way association, but a 1 way data pipeline.

#4 korvax   Members   -  Reputation: 304

Like
0Likes
Like

Posted 21 June 2012 - 12:04 AM

Hi, thx a lot for two excellent answers. Think i will actually look in to both solutions two my problem. Have to say that i totally forgot about the std::pair.
I like this forum already people that actually know there stuff! Posted Image

#5 korvax   Members   -  Reputation: 304

Like
0Likes
Like

Posted 21 June 2012 - 02:57 AM


Here's my question, how do I best link the SceneObject to the DX11Geometry object. Remeber i do want the RenderSystem completet independent of the ScenceObject, so SceneObject dont know what a DX11Geometryobject is..


Create a data bridge type that links a SceneObject to a DX11GeometryObject, SceneObject doesnt know about DX11GeoObject and vice-versa. std::pair<SceneObject*,DX11GeometryObject*> fits well for that. Then you have a process that goes through the pairs and copies the appropriate data across from SceneObject (transforms etc) into your DX11 constant buffers. The object is a two way association, but a 1 way data pipeline.


Is this a better way of doing it than using a int ID thats mapping them, and then storing DX11GeometryObject in a array structure, or is it faster to use pair and then map it with objects?

#6 korvax   Members   -  Reputation: 304

Like
0Likes
Like

Posted 21 June 2012 - 04:37 AM

I then make custom implementations of Model and Renderer for each API (and even rendering technique, deferred vs forward, etc). You can have a load that's API independant and then subclass Model to make a DX11Model that would store any necessary info and override process() to handle uploading the data to the GPU, and have different subclasses of Renderer that override draw() to handle the different APIs, etc

In this case do you end up doing a a lot of static_cast in each frame in the RenderSystem between the Model and the DX11Model? If so isn't it rather costly to cast ever model each fram?

#7 Krypt0n   Crossbones+   -  Reputation: 2526

Like
2Likes
Like

Posted 21 June 2012 - 06:13 AM

I use something similar to what I've read in a presentation from the halo guys.
my logic side requests an ID from the renderer when it creates an object, based on strings to a mesh+material.
this ID is 32bit, lower 16bit represent an index into an array of object references in the renderer, and upper 16bit represent a counter that identifies the object in the array slot.
int createObject(std::string Mesh,std::string Material)
{
   int ID=find(Mesh,Material);
   if(ID>=0)
	 return ID;
   int ID=FindEmptySlot();
   QueueObjectForStreaming(ID,Mesh,Material);
   ID|=(m_CounterArray[ID]+1)<<16;
  return ID;
}
every time I create an object I try to find a free slot in the array of obiect, increase that counter and return (Counter<<16)|ObjectIndex;
if the array is full, I obviously overwrite some old object. when the logic side want to render, it just passes the ID + world matrix and the renderer indexes into the object array, if the upper 16bit match with the counter, the object is rendered, if not, it's obviously not the right one.
if the counter is < of the ID, then it means the streaming system is trying to load it in a queue, then I drop to some default object (box in my case), if the counter is higher, the object needs to be recreated. there are various ways the handle it, e.g. your "draw" call to the renderer could return that this object is invalid.

the nice part is that the rendering and logic are really completely separated (ok, not fully true, my collision checks try to access the mesh to share data), you can have a lot of references to the same object, it's transparently streamed in and also it can be removed (if not replaced), if memory is getting critical.

Edited by Krypt0n, 21 June 2012 - 06:14 AM.


#8 TiagoCosta   Crossbones+   -  Reputation: 2078

Like
0Likes
Like

Posted 22 June 2012 - 02:46 AM

I use something similar to what I've read in a presentation from the halo guys.
my logic side requests an ID from the renderer when it creates an object, based on strings to a mesh+material.
this ID is 32bit, lower 16bit represent an index into an array of object references in the renderer, and upper 16bit represent a counter that identifies the object in the array slot.

int createObject(std::string Mesh,std::string Material)
{
   int ID=find(Mesh,Material);
   if(ID>=0)
	 return ID;
   int ID=FindEmptySlot();
   QueueObjectForStreaming(ID,Mesh,Material);
   ID|=(m_CounterArray[ID]+1)<<16;
  return ID;
}
every time I create an object I try to find a free slot in the array of obiect, increase that counter and return (Counter<<16)|ObjectIndex;
if the array is full, I obviously overwrite some old object. when the logic side want to render, it just passes the ID + world matrix and the renderer indexes into the object array, if the upper 16bit match with the counter, the object is rendered, if not, it's obviously not the right one.
if the counter is < of the ID, then it means the streaming system is trying to load it in a queue, then I drop to some default object (box in my case), if the counter is higher, the object needs to be recreated. there are various ways the handle it, e.g. your "draw" call to the renderer could return that this object is invalid.

the nice part is that the rendering and logic are really completely separated (ok, not fully true, my collision checks try to access the mesh to share data), you can have a lot of references to the same object, it's transparently streamed in and also it can be removed (if not replaced), if memory is getting critical.


That looks like a good solution but I have some questions...

How is the logic side able generate the ID? Since it is separated from the renderer it has no way of knowing where the object is stored right? the createObject() function is part of the renderer?, if so the scene system shouldn't be able to call it.

Edited by TiagoCosta, 22 June 2012 - 02:47 AM.


#9 Krypt0n   Crossbones+   -  Reputation: 2526

Like
0Likes
Like

Posted 22 June 2012 - 05:59 AM

at some place you need to have an interface where you pass data. so yes, "CreateObject" is a renderer interface that the logic side uses. but it's not a connection, it's still separate. if you e.g. want to run on a server without a GPU, you just don't run the renderer thread (or update, if single threaded), the logic still can get some handles and pass them for rendering, they would have no meaning, they also have no meaning of the engine, it's just a handle that could potentially represent something. if you want, you can create a compile time flag (aka #define) that does not create any rendering code at all and "CreateObject" always just immediately returns 0;

(my system is actually a bit more complicated and it's not the renderer that is handling that part, but the resource system that is shared between game logic, scene'graph', renderer, streaming, physics etc.).

#10 korvax   Members   -  Reputation: 304

Like
0Likes
Like

Posted 25 June 2012 - 02:09 AM

I use something similar to what I've read in a presentation from the halo guys.


Do you remeber where you found that articlepls?

thx for you help thought.

#11 Krypt0n   Crossbones+   -  Reputation: 2526

Like
0Likes
Like

Posted 29 June 2012 - 06:08 AM


I use something similar to what I've read in a presentation from the halo guys.


Do you remeber where you found that articlepls?

thx for you help thought.

took me my lunch time, thought it was was halo 3 paper, didn't remember it was from halo2, so it was kind of the last one I checked, lol, yet, here it is:
http://www.bungie.net/images/Inside/publications/presentations/publicationsdes/engineering/butcher_gametech04.pdf
page 29

cheers




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS