Sign in to follow this  

Unity How do YOU render?

Recommended Posts

I'm trying to find an optimal method to rendering a given number of 'renderables' by optimizing state changes. Ordering state changes is not hard, I'm just having trouble putting together a design that is easy to use. Here are my two designs I have come up with (Neither of which make me 100% happy): Design 1: I define a 'Renderable' as a class that holds pointers to vertex buffers, index buffers, a shader (Cg in this case), and a technique. My 'RenderList' is a list of these Renderables that are ordered in a linked list fashion. I order my Renderables by sorting them when I add them to the list. They are sorted by (Render Target, Transparency, Shader, Technique). For each Renderable in the list that gets sent to the Renderer, the Renderable is polled for new information. New parameters are set in the shader and vertex data is drawn. Pros: Linked list is easy to push, insert and pop from. Cons: Each Rendrable must know about the state of the world in order to set the shader parameters properly - ie. Transformation matrices, textures, etc. Design 2: As above, A Renderable class is defined. It only contains a pointer to a vertex and index buffer, nothing else. A RenderTree is now used as a collection of these Renderables. It groups the Renderables by (Render Target, Transparency, Shader, Technique, and Parameter) changes. It basically contains a stack of states that get pushed and popped off the stack (ie. you only set the world view and projection matrices once). This mimics the way OpenGL does it's transformation stack. This is similar to a scenegraph, I believe. Pros: This is a bit more efficient then the above in that it does not poll renderables for their states. Each renderable does not need to know the world state in order to set the shader parameters (like world view projection matrices). Cons: Relies heavily on the user of my code to set up her own render list. Does not automate code (maybe it's a pro?). Anyway, I have both designs on the table. I would like to hear what the GameDev community uses as a rendering mechanism. Perhaps, if anyone has experience with some of the more known engines out there, they can throw in their two cents with rigards to how they render objects (OGRE, Irrlicht, SlimDX, etc?). Thanks for the help.

Share this post

Link to post
Share on other sites
Here is the design for my (unfinished) graphics engine.

* minimize and coalesce API-dependent code into a few key areas
* generality (works for different projection types, 2D/3D, shaders)
* built-in support for commonly used features (shadows, dynamic environment maps, reflections)

* GraphicsObject - sort of like a scene graph node but only for transformations. Each object has a pointer to a GraphicsShape and a list of child graphic objects, plus a transformation (position, orientation, scale). Transformations are accumulated as one recurses down the tree. It also contains a bounding volume for fast hierarchical culling.
* GraphicsShape - generic shape superclass which contains information common to all types of shapes (bounding volume, material, object-space transformation). Uses the visitor pattern with the ShapeDrawer class to avoid RTTI when drawing.
* Material - contains a shader, list of texture units (shader name/index/texture), and a list of named shader attributes for the material (of any type: float, vector, matrix).
* ShapeDrawer - interface for shape drawing. has a draw*(shape) method for each type of shape (ex: sphere, cylinder, static mesh, articulated mesh, heightfield). Most of the API-dependent code is here.
* VisibilityCuller - abstract type which contains all GraphicsObjects being drawn and support queries to determine which objects are in the view of a given camera. Probably uses an octree internally to speed queries.
* Renderer - class which does the organizational work when rendering. For each camera/viewport (including shadow maps) it uses the VisibilityCuller to determine which objects to draw. It then sorts the list by transparency, then material (they can be shared between shapes), then shader. It then iterates through the list drawing all opaque objects (with a ShapeDrawer) making minimal state changes. Finally, it sorts all transparent objects back-to-front and draws them in order. The Renderer also handles pushing/popping transformation matrices.

This is probably quite a bit more complicated than your designs but I think it is the best I've come up with yet.

Share this post

Link to post
Share on other sites
I have a separate Spacial Partitioning system in my code, which I will leave separate from the rendering system. I also used to have a Material class that worked as you did, but I ended up dumping it for something else a while ago (now I'm starting to think I should have kept it). Your Material class seems very generic - it holds a shader and it's state. This seems like a decent design and I might end up resurrecting my Material class to match your description.


built-in support for commonly used features (shadows, dynamic environment maps, reflections)

How exactly do you achieve this? Do you expect a certain shader type to interact with when drawing shadows/reflections/environment maps?

Share this post

Link to post
Share on other sites
Original post by RealMarkP

built-in support for commonly used features (shadows, dynamic environment maps, reflections)

How exactly do you achieve this? Do you expect a certain shader type to interact with when drawing shadows/reflections/environment maps?

Each material object also has 2 names (of the variables in GLSL) for the shadow and environment maps, and boolean flags indicating whether or not the shader needs them. The renderer takes care of rendering shadow maps for each light source and therefore the shader only has to perform depth comparisons. The assumption is that whatever is creating the material object will know whether or not it accepts shadows.

Of course this is just the "plan." None of this is actually fully implemented yet.

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  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By Afambus
      I have a full experienced team that looking for a composer and another 3d designer, im expecting as much from you there are other people in this server that can help you we have a determined team, we have done many things in our game there is more information in the discord about everyone and there skills there region and about the game, if you join the discord pm asap
    • By BAG Labs
      Mobile SoS

      Platform: Android
      Genre: Board
      Link: Google Play
      This games sharpen memory and test your strategies to place S-O-S pattern within time limit and serve 3 difficulties as Easy, Normal, and Hard.

      Goals of the game is to put S-O-S words in patterns (Horizontal, Vertical, and Diagonal) alternately with enemy.
      Single Player Multiplayer Achievements Leaderboards  



      Link: Google Play
      Please help us improve this game with review
    • By abarnes
      I am a game development student in my second year of a three year program and I would like to start building my portfolio. I was thinking of creating some games to show what I can do to potential employers since I wont have any work related experience when I graduate. But as I'm sure you all know there are tons of ways to approach developing/designing a game and I'm curious if anyone had any insight as to any "standards" that come with this? Is it okay to use game engines like Unity, Unreal, Game Maker etc? Or would it be better to make a game from scratch to better show case your skills? Any and all advice will be greatly appreciated!
    • By Hilster
      Hello 2D Artists,
      I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active. 

      The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
      The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
      I intend to add more objects so the amount I'd like to add will be extended.
      My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.
      Please reply with a few past examples of your art below and I'll be in touch!
    • By thefollower
      I have set up my TcpClient to connect to my server and that works fine. But i am a bit confused how i read messages from the network stream with it continuously running via async, without ever closing the connection ?
      My TcpClient Manager class has:
      public async Task<bool> Connect(string address, int port) { try { await _tcpClient.ConnectAsync(address, port); IsConnected = true; return true; } catch(Exception e) { Debug.Log(e); return false; } } public async Task<int> Read(byte[] readBuffer) { if (!IsConnected) return -1; using (var networkStream = _tcpClient.GetStream()) { try { var bytesRead = await networkStream.ReadAsync(readBuffer, 0, readBuffer.Length); return bytesRead; } catch (Exception e) { Debug.Log(e); IsConnected = false; return -1; } } }  
      So i thought to just run a co-routine and call Read constantly to get the most recent message, but that doesn't make much sense to me since a co-routine would be blocked with the await. How is this actually done? The MS Docs don't have very good Async examples with the TcpClient class so i don't know fully get how to keep calling Read correctly.
  • Popular Now