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
1
Question by Nition · Nov 16, 2013 at 01:29 AM · shaderqualitysettingspropertyantialias

Changing shader based on graphics settings

I started with a seemingly simple aim: I have an outline shader that only looks good with 4x or 8x MSAA. The user can change their AA settings in the game, so I also want to automatically change the shader to only show outlines if decent antialiasing is turned on in the Unity quality settings.

Unfortunately I cannot find an elegant way to do this. Any ideas would be appreciated. Some bogus solutions:


Change a shader property.

I can easily change the outline width to zero or use a flag to disable them via a shader property. Unfortunately shader properties are only set via Materials, and can't be tweaked directly.

Change it through the materials then.

There's no way (that I know of) to get a list of all materials so I can find the ones using the appropriate shader and change the property. You can only get materials currently in a scene, but new materials can come into being in a scene at any time. I'd have to be constantly checking.

Have the shader read Unity's AA setting?

As far as I know, shaders can't read external values except through properties, and properties can only be set via materials.


So the only workable solution I can think of right now is to have a specific list of materials using the outline shader attached to an object so I can change them directly, but that means that any time a new material uses the outline shader, I have to remember to manually add it to the list. Or put any materials using that shader into the resources folder so I can access them that way.

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
0

Answer by reefwirrax · Nov 16, 2013 at 10:15 AM

the best way to get any information you can about the graphics settings Using unity itself, and use a unity code to change the shaders on the materials for the materials themselves on any object, or just to change the settings within the shaders. seeing as the shader would have to check with the processor, going backwards through the bus, you may as will just checked straight from the processor and send information forwards to shader, about graphics settings.'

instead of input keys here, you would use the graphics settings information

 #pragma strict
 var mytexture: Texture2D;
 var mymaterial: Material;
 function Start () {
 mymaterial = Resources.Load("green tiles 1", typeof(Material)) as Material;
 mytexture = Resources.Load("461223101") as Texture2D;
 
 }
 
 function Update () {
 
 
 if (Input.GetKeyDown ("1")){renderer.sharedMaterial.shader = Shader.Find ("Custom/vertexoutlines");renderer.sharedMaterial.SetFloat( "select", 0.0);}
 if (Input.GetKeyDown ("2")){renderer.sharedMaterial.shader = Shader.Find ("Custom/vertexoutlines");renderer.sharedMaterial.SetFloat( "select", 1.0);}
 if (Input.GetKeyDown ("3")){renderer.sharedMaterial.shader = Shader.Find ("Custom/vertexoutlines");renderer.sharedMaterial.SetFloat( "select", 2.0);}
 if (Input.GetKeyDown ("4")){renderer.sharedMaterial.shader = Shader.Find ("Custom/vertexoutlines");renderer.sharedMaterial.SetFloat( "select", 3.0);}
 if (Input.GetKeyDown ("5")){renderer.sharedMaterial.shader = Shader.Find ("Custom/vertexoutlines");renderer.sharedMaterial.SetFloat( "select", 4.0);}
 if (Input.GetKeyDown ("6")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223117") as Texture2D;}
 if (Input.GetKeyDown ("7")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223127") as Texture2D;}
 if (Input.GetKeyDown ("8")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223132") as Texture2D;}
 if (Input.GetKeyDown ("9")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223148") as Texture2D;}
 if (Input.GetKeyDown ("0")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223166") as Texture2D;}
 if (Input.GetKeyDown ("-")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223169") as Texture2D;}
 if (Input.GetKeyDown ("=")){renderer.sharedMaterial.shader = Shader.Find ("Diffuse");renderer.sharedMaterial.mainTexture = Resources.Load("461223155") as Texture2D;}
 
 
 }
 
 
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 Nition · Nov 16, 2013 at 06:56 PM 0
Share

The problem with that approach is that it's not possible (as far as I know) to just retrieve a list of all materials. Your script will only update one material, but I was hoping to automatically update any instances of the outline shader. Other materials may be using it too, and I was hoping to not have to manually specify a list of them.

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

18 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

Related Questions

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

Material offset of standart shader - animate? 0 Answers

Frag shader: get value of uv in screen pixels 2 Answers

when change shader dynamically, the following function(shader.PropertyToID) ensures the same values? ​​ 0 Answers

Linear Color Space, Same Color supplied once as Vertex Color, once as a shader property, different results 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