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
0
Question by Tristannn · Oct 24, 2016 at 05:44 PM · animationshadersmaterialsvertex colormaterialpropertyblock

Shader Animation (and PerRendererData)

I'm trying to determine the most optimized way to animate a shader. For example, say I wanted a looping animation of a texture fading to full white and back while both the texture and the mesh are initially shared across multiple duplicates of the asset in the scene.

  • I could take the mesh and set the vertex colors every frame, breaking the shared mesh (also, might this generate a new mesh every frame?)

  • I could use Material Property Blocks to set a shader parameter every frame, generating new materials every frame

  • I could use Material Property Blocks to set a [PerRendererData] shader parameter every frame. This sounds like it might be the best option, but I can't find anyone online suggesting this.

and a quick followup question... how do I judge when to use [PerRendererData]? I feel inclined to use it for just about every parameter on a shader that I would ever want to edit at runtime... is that right?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by monotoan · Oct 28, 2017 at 04:56 PM

The answer here depends on whether you want the shader to animate the same way on every mesh it's material is applied to, or have the animation vary on different meshes (fading to white at different times on different objects, for example).

If the animation should behave the same way on all objects, then just set a Global Shader Variable to modify the fading property from one script, or set the property on renderer.sharedMaterial (instead of renderer.material) and you shouldn't run into any issues with generating multiple materials -- but the material will animate the same way on every object.


If the animation should behave differently on each object using the material/shader, then yes, [PerRendererData] is probably the way to go, as this will enable you to vary the same property across each instance of the material.


If the animation should behave differently AND each object the material is applied to has exactly the same mesh, then use "Enable GPU instancing" and put the property you're varying inside the instanced properties section of your shader. This will keep your meshes batched and your material instanced (instead of creating a new material for each object). If you're using a lot of versions of this object, this should boost performance significantly.


One other option: If you're just trying to run a looping animation, you could probably create that looping change in the shader itself using the built in float "_Time" shader property. Then you wouldn't have to pass in any parameters at all, and the shader would just run the animation. If you wanted the looping time to vary on different objects, you could just pass in a random value parameter to the shader on "void Start()" (probably still using [PerRendererData] / GPU instancing), and use that one random value to offset your _Time - based looping animation on each object for the rest of the time that the game is running.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change textures over time? 0 Answers

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

Is animation of shaders (such as tint) broken in 4.3? 2 Answers

Dynamically assigning a material doesn't work on mobile? 1 Answer

cut a hole in a sprite with alpha 2 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