How to manage Render States in games (optimizing and more....)

Started by
8 comments, last by HexDump 21 years, 9 months ago
Hello, I´m writing this days a little renderer to use in my engine and I would like to know how ppl manage Render States (for a list of objects with different ones), and how they handle them for every object, what I mean is: 1- Object1 needs to be rendered with alpha blending, no lights, and wireframe. 2 - Object2 needs to be rendered with alpha, lights and solid. How do you guys first create a list of Render States for each object (I think you do not hardcode them for each object (slow, etc...), and how do you then group Objects in order to minimize render state changes, etc... I export models from max, is there any way to get from max the render states every object needs to be rendered well? Thnx in advance. HexDump.
Advertisement
This is my idea that I have not tried yet.

Since you usually only have a few render states, or should, then setup a delta pattern between each one. Pre-calcualte what states you have to change for each active state and when you get a state change request from an object you can just look up which state fields need to be changed and change just them. I can''t realy see having more than ten states for most renderes, so you just have to store ten state changes.
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
A more general form of a delta pattern would be a histogram, probably not as fast as a delta pattern since you still have to evaluate it, but can be used for a few other things as well...

------------
- outRider -
delta pattern? histogram patter? ... pls I do not understand :/, coudl you post an example pls?.
Group them together like this.

Render2D()
{
Disable ZBuffer

Draw objects...
Draw more
Draw
Draw

Enable ZBuffer

}

The Render2D function would disable the ZBuffer to draw 2D objects.. then enable it again when it returns.
Check out ID3DXEffect class. This is very useful. You put your render states in data files instead of hard coding it. For hand setting them, a simple optimization is to filter SetRenderState calls. Wrap SetRenderState() and cache them. Only call Direct3d''s SetRenderState() if the it really changes.

Jack
YES YES, do this, just like in the water example!
I do crap like

#define RALPHA 1#define RGRAYSCALE 2#define RUPSIDEDOWN 3#define RZBUFFER 4...void RenderMode(flags){  switch(flags){  case RALPHA: glEnable(GL_ALPHA_TEST); break;... etc 



I find it pretty easy to flag a bunch of values and just switch() them later in a function.

~ Jesse

The gl2D Project
----------[Development Journal]
quote:Original post by HexDump
...and how do you then group Objects in order to minimize render state changes, etc...


One technique I''ve heard of is a ''shader tree,'' basically a tree whose nodes are renderer state changes with more expensive changes near the root and less expensive ones near the leaves. Here''s a quick link.

Glad I read around! I was going to ask this very question

Thanks for the link, smanches!

Josh

This topic is closed to new replies.

Advertisement