//第一种
Shader "VRShader/BaseSurfaceShader"
{
Properties
{
_Color("Color",Color)=(0,1,1,1)
}
SubShader
{
CGPROGRAM //CG语言开始
//编译指令 surface表示下面要写的时表面着色器
//surf是该表面着色器的方法名称
//Lambert是光照模型
#pragma surface surf Lambert alpha
struct Input
{
float4 color:COLOR;
};
//定义属性中的_Color
float4 _Color;
//表面着色器方法
void surf(Input IN,inout SurfaceOutput o)
{
//o.Albedo=float3(1,1,0);
o.Albedo=_Color.rgb;//设置颜色RGB
o.Alpha=_Color.a;//设置透明度A
}
ENDCG //CG语言结束
}
}
//第二种
Shader "VRShader/BumpMapSurfaceShader"
{
Properties
{
_MainTex("纹理贴图",2D)=""{}
_BumpTex("凹凸贴图",2D)=""{}
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;//凹凸纹理的uv
};
sampler2D _MainTex;
sampler2D _BumpTex;
void surf(Input IN,inout SurfaceOutput o)
{
//设置纹理
o.Albedo=tex2D(_MainTex,IN.uv_MainTex).rgb;
//设置法线
o.Normal=UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
}
ENDCG
}
}
//第三种
Shader "VRShader/DetailTextureShader"
{
Properties
{
_Color("MainColor",color)=(1,1,1,1)//主颜色
_MainTex("MainTexture",2D)=""{}//主纹理
_BumpTex("BumpTexture",2D)=""{}//法线贴图
_DetailTex("DetailTexture",2D)=""{}//细节纹理
_RimColor("RimColor",color)=(1,1,1,1)//边缘发光颜色
_RimPower("RimPower",Range(0,1))=1//边缘发光强度
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert finalcolor:setcolor
//变量声明
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpTex;
sampler2D _DetailTex;
float4 _RimColor;
float _RimPower;
//
struct Input
{
float2 uv_MainTex;//主纹理uv
float2 uv_BumpTex;//法线纹理uv
float2 uv_DetailTex;//细节纹理uv
float3 viewDir;//视线方向向量
};
//颜色设置方法
void setcolor(Input IN,SurfaceOutput o,inout fixed4 color)
{
color*=_Color;
}
//表面着色器方法
void surf(Input IN,inout SurfaceOutput o)
{
o.Albedo=tex2D(_MainTex,IN.uv_MainTex).rgb;
//细节纹理添加
o.Albedo*=tex2D(_DetailTex,IN.uv_DetailTex).rgb*2;
o.Normal=UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
half rim=1-saturate(dot(normalize(IN.viewDir),o.Normal));
o.Emission=_RimColor*pow(rim,_RimPower);
}
ENDCG
}
}
//第四种
Shader "VRShader/SetTextureSurfaceShader"
{
Properties
{
_MainTexture("MainTexture",2D)=""{}
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input
{
float2 uv_MainTexture;//uv坐标
};
//定义纹理
sampler2D _MainTexture;
void surf(Input IN,inout SurfaceOutput o)
{
o.Albedo=tex2D(_MainTexture,IN.uv_MainTexture).rgb;
o.Alpha=1;
}
ENDCG
}
}
//第五种
Shader "VRShader/Texture&Color&Normal"
{
Properties
{
_Color("主颜色",Color)=(1,1,1,1)
_MainTex("主纹理",2D)=""{}
_BumpTex("凹凸纹理",2D)=""{}
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert
//变量声明
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpTex;
//定义输入结构体
struct Input
{
float4 color:COLOR;
float2 uv_MainTex;
float2 uv_BumpTex;
};
void surf(Input IN,inout SurfaceOutput o)
{
o.Albedo=tex2D(_MainTex,IN.uv_MainTex).rgb;
o.Albedo+=_Color;
o.Normal=UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
}
ENDCG
}
}
//第六种
Shader "VRShader/Texture&Color&Normal&New"
{
Properties
{
_Color("Color",Color)=(1,1,1,1)
_MainTex("MainTex",2D)=""{}
_BumpTex("BumpTex",2D)=""{}
}
SubShader
{
CGPROGRAM
//finalcolor:setcolor----预编制指令设置颜色方法setcolor
#pragma surface surf Lambert finalcolor:setcolor
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpTex;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;
};
void setcolor(Input IN,SurfaceOutput o,inout fixed4 color)
{
color*=_Color;
}
void surf(Input IN,inout SurfaceOutput o)
{
o.Albedo=tex2D(_MainTex,IN.uv_MainTex).rgb;
o.Normal=UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
}
ENDCG
}
}
//第七种
Shader "VRShader/Texture&Color&Normal&RimEmisssion"
{
Properties
{
_Color("Color",color)=(1,1,1,1)
_MainTex("MainTex",2D)=""{}
_BumpTex("BumpTex",2D)=""{}
_RimColor("RimColor",color)=(1,1,1,1)
_RimPower("RimPower",Range(1,10))=5
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert finalcolor:setcolor
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpTex;
float4 _RimColor;//发光颜色
float _RimPower;//发光强度
struct Input
{
float4 color:COLOR;
float2 uv_MainTex;
float2 uv_BumpTex;
float3 viewDir;//视线方向
};
void setcolor(Input IN,SurfaceOutput o,inout fixed4 color)
{
color*=_Color;
}
void surf(Input IN,inout SurfaceOutput o)
{
o.Albedo=tex2D(_MainTex,IN.uv_MainTex).rgb;
o.Normal=UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
//获取边缘值,越靠边缘,值越大
half rim=1-saturate(dot(normalize(IN.viewDir),o.Normal));
//设置边缘自发光
o.Emission=_RimColor*pow(rim,_RimPower);
}
ENDCG
}
}
Shader(表面着色器)
最新推荐文章于 2022-08-12 13:56:18 发布