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
2
Question by SuIXo3 · Dec 28, 2012 at 01:56 PM · shaderalphasliderblend

Scripting Shader: How to control Alpha with slider?

I'm creating a skybox with physical spheres. And I duplicated the Unlit>Transparent shader to create a skybox shader. I have a color for brightness and a slider to control the alpha (from 0 to 1). The idea is manipulate the slider in other scripts to create the blend effect and see the other skybox through the first one.

But I have no idea how to script shaders. I look around and learned a bit from the manual and other sites but still don't really understand how the code must be written.

In properties I have the slider, brightness color(or tint) and the texture:

_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}

_Brightness ("Brightness", Color) = (.5, .5, .5, 0.5)

_Alpha ("Alpha", Range(0.0,1.0)) = 1

But then I don't know how to apply the value of the slider to the alpha of the texture. The alpha should be the same on the whole image, there is no gradient or anything.

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

Answer by Seth-Bergman · Dec 28, 2012 at 02:34 PM

you can access a shader via renderer.material....

in this case, there are already several working examples out there if you look.. This one works:

http://forum.unity3d.com/threads/115455-Unlit-with-adjustable-Alpha

then you can access the alpha as you normally would, by saying:

renderer.material.color.a = someValue; //from 0 to 1;

this would work with the transparent diffuse, but not the unlit/transparent, though I don't actually know exactly why,just that the unlit/transparent doesn't have a color property.. If there is a way to script the unlit/transparent I don't know it..

Comment
Add comment · Show 8 · 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 SuIXo3 · Dec 28, 2012 at 02:47 PM 0
Share

I have it changing color based on the brightness color. It's more like a tint color. But still, the alpha doesn't work. I change it in the color palette to 0 but the sky is still fully visible.

avatar image Seth-Bergman · Dec 28, 2012 at 03:05 PM 0
Share

you change what? it's very unclear what you are actually doing..

To change the tint, in the above linked script, you could likewise say:

 renderer.material.color.r = someValue; 
 renderer.material.color.g = someValue; 
 renderer.material.color.b = someValue; 
 

if you are accessing the color.a but it is not affecting alpha, you may need to access a different material than the one you are trying...

either way, it seems you are adding extra unnecessary properties, the _Color property inherently handles all of what you are trying to do

avatar image SuIXo3 · Dec 28, 2012 at 03:21 PM 0
Share

I tried with the Transparent/Diffuse shader. It seems to work fine. The problem is that shader is affected by fog and light. I want the same visual result as the "Unlit" shader, with the transparency working as the Transparent/Diffuse shader.

I know I have to add Fog{$$anonymous$$ode off}, lighting Off, etc, within the Pass{} block. But this shader doesn't have one. And when I add it, it just stops working and show black.

avatar image Seth-Bergman · Dec 28, 2012 at 03:24 PM 0
Share

Did you notice the LIN$$anonymous$$ in my answer???!!!!!??!??

http://forum.unity3d.com/threads/115455-Unlit-with-adjustable-Alpha

avatar image Seth-Bergman · Dec 28, 2012 at 03:26 PM 0
Share

here is a nice one too, in general:

http://wiki.unity3d.com/index.php?title=Shaders

Show more comments

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

9 People are following this question.

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

Related Questions

Trying to write a simple mixing 2 textures shader with alpha support on the 2d texture 1 Answer

render Alpha only on another Alpha 0 Answers

Blending one material/texture/shader to another 1 Answer

Blend two texture diffuse shader with alpha 0 Answers

Decal Alpha Blend 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