Global Material Parameters

If I have thousand of objects using the same shader and I need to pass in Global variables into that shader to do some rendering.

What is the best way to keep those parameters up to date. I don’t see looping through all objects to update the parameter? I assume there is a better way.
I need to pass in a height map that is static, so I can do that once when the object is created.
But that height map has 2 variables that change all the time, I need to keep those parameters up to date on thousand of objects.

What is the best practice for that?
One is an integer and other is a float.

I’m using the height map for snow accumulation on any surface that is facing up. Those values tells how much snow has fallen, so I compare against height map to determine if I alter the color to snow color or not.


Are these objects using the same material (as in the same instance) and if they are not, could they?

No not really. I’ve not thought about that. But I could cache the material and use the same one over and over when they have the same texture.

I would limit the number of material.

But would cut it down to about 30 materials for the entire game.

You can either set material parameter overrides on sections of the scene graph. They will be applied to all materials underneath that node.

Or you can just share instances. JME has a cool quirk that if you give the same ColorRGBA, Vector3f, etc. instance to different shaders then you can update that one instance and all shaders will see it. (Material parameters are resent every frame.)

1 Like