2d shader unity 阴影_shader笔记

本文介绍了如何在Unity中创建一个自定义的2D Shader,通过Standard Surface Shader实现颜色、B和A贴图的混合,并讨论了如何在Shader中处理阴影效果。通过对Inputs结构体和Properties代码块的详细解析,展示了如何定义和应用纹理,以及使用lerp函数进行颜色混合。同时,还涵盖了Glossiness和Metallic属性的设置,以及对Shader的完整代码展示。
摘要由CSDN通过智能技术生成

新建Standard Surface Shader,详解说明

f1366c25bee7378fae3c8b822e2c4700.png

Shader "Custom/shader3"

{

    Properties                   //Properties代码块                

    {

        _Color ("Color", Color) = (1,1,1,1)         //Color类型 双引号“Color”是用来显示在Inspector面板中 _Color是内部用

        _MainTex ("Albedo (RGB)", 2D) = "white" {}  //2D贴图类型

         _B ("B", 2D) = "white" {}

        _A ("A", 2D) = "white" {}

        _Glossiness ("Smoothness", Range(0,1)) = 0.5   //数值范围0-1,默认取值0.5

        _Metallic ("Metallic", Range(0,1)) = 0.0

    }

    SubShader                  //SubShader

    {

        Tags { "RenderType"="Opaque" }  //RenderType着色器类型,这里是渲染类型为不透明

        LOD 200                         //渲染层级

        CGPROGRAM            //CG语言 用来生成定点片元pass通道

        // Physically based Standard lighting model, and enable shadows on all light types

         //#pragma surface 指这个是表面着色器 ,surfmjj指方法名,Standard光照模型,fullforwardshadows支持前向渲染阴影

        #pragma surface surfmjj Standard fullforwardshadows             

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

        #pragma target 3.0

        sampler2D _MainTex;   //对应Properties代码块中_MainTex,CG中类型是sampler2D

        sampler2D _B;

        sampler2D _A;

        struct Input     //表面着色器输入结构体

        {

            float2 uv_MainTex;    //纹理uv坐标必须“uv”开头,加纹理名称组合

            float2 uv_A;          //纹理_A的uv坐标

            float2 uv_B;          //纹理_B的uv坐标

        };

        half _Glossiness; //对应Properties代码块中_Glossiness,CG中类型是half

        half _Metallic;

        fixed4 _Color;    //对应Propertiesz中color类型

        UNITY_INSTANCING_BUFFER_START(Props)      //GPU Instancing开和关

            // put more per-instance properties here

        UNITY_INSTANCING_BUFFER_END(Props)

        void surfmjj (Input IN, inout SurfaceOutputStandard o)   //上面申明的surfmjj方法,具体定义

        {

            // Albedo comes from a texture tinted by color

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);

            fixed4 a=tex2D(_A,IN.uv_A);

            fixed4 b=tex2D(_B,IN.uv_B);

            fixed4 d=lerp(c,b,a.a); //lerp混合贴图

            o.Albedo = d.rgb;       //返回主Albedo通道的颜色

            // Metallic and smoothness come from slider variables

            o.Metallic = _Metallic;

            o.Smoothness = _Glossiness;

            o.Alpha = d.a;  

        }

        ENDCG

    }

    FallBack "Diffuse"

}

最后记录下最近的sss皮肤测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值