Shader学习笔记2

这一篇就全是官方文档上我感觉有用的一些效果了。

这是一种加入天空盒的Shader,他会呈现出以下状态,他也可以放在人物模型上,有反光的感觉
注意: 如果需要加入发现贴图,在Input结构体里要加上INTERNAL_DATA(没分号)
Shader "MySurfaceShader/CubeMapShader" {
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
    //加入一个天空盒
     _Cube( "Cubemap" ,CUBE) = "" {}

}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
//Level of Detail
      LOD 200

CGPROGRAM
#pragma surface surf Lambert
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
    fixed3 worldRefl;
};

//2D在CG语言里面用sampler2D表示,sampler中文含义:采样
//Color在CG语言里面用fixed4表示
sampler2D _MainTexture;
samplerCUBE _Cube;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
o.Emission = texCUBE (_Cube,IN.worldRefl).rgb;
}
ENDCG
}

FallBack "DIFFUSE"
}


这个是边缘光的Shader

可以调节边缘光的颜色和强度
Shader"MySurfaceShader/HeroShader"{
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
     _BumpTex( "BumpTexture" , 2D ) = "bump" {}
     //边缘照明强调对象的边缘。(看上去像是边上一圈光)添加一些放射光基于曲面法线夹角和视图方向。
     _RimColor( "Rim Color" , Color ) = (0.26,0.19,0.16,0.0)
     _RimPower( "Rim Power" , Range (0.5,8.0))=3.0

}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
//Level of Detail
      LOD 200

CGPROGRAM
#pragma surface surf Lambert
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
    fixed2 uv_BumpTex;
    //使用viewDir内置表面着色器变量。
    fixed3 viewDir;
};

//2D在CG语言里面用sampler2D表示,sampler中文含义:采样
//Color在CG语言里面用fixed4表示
sampler2D _MainTexture;
sampler2D _BumpTex;
fixed4 _RimColor;
half _RimPower;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
o.Normal = UnpackNormal ( tex2D (_BumpTex,IN.uv_BumpTex));
half rim = 1.0 - saturate ( dot ( normalize (IN.viewDir),o.Normal));
o.Emission = _RimColor.rgb* pow (rim,_RimPower);
}
ENDCG
}

FallBack "DIFFUSE"
}



贴图细节Shader

效果就像屏幕上的脏东西,长得和贴图一样
Shader "MySurfaceShader/TextureDetailShader" {
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
     //细节处理,更真实,更立体
     _Detail( "Detail" , 2D )= "grey" {}
}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
//Level of Detail
      LOD 200

CGPROGRAM
#pragma surface surf Lambert
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
    //感觉像屏幕上的脏东西,长得和贴图一样
    fixed4 screenPos;

};

//2D在CG语言里面用sampler2D表示,sampler中文含义:采样
//Color在CG语言里面用fixed4表示
sampler2D _MainTexture;
sampler2D _Detail;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
fixed2 screenUV = IN.screenPos.xy/IN.screenPos.w;
screenUV *= fixed2 (8,6);
o.Albedo *= tex2D (_Detail,screenUV).rgb*2;


}
ENDCG
}

FallBack "DIFFUSE"
}
这是细节Shader,和上面的代码差别不大,但是效果还是有区别的。

就是在基础贴图上乘等于一张细节贴图,产生一种贴图融合的感觉
Shader "MySurfaceShader/DetailShader" {
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
     _BumpTex( "BumpTexture" , 2D ) = "bump" {}
     //细节处理,更真实,更立体
     _Detail( "Detail" , 2D )= "grey" {}
}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
//Level of Detail
      LOD 200

CGPROGRAM
#pragma surface surf Lambert
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
    fixed2 uv_BumpTex;
    fixed2 uv_Detail;

};

//2D在CG语言里面用sampler2D表示,sampler中文含义:采样
//Color在CG语言里面用fixed4表示
sampler2D _MainTexture;
sampler2D _BumpTex;
sampler2D _Detail;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
o.Albedo *= tex2D (_Detail,IN.uv_Detail).rgb*2;
o.Normal = UnpackNormal ( tex2D (_BumpTex,IN.uv_BumpTex));

}
ENDCG
}

FallBack "DIFFUSE"
}


卡通效果Shader

是对物体的定点进行修改,产生扩张和收缩的效果,扩张0.1,大概就像是卡通的样子(夸张)

Shader "MySurfaceShader/AmountShader" {
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
     //人物变粗变细,0是正常,0+是向外扩张,0-是向内收缩
     _Amount ( "Extrusion Amount" , Range (-1,1))= 0.5

}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
};
fixed _Amount;
void vert( inout appdata_full v){
v.vertex.xyz += v.normal*_Amount;
}


//2D在CG语言里面用sampler2D表示,sampler中文含义:采样
//Color在CG语言里面用fixed4表示
sampler2D _MainTexture;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
}
ENDCG
}

FallBack "DIFFUSE"
}
颜色修补Shader
这个Shader主要是surface中有finalcolor(Tint)的函数,是最后调用修补颜色用的
Shader "MySurfaceShader/TintShader" {
Properties {

     _MainTexture( "MainTexture" , 2D )= "white" {}
     //色彩(底色)
     _ColorTint( "Tint" , Color ) = (1.0,0.6,0.6,1.0)
}
SubShader {
//RenderType表示渲染模式,Opaque表示不透明物体
      Tags { "RenderType" = "Opaque" }
CGPROGRAM
//需要定义
#pragma surface surf Lambert finalcolor:mycolor
struct Input{
    //取得属性面板的纹理uv,用固定格式:uv变量名
    fixed2 uv_MainTexture;
};
fixed4 _ColorTint;

//颜色修补函数
void mycolor (Input IN , SurfaceOutput o, inout fixed4 color ){

color *= _ColorTint;
}


sampler2D _MainTexture;
void surf (Input IN , inout SurfaceOutput o){
//每个顶点的颜色,通过uv计算得到
o.Albedo = tex2D (_MainTexture,IN.uv_MainTexture).rgb;
}
ENDCG
}

FallBack "DIFFUSE"
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值