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 Cypras · Dec 27, 2018 at 01:02 AM · shadertransparencywater

Water Shader Transparency Problems

Hi,

When using this ocean shader

 Shader "OceanDepth" {
     Properties {
          _FoamMap ("Foam Map", 2D) = "white" {}
          _ColorMap ("Color map", 2D) = "white" {}
          _LightDir ("Light Direction", Vector) = (0,-1,0)
          
          _FoamSpeed ("Foam speed", Float) = 0.1
          _FoamColor ("Foam color", Color) = (1,1,1,0)
          _FoamPower ("Foam power", Float) = 0.5
          _FoamLevel ("Foam distance", Float) = 0.5
          _FoamThreshold("Foam threshold", Float) = 1
     }
     SubShader {
         Tags { "Queue" = "Transparent" "RenderType"="Transparent"  }
         LOD 200
         
         Pass {
         Tags { "LIGHTMODE"="ForwardBase" "RenderType"="Transparent" }
             
             Blend SrcAlpha OneMinusSrcAlpha
             //ZWrite Off
             Cull Off
             
             CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #include "UnityCG.cginc"
                 
                 uniform sampler2D _CameraDepthTexture;
                 uniform float4 _LightDir;
 
 
                 uniform float _FoamPower;
                 uniform float _FoamLevel;
                 uniform float4 _FoamColor;
                 sampler2D _ColorMap;
                 sampler2D _FoamMap;
                 float4 _FoamMap_ST;
                 uniform float _FoamThreshold;
                 uniform float _FoamSpeed;
                 
                 struct IN{
                     float4 vertex : POSITION;
                     float3 normal : NORMAL;
                     fixed4 color    : COLOR;
                     float4 texcoord : TEXCOORD0;
                     
                 };
             
                 struct OUT {
                     float4 pos : SV_POSITION;
                     float2 textcoord : TEXCOORD0;
                     float4 projPos : TEXCOORD1;
                     float2 wYPos : TEXCOORD2;
                 };
                         
                 float4 getDepthColor(OUT i,fixed4 mainColor,fixed4 foamColorMap){
                     float4 finalColor = mainColor;
  
                     float sceneZ = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)).r);
 
                     float partZ = i.projPos.w;
                     float d = 1 - saturate((sceneZ - partZ) / _FoamLevel);
 
                     float4 c = mainColor;
                     
                     float4 cc =_FoamPower*_FoamColor;
                     c.w = 0;
                     cc.w =1;
 
                     //finalColor = lerp(mainColor, lerp(c,cc,foamColorMap.x > 0.1 && i.wYPos.y  > _FoamThreshold + foamColorMap.x), float4(d, d, d, d));
                     finalColor = lerp(mainColor, lerp(c,cc,i.wYPos.y  > _FoamThreshold), float4(d, d, d, d)); 
 
                     finalColor.a = .75;
 
                     return finalColor;
                 }            
                     
                 OUT vert(IN v) {
                     
                     half3 normal =  normalize(mul(unity_ObjectToWorld,half4(v.normal,0.0)).xyz);
 
                       // How much the light affects to this triangle
                       // range -1..1 to 0..1
                       fixed light = 1+(dot (normal, normalize(_LightDir.xyz).xyz));
                       light*=0.5;
                   
                       OUT o;
       
                       o.pos = UnityObjectToClipPos (v.vertex);
                       o.textcoord = TRANSFORM_TEX (v.texcoord, _FoamMap);
                       o.textcoord.x+=_Time*_FoamSpeed;
                       o.wYPos.x = half(clamp(light+(1-_LightDir.w/100),0,1));
                       o.wYPos.y = mul(unity_ObjectToWorld, v.vertex).y;
                     o.projPos = ComputeScreenPos(o.pos);
                     
                     return o;
                 }
             
                 float4 frag(OUT vert) : COLOR {
                       fixed4 mainColor;
                       mainColor. w = 1;
                       float2 colorUv;
                       colorUv.x = vert.wYPos.x;
                       colorUv.y = vert.textcoord.y;
                       mainColor.xyz = tex2D (_ColorMap, colorUv).xyz;
                     
                     fixed4 foamColorMap = tex2D (_FoamMap, vert.textcoord);
                     mainColor = getDepthColor(vert,mainColor,foamColorMap);
                     
                     return mainColor;
                 }
             ENDCG
         }
     }
     FallBack "Diffuse"
 }
 

Any transparent materials used on objects under the ocean don't get drawn at all on the screen. Is there anyway to get objects with transparent shaders to react the same way as fully opaque objects?

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

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

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

Partially transparent water (Simple/Basic) 1 Answer

Is there a way to have a transparent vertex shader recieve and cast Shadows? 0 Answers

transparent object, so everything behind it appears in grayscale 1 Answer

Transparent Shader/Water With Shadows 1 Answer

How to see both sides of transparrent mesh? 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