In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how Unity Shader achieves the rippling effect on the water surface on rainy days. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
Last dynamic effect...
Project requirements, need to add a rainy water ripple effect, the initial idea is to add special effects directly, but after thinking about how much money, unrealistic, the best way is to use shader to achieve, but how to achieve the random diffusion of texture (raindrops have big and small), and irregular time (raindrops have first and then), thought for a long time did not understand, fortunately found a similar effect from AssetStore, after a study, found that it is actually quite simple... share it with everyone.
The two problems I mentioned earlier, random diffusion and irregular time, were solved by this great god with a map (we thought about it at first, but we didn't think of how to implement it). Let's show this map.
This seems a bit confusing, right? Let's separate the four channels and look at them. It's much clearer.
Let me explain it separately. The R channel represents the range of ripples generated, and it has the effect of fading out. The GB two channels are height, which is almost the effect of normal diagram. The A channel is used to store the time difference. Different color values from white to black represent different times.
Next believe many people already understand how to write, here I posted the code, important places have added their own understanding, not many lines, or relatively simple.
Shader "Custom/Ripple" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _RippleTex("RippleTex", 2D) = "white" {} _RippleScale("RippleScale",Range(1,10)) =1
} SubShader { Tags { "RenderType"="Opaque" } LOD 200
CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows #pragma target 3.0 #define PI 3.141592653 sampler2D _MainTex;
struct Input { float2 uv_MainTex; half2 texcoord; };
half _Glossiness; half _Metallic; fixed4 _Color; sampler2D _RippleTex; float _RippleScale; UNITY_INSTANCING_BUFFER_START(Props) UNITY_INSTANCING_BUFFER_END(Props)
//calculate the main function of the ripple float3 ComputeRipple(float2 uv, float t) { //Ripple map samples and extends the height values of the samples to-1 to 1. float4 ripple = tex2D(_RippleTex, uv); ripple.yz = ripple.yz * 2.0 - 1.0; //Get ripple time, get different ripple times from channel A, float dropFrac = frac(ripple.a + t); //Limit time to R channel float timeFrac = dropFrac - 1.0 + ripple.x; //do fade out processing float dropFactor = 1-saturate( dropFrac); //calculate the final height, calculate the amplitude over time with a sin, modify the value to know what effect float final = dropFactor* sin(clamp(timeFrac * 9.0, 0.0, 4.0) * PI); return float3(ripple.yz * final, 1.0); }
void surf (Input IN, inout SurfaceOutputStandard o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb;
//Call the method to get the height. Here I am too lazy to use a new uv, simply use the main map UV float3 ripple = ComputeRipple(IN.uv_MainTex / _RippleScale, _Time.y); // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; //assign to normal o.Normal = ripple; o.Alpha = c.a; } ENDCG } FallBack "Diffuse"} Thank you for reading! About "Unity Shader how to achieve the effect of water ripples in rainy days" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 297
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un