x


Graphics.DrawMesh and MaterialProperty Blocks

I'd like to fire up the following question as I have found the same problem:

http://answers.unity3d.com/questions/3483/problems-with-graphics-drawmesh-where-to-call-it-and-how-to-get-material-propert

This is what I understand from the documentation:

  1. Graphics.DrawMesh(...) is used to queue up meshes to render that you don't want to have gameObjects for. i.e. it saves you the cost of instantiating many objects if you want many copies of that mesh drawn.

  2. If all of those meshes are to be drawn with essentially the same material but perhaps each one varies by colour or by alpha or something like that, you can use a MaterialPropertyBlock which is essentially some parameters to create a variant of the used Material to apply at render time. So this means you don't have to create a new material for every mesh drawn, you simply create a MaterialPropertyBlock with the modified element eg. the color.

The thing is that no matter how hard I try, every time I try to use material property blocks all the meshes are drawn the same. Apparently using one variant of the MaterialPropertyBlock for the whole lot. I guess what I would like to know is if I am interpreting the documentation correctly and if so is this a bug? And if it is a bug, is it fixed in Unity 3

Documentation for reference: http://unity3d.com/support/documentation/ScriptReference/Graphics.DrawMesh.html

more ▼

asked Jul 18 '10 at 11:24 AM

cncguy gravatar image

cncguy
1k 21 25 36

Could you post some code demonstrating more precisely the problem you're experiencing? Having some code reproducing the problem to test with may increase the responses to this question and/or the linked one. Graphics.DrawMesh(mesh,matrix0,material,0,null,0,propertyBlock0,false,false); Graphics.DrawMesh(mesh,matrix0,material,0,null,0,propertyBlock1,false,false); alone doesn't really tell anyone how the use case is trying to change the property block although obviously instantiating two separate propertyBlocks should produce the desired result.

Jul 20 '10 at 02:24 PM skovacs1

Also, Aras' answer in the linked question seems to identify a potential part of the problem. Are you using single or multiple pass shaders in your material? pixel-lit or vertex-lit shaders? If so it may well be the bug he mentioned and should be submitted as a bug report if it hasn't been already.

Jul 20 '10 at 02:32 PM skovacs1

Hi sorry Missed your comments. Nightime here, will post some code tomorrow.

Jul 21 '10 at 11:47 AM cncguy
(comments are locked)
10|3000 characters needed characters left

0 answers: sort newest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x841
x505
x16
x3

asked: Jul 18 '10 at 11:24 AM

Seen: 1596 times

Last Updated: Jul 18 '10 at 11:24 AM