How to design a material system that can be dynamically updated?

Started by
1 comment, last by MJP 6 years, 6 months ago

Hello guys ;)

My engine is currently only capable of rendering using materials that are shared among different meshes. (Change one parameter -> every mesh has it)
So my rendering loop looks like this:
for all materials m: upload common matrices (projection etc.). Use the shader. Then for all meshes associated with m: Render it after uploading model matrix.

But what if I want to instance a material (like in UE4)? This would mean that I either have to create a different shaderprogram for all different instances OR use one common shaderprogram. The last option implies that I have to update the uniforms of said shaderprogram each time I render an object with a material instance. 

So I don't know whats worse: A State change or high frequency updates of uniforms which decreases my bandwidth? 
My question: What is the best way to deal with the problem and how would a possible render loop look like?
 

Thank you.

Advertisement

I would go with updating a constant buffer that contains the material parameters. It's very common to update a constant buffer before issuing a Draw, so drivers will try to optimize for that case. For DX11, you can see this article from Nvidia on how to optimize your constant buffer updates, and use D3D11.1 features in Windows 8.1 to make updating them even faster. On DX12/Vulkan/consoles updating a constant buffer is (almost) completely in your hands, and so you can potentially make it *really* fast.

This topic is closed to new replies.

Advertisement