Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by qhhh · Feb 01, 2010 at 10:08 PM · renderinggraphics

Problems with Graphics.DrawMesh, where to call it and how to get material property blocks to work.

I've been trying to use Graphics.DrawMesh to improve the performance of drawing multiple instances of a mesh and have run into some issues.

Based on the documentation I first tried to call Graphics.DrawMesh in the OnRenderObject method which didn't work. Putting it in the Update method instead solved the problem but is that really the proper location of calls to Graphics.DrawMesh?

Another issue is that modifying shader parameters between Graphics.DrawMesh calls using material property blocks doesn't appear to work. It looks like the material property block of the first visible instance of the mesh will get used by all other instances of the mesh, even if each draw call uses a different material property block.

Can somebody provide an example of working code that renders two or more instances of a mesh and applies different material property blocks to each instance?

Here's a (simplified) C# version of my Update method:

Graphics.DrawMesh( mesh, matrix0, material, 0, null, 0, propertyBlock0, false, false ); Graphics.DrawMesh( mesh, matrix1, material, 0, null, 0, propertyBlock1, false, false );

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cncguy · Jul 18, 2010 at 11:01 AM 0
Share

I've run into the same issue. I want to draw hundreds of markers with the same texture but varying alpha. I was using $$anonymous$$aterialPropertyBlocks and Graphics.Draw$$anonymous$$esh(...). But I found as you did that it didn't work as documented. It seemed to use one variant of the material for all the markers.

avatar image cncguy · Jul 18, 2010 at 11:04 AM 0
Share

Did you get any joy on this problem in the end? I had to resort to using OnPostRender on the camera. But you solve one problem and you end up with another as it then renders over the top of all transparent objects since it is rendered after everything else. It does respect Z-depth for non-transparent objects though.

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Jaap Kreijkamp · Feb 02, 2010 at 12:22 AM

DrawMesh doesn't execute the rendering immediately so it doesn't really matter where you put it (I use lateupdate for several reasons but in update is fine). As the renderering isn't executed at call time, modifying materials between calls doesn't work (it takes the material at time of rendering so probably the final state). It sounds like you need to use Graphics.DrawMeshNow.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andy-Block · Feb 21, 2013 at 11:26 AM 1
Share

Note that it can matter where you put it, depending on what you are doing. I was drawing a mesh in Update, but it's position was sometimes 'laggy' when the camera was moving. I think this was because the movement was being done via HOTween, which I am guessing does its updates in 'Update'; as a result, behaviour varies for objects that were updated before the tweener and those that were updated after the tweener. $$anonymous$$oving my Draw$$anonymous$$esh to LateUpdate resolved the problem.

avatar image
2

Answer by Aras · Feb 02, 2010 at 03:47 PM

Like Jaap said, Graphics.DrawMesh does not render the mesh immediately. So it does not really matter where you put it; it will be eventually drawn in that frame.

I just found out that indeed, using MaterialPropertyBlock works funny with per-pixel lit shaders (or perhaps all multipass shaders). If I use VertexLit shader (or any other single pass shader) on the objects, then it works correctly for me.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-2

Answer by tony oakden 1 · Jun 23, 2010 at 04:55 AM

I'm trying to use the DrawMesh code in my game but objects which I try to render using it don't light properly. See my other thread on the topic: http://forum.unity3d.com/viewtopic.php?t=53159

Can anyone advise why this might be? To summarise objects which i try to render using hte DrawMesh code light overbright on faces which face the directional light in the scene which i am using for the sun. If I render the same object using the normal rendering code they light perfectly. I'm at a loss to understand why this might be and would like to fix it.

thank you in advance,

Tony Oakden

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Blank screen on Android 0 Answers

Unity 5 Custom Deferred shader 0 Answers

Why is this issue occurring with my models? 1 Answer

Object see-through when rendering mode is set to Fade 1 Answer

Cutting hole in water plane using stencil buffer.Help making it visible from both sides. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges