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 SBull · Nov 17, 2015 at 07:52 PM · shaderstransparencyalphawaterdistortion

How to add transparency to a waving shader?

I'm trying to get a 2D water effect and found a shader that gives me the wavy effect I'm looking for. Unfortunately, I can't seem to figure out how to add transparency to it. I am trying to emulate something like the water seen here:

https://youtu.be/z1rRuWBfc8k?t=6m6s

I don't need the dynamic waves at the top. I'm mainly just trying to apply this to a textured plane. I have looked through many similar posts about people trying to add transparency to certain shaders and have attempted to add several different lines to the wavy shader, but it seems like the answer is different depending on the type of shader you are using. Here is the shader I am trying to modify:

 Shader "Custom/NewShader" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _SpeedX("SpeedX", float)=3.0
         _SpeedY("SpeedY", float)=3.0
         _Scale("Scale", range(0.005, 0.2))=0.03
         _TileX("TileX", float)=5
         _TileY("TileY", float)=5
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
        
         CGPROGRAM
         #pragma surface surf Lambert
  
         sampler2D _MainTex;
         float4 uv_MainTex_ST;
  
         float _SpeedX;
         float _SpeedY;
         float _Scale;
         float _TileX;
         float _TileY;
  
         struct Input {
             float2 uv_MainTex;
         };
  
  
         void surf (Input IN, inout SurfaceOutput o)
         {
             float2 uv = IN.uv_MainTex;
             uv.x += sin ((uv.x+uv.y)*_TileX+_Time.g *_SpeedX)*_Scale;
             uv.x += cos (uv.y*_TileY+_Time.g *_SpeedY)*_Scale;
  
             half4 c = tex2D (_MainTex, uv);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by MakinStuffLookGood · Nov 17, 2015 at 08:00 PM

EDIT: My knowledge of surface shaders is terrible, here's the actual changes you need to make:

 Tags
 { 
     "Queue"="Transparent" 
     "RenderType"="Transparent" 
 }
 ...
 #pragma surface surf Lambert alpha
 ...

Then, as you have it now you just use the Texture's alpha value, you may want to define another property _Alpha and in your surf program do something like this:

 o.Albedo = c.rgb * _Alpha;
 o.Alpha = c.a * _Alpha;

Multiplying the output Albedo by the Alpha value seems to be necessary for an _Alpha value of zero to actually make the object entirely transparent.

Comment
Add comment · Show 6 · 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 SBull · Nov 17, 2015 at 08:24 PM 0
Share

I gave that a try, but it didn't seem to do anything yet. Would I need to change something in the Properties so that I could adjust the alpha value to tell it how translucent to be?

avatar image MakinStuffLookGood SBull · Nov 17, 2015 at 08:52 PM 0
Share

I was using my knowledge of CG shaders which wasn't applicable in the surface shader world! I've update my original answer with the correct information.

avatar image SBull MakinStuffLookGood · Nov 18, 2015 at 06:18 PM 0
Share

That's okay. You've still helped me quite a bit so far. It isn't quite working yet though. I added:

  o.Albedo = c.rgb * _Alpha;
  o.Alpha = c.a * _Alpha;

But that turns it completely pink.

Do I still need the other lines that you listed before then?:

 ZWrite Off
 Blend SrcAlpha One$$anonymous$$inusSrcAlpha
avatar image SBull SBull · Nov 18, 2015 at 05:44 PM 0
Share

Ah. I was using an opaque texture before and trying to make it semi-transparent with the shader. But if I just make it semi-transparent in Photoshop, then it becomes translucent in Unity. Thanks!

I don't quite understand what to change for the o.Alpha though.

avatar image MakinStuffLookGood SBull · Nov 18, 2015 at 09:09 PM 1
Share

I edited my original answer and took out stuff that didn't need to be here. Here is the complete shader with the _Alpha property implemented:

http://hastebin.com/ijuviteqiq.avrasm

If this solution works for you please mark the answer as correct! :D

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

33 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

Related Questions

Looking for a transparent shader 0 Answers

LWRP - shader graph - transparency for distortion 1 Answer

Transparent Diffuse Specular Normal Shader problem 1 Answer

Changing custom shader. Add alpha cutout 1 Answer

Make a complex object semi transparent without changing it 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