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
1
Question by newfinalflashers · Mar 17, 2018 at 11:34 PM · shaderalphaplanetalpha-channelalphamap

How should I add an alpha mask AND an alpha multiplier into a shader?

For this planet shader I need the overall thing to render with a mask as well as fade in and out with an alpha variable on top of the mask. I have no clue what to do about this and have went through several forums like the ones below and followed their suggestions but could not get it to work. https://answers.unity.com/questions/244837/shader-help-adding-transparency-to-a-shader.html https://forum.unity.com/threads/alpha-mask-shader-help.181605/ https://stackoverflow.com/questions/41525411/how-to-transparent-unity3d-custom-shader?rq=1 https://forum.unity.com/threads/adding-features-and-modifying-shader.521811/

I tried changing the render type to transparent and adding the transparent queue as well as adding a mask to the properties section but could not get it to work. I also tried adding in an overall alpha for the shader but I feel I am missing a key piece of code or have a particular part of my code that is causing this to not work. There is already an emission based alpha I have to work on top of as I did not make this shader. Help very much appreciated. Thank you.

Shader "Custom/Planet" { Properties { _MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {} _BumpMap ("Bumpmap", 2D) = "bump" {} _EmissionMap("Night Lights Map", 2D) = "white" {} _EmissionStr("Night Lights Strength", Range(0,1)) = 0.5 _EmissionColor("Night Lights Color", Color) = (1.0, 1.0, 1.0, 1.0) _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1) _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 _SpecPower ("Specular Power", Float) = 48.0 } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Planet noambient float _Shininess; float _SpecPower; float _EmissionStr; half4 _EmissionColor;

  half4 LightingPlanet (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
      half3 lightView = normalize (lightDir + viewDir);
      half diffuse = max (0, dot (s.Normal, lightDir));
      float specStr = max (0, dot(s.Normal, lightView));
      float spec = pow (specStr, _SpecPower);
      half4 c;
      c.rgb = _LightColor0.rgb * (atten * 2) * (s.Albedo * diffuse + 
          spec * s.Specular * _Shininess * _SpecColor) + 
          (saturate(1.0-2*diffuse) * s.Alpha * _EmissionStr * _EmissionColor);
      c.a = s.Specular;
      return c;
  }
  
  struct Input {
      float2 uv_MainTex;
      float2 uv_BumpMap;
      float2 uv_EmissionMap;
      float3 viewDir;
  };
  sampler2D _MainTex;
  sampler2D _BumpMap;
  sampler2D _EmissionMap;
 
  void surf (Input IN, inout SurfaceOutput o) {
      o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
      o.Specular = tex2D (_MainTex, IN.uv_MainTex).a;
      o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
      o.Alpha = length(tex2D (_EmissionMap, IN.uv_EmissionMap).rgb);
  }
  
  ENDCG

} Fallback "Diffuse" }

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

0 Replies

· Add your reply
  • Sort: 

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

122 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 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 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 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 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 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 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

Can someone add a 2D texture alpha mask to this planet shader 0 Answers

Change alpha in runtime of gameObject with mobile shader 1 Answer

Water shader with alpha 0 Answers

sprite.associatedAlphaSplitTexture with RGB Crunched ETC1 0 Answers

Shader to render RenderTexture plus alpha? 1 Answer


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