渐变纹理模拟光照

本文介绍了一种使用Unity Shader来实现卡通风格渲染的方法。通过定义自定义着色器,利用两个纹理贴图:主纹理(MainTex)用于获取颜色,渐变纹理(RampTex)用于控制光照效果。该着色器在透明队列中渲染,并忽略投影,适用于多种光照类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shader "Custom/Toon" {
    Properties {
        _MainTex ("Main Tex", 2D) = "white" {}
        _RampTex("Ramp Tex",2D)=""{}
    }
    SubShader {
        Tags { "Queue"="Transparent" "IngnoreProjector"="True" "RenderType"="Transparent" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Toon alpha:fade nolighting

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

        sampler2D _MainTex;
        sampler2D _RampTex;
        struct Input {
            float2 uv_MainTex;
        };

        fixed4 LightingToon(SurfaceOutput s,fixed3 lightDir,fixed atten)
        {
            half NdotL = dot(s.Normal,lightDir);
            fixed4 col = tex2D(_RampTex,fixed2(NdotL,0.5));

            fixed4 c;
            c.rgb = s.Albedo*_LightColor0.rgb*col*atten;
            c.a = s.Alpha;
            return c;
        }
        void surf (Input IN, inout SurfaceOutput o) {

            fixed4 c = tex2D(_MainTex,IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值