Jan Haas

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

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