- Home /
How to draw a mesh multiple times with different shader parameters
Hello to Unity users,
I've got a small problem I'm trying to solve and your help would be appreciated.
I've got a simple one pass shader with parameters that I can change from code, and I'd like to know the cleaner solution to draw multiples times (a varying / dynamic number of time) an object with this shader, but modifying the parameters between each draw.
What I'm doing right now is having N copies of the mesh in the scene, every copy with a different material (same shader, but different parameters). I'd like to optimize this by having only one copy of the mesh and a simple management of the draw count from code while still being able to update the shader parameters between draws.
How would you do that?
Thanks !
Answer by DavidWatts · Aug 23, 2017 at 12:56 PM
What you need is a material property block. You can use the same material and set a different property block for each renderer. https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
Thank you for your answer! It should do for updating the values, but how can I trigger N redraw of the same object (containing multiple meshes) in the same frame?
Your answer

Follow this Question
Related Questions
Shading is visible through object using surface shader 0 Answers
How to setup Shader Variant Collection 0 Answers
Use Shader Motion Vectors pass in Surface Shader 2 Answers
Referencing the current pixel's world coordinates in the SURF block of a shader 1 Answer
Is it possible to replace texture read with a constant color if texture value is "default-white"? 1 Answer