Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Matt 16 · Nov 30, 2010 at 08:20 AM · shaderprefabmaterial

Different shader parameters for instances of a material

We have multiple instances of a vehicle prefab in our scene (set up very similarly to the vehicle tutorial), and of course each of these share materials, being based on the same prefab.

As in the vehicle tutorial, the brake light system currently sets and intensity parameter on the shader set on the lights material in the OnUpdate function:

if (controls.ThrottleInput < 0.0f)
{
    brakeLights.SetFloat("_Intensity", Mathf.Abs(1.0f));
}
else
{
    brakeLights.SetFloat("_Intensity", 0.0f);
}

Unfortunately, since the OnUpdate is called per vehicle, and the shader parameters shared across all instances since they use the same meterial, by the time the object is rendered, the parameter is set to the last calculated value. Is there a way to either:

  1. Set shader parameters differently on material per object that uses them (having a different material for this makes no sense, defeats the point of a prefab) or..
  2. Specify shader parameters before each object is rendered, basically a sort of OnPreRender but at object scope rather than camera scope?

Thanks :)

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
11
Best Answer

Answer by Jessy · Nov 30, 2010 at 08:53 AM

Don't store brakeLights as a reference to a material. Just store a reference to the Renderer, and use Renderer.material.SetFloat on that. That will automatically instance the materials. (The alternative to Renderer.material is Renderer.sharedMaterial, which would yield the same results as storing a reference to a Material, as you did.)

Comment
Add comment · Show 2 · 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 Matt 16 · Nov 30, 2010 at 10:15 AM 0
Share

Thanks so much. Just to complete this, in our case we ended up exposing a Renderer property that artists could set, as well as an index into the materials array to deter$$anonymous$$e which material should have the parameter set: BrakeLights$$anonymous$$esh.materials[BrakeLights$$anonymous$$aterialIndex].SetFloat("_Intensity", 1.0f);

avatar image MountDoomTeam · Oct 14, 2012 at 03:41 PM 0
Share

also there is sharedmaterial , some kind of array,in the reference!

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

Material doesn't have a color property '_Color' 4 Answers

Changing material with custom shader while instantiating prefab at runtime leads to change in color of all the instances 1 Answer

make unique shader for prefab 1 Answer

Materials showing up black on non-static objects 0 Answers

using shader keywords to toggle pass 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