【unity shader/风格化水表面渲染/基础笔记】urp代码版03-水表面颜色

前言


上一节生成了岸边的泡沫。本节主要梳理水表面的上色过程,这部分涉及半透明渲染和fresnel颜色

颜色


  • 首先,岸边_ShallowCol和远离岸边_DeepCol的颜色应该有所区分。这里依旧利用上一节的RawDepth,稍加处理后变为WaterDepth
float waterDepth = _getNewDepthMask(RawDepth, _DepthRange);

在这里插入图片描述
fig1
图1所示,白色为浅水部分,黑色为深水部分。用lerp后的结果如下
在这里插入图片描述

  • 其次,加入fresnel的颜色
    在这里插入图片描述

这段代码为

                // =========Fresnel=========== //
                real4 base_col = lerp(_DeepCol, _ShallowCol, waterDepth);
                float F = _getfresnelMask(normalW, viewW);
                base_col = lerp(base_col, _FresnelCol, F);

半透明


将RenderType从不透明模式改为半透明模式,之后,颜色的alpha通道能够改变mesh的透明度。同样透明度有depth相关的变量控制

        Tags {"RenderPipeline"="UniversalRenderPipeline"
            "RenderType"="Transparent" 
            "Queue" = "Transparent"
            "IgnoreProjector"="True"}
            
           Tags {"LightMode"="UniversalForward"}
           Blend SrcAlpha OneMinusSrcAlpha
           ZWrite Off

地面换上了之前所做的沙漠纹理
在这里插入图片描述

加入上一节的岸边泡沫
在这里插入图片描述


目前的片元部分的代码

           real4 frag(v2f i) : SV_TARGET
           {
                // =========Get necessity=========== //
                float3 PosW = i.posW;
                float3 normalW = i.normalW;
                float3 viewW = i.viewDirW;

                float4 screenPos = i.scrPos / i.scrPos.w;
                // screenPos.z = (UNITY_NEAR_CLIP_VALUE >=0)?screenPos.z:screenPos.z* 0.5 + 0.5;
                float sceneRawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture,screenPos.xy);
                float3 worldPos = ComputeWorldSpacePosition(screenPos.xy, sceneRawDepth, UNITY_MATRIX_I_VP);
                float RawDepth = PosW.y-worldPos.y;

                float waterDepth = _getNewDepthMask(RawDepth, _DepthRange);

                // =========Foam=========== //
                float FoamDepth = smoothstep(_FoamBlend, 1, RawDepth);
                float wave_noise = SAMPLE_TEXTURE2D(_FoamNoiseMap, sampler_FoamNoiseMap, i.uv.xy).r
                                    *  _FoamNoiseStr;
               
                real4 sinWave = _getFoamWave(RawDepth, wave_noise) * _FoamCol;

                // =========Fresnel=========== //
                real4 base_col = lerp(_DeepCol, _ShallowCol, waterDepth);
                float F = _getfresnelMask(normalW, viewW);
                base_col = lerp(base_col, _FresnelCol, F);

                // =========Mix Results=========== //
                base_col = lerp(base_col, base_col+sinWave, sinWave.a);

                // return float4(base_col.xyz, 1);
                return base_col;
        
           }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值