Seperation of Render and SceneSystem.
#1 Members - Reputation: 230
Posted 20 June 2012 - 01:49 PM
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.
#2 Members - Reputation: 586
Posted 20 June 2012 - 02:21 PM
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 Members - Reputation: 398
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.
#5 Members - Reputation: 230
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 Members - Reputation: 230
Posted 21 June 2012 - 04:37 AM
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?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
#7 Members - Reputation: 1403
Posted 21 June 2012 - 06:13 AM
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 Crossbones+ - Reputation: 1110
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.
Aqua Engine - my DirectX 11 game "engine" - In development
#9 Members - Reputation: 1403
Posted 22 June 2012 - 05:59 AM
(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.).
#11 Members - Reputation: 1403
Posted 29 June 2012 - 06:08 AM
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:
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.
http://www.bungie.net/images/Inside/publications/presentations/publicationsdes/engineering/butcher_gametech04.pdf
page 29
cheers






