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 Kiloblargh · May 22, 2011 at 04:52 PM · shaderalphavertextint

What shader do I need to tint an object and fade transparency per vertex?

I checked out the Shader Wiki to see if there's already a user-created shader that does what I want to do but I'm not sure if there is and I'm just missing it. Shader programming is a mystery to me and the manual wasn't much help.

The specific effect I'm trying to do is to have my object disappear if it goes outside of an area, but in a smooth and stylish way. So if its transform.position is past for example +10Z, then the alpha value of each vertex is Lerped between the whole object's current alpha value and 0 based on that vertex's Z position between 10 and 11.

For another effect on the same object, I want to be able to tint the entire thing some percent between a solid hue and its texture map's hue, and set its overall transparency- I am guessing that enabling vertex colors to do the fade effect will allow me to do this too. I can't modify the textures, because all my prefab instances are using the same texture map but their hue and alpha need to change independently.

The objects I want to tint and fade are bumped/specular, and I don't need to have a texture map for transparency on them at all. Is there a shader that already fits this purpose, or do I have to make my own?

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 Peter G · May 22, 2011 at 05:09 PM

You could do it in a shader, but I would suggest doing it in a script that modifies the alpha of the main color in a transparent shader.

 var beginFadeDist : float; //How far from the origin should we be before we start fading
 var fadeDist : float;  //How many units after that before it is totally faded.
 
 function Update() {
       var playerDist : float = transform.position.magnitude;
       //Dist from the origin
 
        var lerpValue = playerDist - beginFadeDist;
        //subtract out the starting point.
        if(lerpValue < 0) return;
        //If we are closer than the start distance, escape and skip the last part.

        var newColor = renderer.material.color;
        //get the current color.
        newColor.a = Mathf.Clamp01(1 - lerpValue /fadeDist);
        //When we are exactly at fadeDist, the alpha will be 0, and it will be clamped after that. 

        renderer.material.color = newColor;
        //assign the new value to the material.
 }

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 Kiloblargh · May 22, 2011 at 06:37 PM 0
Share

Thanks, but fading out the whole object at once is my 'fallback' idea. I was talking about using a for loop through an array of the objects' vertices and setting each of their color.a based on 'lerpValue.'

I didn't mean I wanted to do the effect in the shader- but wouldn't I need a special shader to allow me to do that from a script?

avatar image Bunny83 · May 22, 2011 at 07:25 PM 0
Share

Well, the only buildin shaders that use vertex colors are the particle shaders (AFAI$$anonymous$$). I've created some shaders in the past but i'm actually not a pro in shader creation ;)

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

2 People are following this question.

avatar image avatar image

Related Questions

Transparent Vertex Shader Error 1 Answer

Z-priming alpha-per-vertex 0 Answers

Strange artifacts on Vertex Color Shader 0 Answers

Add Colour tint onto another shader? 3 Answers

Shader is not displaying alpha correctly 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