🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Material System Considerations

Published June 09, 2008
Advertisement
Material SystemSo, the big picture with my material system is that I want to be able to assign an object a particular material, and have the material prepare everything that is needed to render that object. This includes rendering additional render views as required, such as cube maps, shadow maps, etc...

The function paradigm that I will use is for each entity to perform a 'pre' render function to prepare the material, and then call the actual render function when all of the pre-rendering for the current view is complete.

While considering how best to do this, I have come to a few conclusions:

1. The material system must be fully re-entrant, meaning that one material has to be able to perform its duties without depending on other materials. This works out OK since I use render views to encapsulate all of the rendering passes anyways, but I wanted to formalize the requirement.

2. The material preparation must be recursive in nature. Consider what happens when two reflective objects are next to each other - to make it correct, the environment maps for each object need to be recursively updated until an acceptable level of the 'mirrored elevator' look is achieved.

3. The recursive pre-rendering has to have a maximum limit to the number of recursions. The example from point #2 is a good way to crash unless you limit the amount of recursion allowed in the system. I think the way to handle it is to limit the number of times that a render view can be updated in a single frame, but I'll have to test it out to see how well it works out.

With these concepts in mind, I'll probably get started on an implementation in the coming week or so. I should be completely finished with all of the book material by then, and I'll be ready to jump in head first!!!
0 likes 2 comments

Comments

SimmerD
I would highly recommend laying things out somewhat differently, or at least naming things differently. IMO there should be a clear distinction between material - which I view as the physical properties of an object, and the lighting/shadowing being applied.

One example of this is that the diffuse color of a piece of world geometry or other object might be a blend of several textures, including decals. That material looks different on-screen when moved through the environment with different shadowing & lighting properties.

I like your 'render view' concept. It is similar to the 'RenderFrame' object I use in my enginge. The RenderFrame's constructor sets up basic render state needed, possibly set up viewports and switch rendertargets, clear buffers, then the renderframe() takes its view of the subset of objects it has and draws them to that rendertarget, then its destructor sets renderstates back.

Maybe it's just nomenclature, but to my mind the material is the 'Document' - it provides data, including some flags about rendering, like 'i don't cast shadows', etc. and the RenderView chooses some subset of material paramters and other info, maybe associated with the entity, to choose how to render this guy to the current render target.

June 12, 2008 08:53 AM
Jason Z
Hi Sim - its been a while, welcome back! [grin]

You are right, the term 'material' is typically used for a somewhat different purpose. However, in my engine I am attempting to create the material as all of the information (including textures, render parameters, and effect files) for rendering geometry in the context of any type of render view. Due to the flexible nature of render views, this can mean many different types of rendering sequences.

For example, a material needs to be able to render a particular piece of geometry in a paraboloid environment map render view as well as a plain shadow map render view. If the entity that will be using this material is a wooden chair, then the material would represent a static wood material. This would require a wood texture and the effect for rendering a static geometry object into the paraboloid map and the effect to render a static geometry into a shadow map. This would be different a different material for a skinned wooden table, since it needs different effect files to render the geometry appropriately.

For lighting and shadowing, it depends on how you implement the cumulative nature of the light's contribution. In my case, if there is a point light in a scene, then it would actually have a material that contains a 'point light' render view that select the appropriate entities in the scene (within its radius) and then renders the entities into the main render target with additive blending. This rendering pass would use the point light rendering pass information stored in each of the entities' materials.

To be perfectly honest, I can't think of a better term to describe what I am doing here. Any suggestions???

Also, the similarities between our render frames and render views are striking. The only real difference that I see is that I don't store the render states in the object to be restored in the destructor - I just use the effect files to take care of it. Also, the render views typically stick around for a long period of time and get re-used instead of created and destroyed frequently. Even so, it is interesting to know that someone else found the same design pattern useful! [grin]
June 12, 2008 05:48 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement