【千锋合集】史上最全Unity3D全套教程|匠心之作_哔哩哔哩_bilibili
Unity Shader教程 序+Shader和材质的创建与认知 - 哔哩哔哩

?
Shader "Custom/NewSurfaceShader" { ?? ?//ShaderLab语法中不需要加分号 ?? ?Properties { ?? ?//属性名(面板显示名称,类型)=默认值 ?? ??? ?_FloatValue("一个浮点数",float)=1 ?? ?} ?? ?SubShader { ?? ??? ?pass ?? ??? ?{ ?? ??? ? ?? ??? ?} ?? ?} ?? ?FallBack "Diffuse" }

Shader "Custom/NewSurfaceShader" { ?? ?//ShaderLab语法中不需要加分号,初值一定要给 ?? ?Properties { ?? ?//属性名(面板显示名称,类型)=默认值 ?? ??? ?_FloatValue("一个浮点数",float)=1 ?? ??? ?//*** ?? ??? ?_RangeValue("一个范围浮点数",Range(1,100))=50 ?? ??? ?_VectorValue("一个四维数",Vector)=(1,1,1,1) ?? ??? ?//*** ?? ??? ?_ColorValue("一个颜色值",Color)=(1,0,0,1) ?? ??? ?//*** ?? ??? ?_Texture2D("一个二阶贴图",2D)="red"{} ?? ??? ?_TextureRect("一个非2阶贴图",Rect)=""{} ?? ??? ?_TextureCube("一个立方体贴图",Cube)=""{}
?? ?} ?? ?SubShader { ?? ??? ?pass ?? ??? ?{ ?? ??? ? ?? ??? ?} ?? ?} ?? ?FallBack "Diffuse" }


//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed002" { ?? ?Properties { ?? ??? ?_MainColor("颜色值",Color)=(1,0,0,1) ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ??? ?_AmbientColor("环境光颜色值",Color)=(1,1,1,1) ?? ??? ?_SpecularColor("镜面反射颜色",Color)=(1,1,1,1) ?? ??? ?_Shininess("光泽度",Range(0.02,1))=0.5 ?? ??? ?_EmissionColor("自发光颜色",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//开启顶点光照 ?? ??? ??? ?Lighting On ?? ??? ??? ?//开启镜面反射开关 ?? ??? ??? ?SeparateSpecular On ?? ??? ??? ?Material{ ?? ??? ??? ?//固定漫反射 ?? ??? ??? ?//Diffuse(0,1,0,0) ?? ??? ??? ?//可变漫反射颜色[偏暗] ?? ??? ??? ?Diffuse[_DiffuseColor] ?? ??? ??? ?//可变环境光颜色 ?? ??? ??? ?Ambient[_AmbientColor] ?? ??? ??? ?//可变镜面反射光颜色 ?? ??? ??? ?Specular[_SpecularColor] ?? ??? ??? ?//光泽度设置 ?? ??? ??? ?Shininess[_Shininess] ?? ??? ??? ?//自发光 ?? ??? ??? ?Emission[_EmissionColor] ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?FallBack "Diffuse" }

//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed003" { ?? ?Properties { ?? ??? ?_DiffuseFrontColor("正面漫反射颜色值",Color)=(1,0,0,1) ?? ??? ?_DiffuseBackColor("反面漫反射颜色值",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//开启顶点光照 ?? ??? ??? ?Lighting On ?? ??? ??? ?//剔除背面 ?? ??? ??? ?Cull Back ?? ??? ??? ?Material{ ?? ??? ??? ??? ?Diffuse[_DiffuseFrontColor] ?? ??? ??? ?} ?? ??? ?} ?? ??? ?Pass{ ?? ??? ??? ?//剔除正面,渲染北美 ?? ??? ??? ?Cull Front ?? ??? ??? ?//开启顶点光照 ?? ??? ??? ?Lighting On ?? ??? ??? ?Material{ ?? ??? ??? ??? ?Diffuse[_DiffuseBackColor] ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?FallBack "Diffuse" }

?p149-3:18
//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed004" { ?? ?Properties { ?? ??? ? ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//进行深度检测,当前像素的深度大于缓存里的深度 ?? ??? ??? ?//说明当前像素被挡在缓存像素后面 ?? ??? ??? ?//就是被挡住了,但依旧渲染颜色 ?? ??? ??? ?ZTest Greater ?? ??? ??? ?//关闭深度缓存 ?? ??? ??? ?ZWrite Off ?? ??? ??? ?//被挡住渲染该颜色 ?? ??? ??? ?Color(1,0,0,1) ?? ??? ?} ?? ??? ?Pass{ ?? ??? ??? ?//进行深度检测 ?? ??? ??? ?//被挡住渲染的颜色,当前像素的深度小于或等于缓存里的深度 ?? ??? ??? ?//说明当前像素不在缓存像素的后面 ?? ??? ??? ?//通俗来讲就是没被挡住 ?? ??? ??? ?ZTest LEqual
?? ??? ??? ?Color(0,0,1,1) ?? ??? ?} ?? ?} ?? ?FallBack "Diffuse" }


//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed005" { ?? ?Properties { ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//开启顶点光照 ?? ??? ??? ?Lighting On ?? ??? ??? ?//开启半透明混合 ?? ??? ??? ?Blend SrcAlpha OneMinusSrcAlpha ?? ??? ??? ?//各种混合 ?? ??? ??? ?//Blend One One ?? ??? ??? ? ?? ??? ??? ?Material{ ?? ??? ??? ??? ?Diffuse[_DiffuseColor] ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?} ?? ?FallBack "Diffuse" }

?

?
?链接:http://pan.baidu.com/s/1qYThKuS 密码:ripn

//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed008" { ?? ?Properties { ? ? ? ? _MainTex("纹理图片",2D)=""{} ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?Lighting On ?? ??? ??? ?Material{ ?? ??? ??? ??? ?Diffuse[_DiffuseColor] ?? ??? ??? ?} ?? ??? ??? ?//设置纹理 ?? ??? ??? ?SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//融合纹理和其他 ?? ??? ??? ??? ?//ComBine:融合命令 ?? ??? ??? ??? ?Combine texture+Primary ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?} ?? ?FallBack "Diffuse" }


?
//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed008" { ?? ?Properties { ?? ??? ?_MainTex("纹理图片",2D)=""{} ?? ??? ?_SeconTex("第二个纹理",2D)=""{} ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ??? ?_MainColor("颜色值",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?Lighting On ?? ??? ??? ?Material{ ?? ??? ??? ?Diffuse[_DiffuseColor] ?? ??? ??? ?} ?? ??? ??? ?//设置纹理 ?? ??? ??? ?/*SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//融合纹理和其他 ?? ??? ??? ??? ?//ComBine:融合命令 ?? ??? ??? ??? ?Combine texture+Primary ?? ??? ??? ?}*/ ?? ??? ??? ?SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?ConstantColor[_MainColor] ?? ??? ??? ??? ?//纹理的颜色与上面的固定颜色做混合 ?? ??? ??? ??? ?Combine texture*Constant Double ?? ??? ??? ?} ?? ??? ??? ?SetTexture[_SeconTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?Combine texture*Previous ?? ??? ??? ?}
?? ??? ?} ?? ??? ? ?? ?} ?? ?//FallBack "Diffuse" }
//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed009" { ?? ?Properties { ?? ??? ?_MainTex("纹理图片",2D)=""{} ?? ??? ?_SeconTex("第二个纹理",2D)=""{} ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ??? ?_MainColor("颜色值",Color)=(1,0,0,1) ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//设置纹理 ?? ??? ??? ?/*SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//融合纹理和其他 ?? ??? ??? ??? ?//ComBine:融合命令 ?? ??? ??? ??? ?Combine texture+Primary ?? ??? ??? ?}*/ ?? ??? ??? ?SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?ConstantColor[_MainColor] ?? ??? ??? ??? ?//纹理的颜色与上面的固定颜色做混合 ?? ??? ??? ??? ?Combine texture ?? ??? ??? ?} ?? ??? ??? ?SetTexture[_SeconTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?ConstantColor[_MainColor] ?? ??? ??? ??? ?// ? ? ?src1 ? ? src2 ? ? ? ? ?src3 ?? ??? ??? ??? ?Combine texture lerp(Constant) Previous ?? ??? ??? ?}
?? ??? ?} ?? ??? ? ?? ?} ?? ?//FallBack "Diffuse" }
重点
//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed009" { ?? ?Properties { ?? ??? ?_MainTex("纹理图片",2D)=""{} ?? ??? ?_SeconTex("第二个纹理",2D)=""{} ?? ??? ?_DiffuseColor("漫反射颜色值",Color)=(1,0,0,1) ?? ??? ?_MainColor("颜色值",Color)=(1,0,0,1) ?? ??? ?_LerpValue("插值比例",Range(0,1))=0 ?? ?} ?? ?SubShader { ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?//设置纹理 ?? ??? ??? ?/*SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//融合纹理和其他 ?? ??? ??? ??? ?//ComBine:融合命令 ?? ??? ??? ??? ?Combine texture+Primary ?? ??? ??? ?}*/ ?? ??? ??? ?SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?ConstantColor[_MainColor] ?? ??? ??? ??? ?//纹理的颜色与上面的固定颜色做混合 ?? ??? ??? ??? ?Combine texture ?? ??? ??? ?} ?? ??? ??? ?SetTexture[_SeconTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//ConstantColor[_MainColor] ?? ??? ??? ??? ?ConstantColor(0,0,0,[_LerpValue]) ?? ??? ??? ??? ?// ? ? ?src1 ? ? src2 ? ? ? ? ?src3 ?? ??? ??? ??? ?Combine texture lerp(Constant) Previous ?? ??? ??? ?}
?? ??? ?} ?? ??? ? ?? ?} ?? ?//FallBack "Diffuse" }
C#代码,重点 发廊洗剪吹效果
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SetShaderProperties : MonoBehaviour { ? ? private MeshRenderer meshRenderer; ? ? private void Awake() ? ? { ? ? ? ? meshRenderer = GetComponent<MeshRenderer>(); ? ? } ? ? private void Update() ? ? { ? ? ? ? //获取此时材质中Shader中属性的值 ? ? ? ? float lerpValue=meshRenderer.material.GetFloat("_LerpValue"); ? ? ? ? lerpValue += Time.deltaTime/5; ? ? ? ? //设置材质中Shader属性的值 ? ? ? ? meshRenderer.material.SetFloat("_LerpValue", lerpValue); ? ? ? ? meshRenderer.material.SetTextureOffset("_SecondTex",new Vector2(Time.time,0)); ? ? } } ?

?溶解效果制作
//固定管线着色器【Shader1.0】__001 Shader "MyShader/FixedShader/Fixed010" { ?? ?Properties { ?? ??? ?_MainTex("纹理图片",2D)=""{} ?? ??? ?_TestValue("透明度测试值",Range(0,1))=0 ?? ?} ?? ?SubShader {?? ??? ? ?? ??? ?Pass ?? ??? ?{ ?? ??? ??? ?AlphaTest Greater [_TestValue] ?? ??? ??? ?SetTexture[_MainTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?ConstantColor[_MainColor] ?? ??? ??? ??? ?//纹理的颜色与上面的固定颜色做混合 ?? ??? ??? ??? ?Combine texture ?? ??? ??? ?} ?? ??? ??? ?SetTexture[_SecondTex] ?? ??? ??? ?{ ?? ??? ??? ??? ?//ConstantColor[_MainColor] ?? ??? ??? ??? ?ConstantColor(0,0,0,[_LerpValue]) ?? ??? ??? ??? ?// ? ? ?src1 ? ? src2 ? ? ? ? ?src3 ?? ??? ??? ??? ?Combine texture lerp(Constant) Previous ?? ??? ??? ?}
?? ??? ?} ?? ??? ? ?? ?} ?? ?//FallBack "Diffuse" }


?
|