|
- float4 offsetColor = (tex2D(_BumpTex, IN.uv_WaterTex + float2(_WaterSpeed*_Time.x,0))+tex2D(_BumpTex, float2(1-IN.uv_WaterTex.y,IN.uv_WaterTex.x) + float2(_WaterSpeed*_Time.x,0)))/2;
- half2 offset = UnpackNormal(offsetColor).xy * _Refract;//法线偏移程度可控
- //让水面检测深度并根据Grab贴图 显示;
- float2 uv = IN.proj.xy/IN.proj.w; // 获取屏幕纹理坐标信息
- fixed4 water = (tex2D(_WaterTex, IN.uv_WaterTex )); //采样water贴图
- half4 bott = tex2D(_GrabTexture, uv+offset); //采样渐变贴图
- fixed dis1 = distance(IN.uv_WaterTex,fixed2(0.5,0.5));
- fixed2 uv1 =IN.uv_WaterTex + 2*sin(_Time.y + dis1*2);
- fixed4 c =tex2D(_WaterTex,uv1);
-
- //计算当前像素深度
- float depth = tex2Dproj (_CameraDepthTexture, IN.proj).r; //UNITY_PROJ_COORD:深度值 [0,1]
- half m_depth = LinearEyeDepth(depth); //深度根据相机的裁剪范围的值[0.3,1000],将经过透视投影变换的深度值还原
- half deltaDepth = m_depth - IN.proj.z;
- fixed4 waterColor = tex2D(_GTex, float2(min(_Range.y,deltaDepth)/_Range.y,1)); //根据深度显示水的颜色
- //采样两次法线,交叉移动形成波光粼粼的样子
- float4 bumpColor1 = tex2D(_BumpTex, IN.uv_WaterTex + offset + float2(_WaterSpeed*_Time.x,0));
- float4 bumpColor2 = tex2D(_BumpTex, float2(1-IN.uv_WaterTex.y,IN.uv_WaterTex.x)+offset + float2(_WaterSpeed*_Time.x,0));
- o.Normal = UnpackNormal((bumpColor1+bumpColor2)/2).xyz; //采样法线贴图,并移动。
- o.Specular = _Specular; //镜面反射系数
- o.Gloss = _Gloss; //实时调整光泽系数 就是光强
- //深度 控制 颜色
- half water_w = min(_Range.w, deltaDepth)/_Range.w;
- o.Albedo = bott.rgb * (1 - water_w) + waterColor.rgb * water_w; //输出纹理
- o.Alpha = min(_Range.x, deltaDepth)/_Range.x; //岸边为透明,所以a的值是根据深度来控制的
复制代码
|
|