Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 monotoan · Oct 28, 2017 at 04:25 PM · renderingshadersmaterialsgpumaterialpropertyblock

What's the difference between using "[PerRendererData]" and "Enable GPU Instancing" in Unity shaders/materials?

I know that both of these options help optimize GPU performance when rendering many meshes with a few varying material properties -- for example, hundreds of objects that use the same material but should each be a different color.

However, each option seems to give different performance gains, and I haven't been able to find a clear explanation of how they differ or when to use each one.


In other words, when should I do this in my shader:

 Properties {
         [PerRendererData]_Color ("Color", Color) = (1,1,1,1)
 }


vs. this:

    UNITY_INSTANCING_CBUFFER_START(Props)
                 // put more per-instance properties here
                 UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
    UNITY_INSTANCING_CBUFFER_END


...and why?


Running some basic tests in editor (rendering a few thousand cubes with the same material, then varying the color of each one via script), I found that [PerRendererData] reduced render thread time by about 30% (from ~9ms to ~6ms) while enabling GPU Instancing reduced render thread time by closer to 90% (from ~9ms to ~1ms).


So, my best guess is that:
- [PerRendererData] should be used when applying the same material with varying properties to many different objects that ALSO have different meshes (i.e. aren't all the exact same shape). It uses Material Property Blocks to take advantage of material instancing, but doesn't affect dynamic batching in any way.


- GPU Instanced Properties should be used when applying the same material with varying properties to many different objects that have the SAME mesh. It takes advantage of both material instancing and dynamic mesh batching.


Is this right, or are there other important distinctions / technical differences between these two? (Also, is there any documentation source that explains this?)

Comment
Add comment · Show 1
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 michi_b · Oct 31, 2018 at 10:15 AM 0
Share

Since you already set up that test... have you tried setting the material properties via $$anonymous$$aterialPropertyBlock but without [PerRendererData] or did you just instantiate the material for your "unoptimized" test? I'm asking because adding [PerRendererData] does nothing to my shaders' disassemblies and I have also seen comments from Unity staff on forums that claimed that [PerRendererData] is functionally the same as [HideInInspector].

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DavidSWu · Oct 31, 2018 at 08:40 AM

 That sounds accurate to me.
 My guess is that PerRendererData does not have anything to do with instancing, it just allows the rendering system to more rapidly chain together draw calls (semi batching) for related materials 
 I.e.
 (Setup material)
 DrawIndexed()
 VSSetConstants()
 DrawIndexed()

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

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Every shader and quality is pink. URP 2 Answers

MaterialPropertyBlock ignored when rendering with replaced shaders? 0 Answers

Render problems (black, purple and blue effects) in old GPU and Unity3D 5.6 project on Unity 2018 0 Answers

Custom Shader with Canvas Renderer limit draw calls. 0 Answers

How to render material under UI? 1 Answer


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