Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Stylized Water 3/Underwater Transparent"
- {
- Properties
- {
- _Color("Color", Color) = (1,1,1, 1)
- }
- SubShader
- {
- //Offset the render queue so that the material actually renders after the underwater fog!
- Tags { "RenderType" = "Transparent" "Queue" = "Transparent+2" "RenderPipeline" = "UniversalPipeline" }
- Blend SrcAlpha OneMinusSrcAlpha
- ZWrite Off
- Pass
- {
- Tags { "LightMode" = "UniversalForward" }
- HLSLPROGRAM
- #pragma target 3.0
- #pragma vertex vert
- #pragma fragment frag
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- //Using a shader variant is optional, as the code is still conditionally executed
- #pragma multi_compile_fragment _ UNDERWATER_ENABLED
- //Include this library
- #include "Assets/Stylized Water 3/Shaders/Underwater/UnderwaterShading.hlsl"
- float4 _Color;
- struct appdata
- {
- float4 vertex : POSITION;
- };
- struct v2f
- {
- float4 positionCS : SV_POSITION;
- float3 positionWS : TEXCOORD0;
- };
- v2f vert(appdata v)
- {
- v2f o;
- o.positionCS = TransformObjectToHClip(v.vertex.xyz);
- o.positionWS = TransformObjectToWorld(v.vertex.xyz);
- return o;
- }
- half4 frag(v2f input) : SV_Target
- {
- float3 color = _Color.rgb;
- float alpha = _Color.a;
- float2 uv = GetNormalizedScreenSpaceUV(input.positionCS);
- #if UNDERWATER_ENABLED
- //Factor to fade the alpha with, material will dissappear into the fog
- float fogDensity = GetUnderwaterFogDensity(input.positionWS);
- //Used to restrict visibility to underwater
- half underwaterMask = SampleUnderwaterMask(uv) * fogDensity;
- //Fade out material as it touches the water level
- float waterLevel = SampleWaterLevel(input.positionWS);
- //Will make the parts that are BELOW the water completely transparent
- alpha *= 1-underwaterMask;
- alpha *= saturate(waterLevel - input.positionWS.y);
- #endif
- return float4(color.rgb, alpha);
- }
- ENDHLSL
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement