模型膨胀效果

【核心思路】

让顶点坐标沿着顶点法线方向移动

【效果】

 

【Shader实现】

Shader "Custom/Swell"//采用表面着色器
{
    Properties
    {      
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Color("Color", Color) = (1,1,1,1)      
        _Metallic ("Metallic", 2D) = "white"{}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Occlusion("Occlusion",2D) = "white"{}
        _Normal("Normal",2D) = "white"{}
        _SwellFactor("SwellFactor",Range(0,0.1)) = 0.0 //膨胀系数
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows vertex:vert//设置顶点修改函数

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _Metallic;
        sampler2D _Occlusion;
        sampler2D _Normal;

        struct Input//定义输入结构体
        {
            float2 uv_MainTex;
            float2 uv_Normal;
        };

        half _Glossiness;
        fixed4 _Color;
        fixed _SwellFactor;

        void vert(inout appdata_full v)
        {
            v.vertex.xyz += v.normal * _SwellFactor;//让顶点坐标沿着顶点法线方向移动
        }

        //表面着色器的表面函数
        void surf (Input IN, inout SurfaceOutputStandard o)//SurfaceOutputStandard为适用于金属工作流的物理光照模型的表面结构体               
        {                                                   //该结构体在UnityPBSLighting.cgnic中被定义
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic comes from a texture  
            o.Metallic = tex2D(_Metallic, IN.uv_MainTex);
            //Smoothness come from slider variables
            o.Smoothness = _Glossiness;
            o.Occlusion = tex2D(_Occlusion, IN.uv_MainTex);
            o.Alpha = c.a;

            //采样法线贴图并解包(像素值范围为[0,1],而法线范围为[-1,1]
            float3 normal = UnpackNormal(tex2D(_Normal, IN.uv_Normal));
            o.Normal = normal;

        }
        ENDCG
    }
    FallBack "Diffuse"
}

【材质赋值】

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值