Shader学习笔记3
来源:互联网 发布:华为 acl 端口 编辑:程序博客网 时间:2024/05/31 19:42
上一篇发现太多了,在加一份:
深度Shader,被遮挡的物体透明变色
透明的写法:1.Tags{"RenderType"="Transparent" "Queue"= "Transparent"}
2.在光照模型后面加上alpha(非大写A)
3.在surf中给o.Alpha赋值
Shader"Custom/ZTestShader"{
Properties{
_Color ("Color",Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)",2D) ="white"{}
}
SubShader{
Tags{"RenderType"="Transparent""Queue"="Transparent"}
LOD200
//如果没有遮挡 (和其他物体深度相等)
ZTestLEqual
CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha
#pragma target 3.0
sampler2D_MainTex;
structInput {
float2uv_MainTex;
};
fixed4_Color;
voidsurf (InputIN,inoutSurfaceOutputStandard o) {
fixed4c =tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
//如果被遮挡住了(深度大于遮挡物体)
ZTestGreater
CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha
#pragma target 3.0
sampler2D_MainTex;
structInput {
float2uv_MainTex;
};
fixed4_Color;
voidsurf (InputIN,inoutSurfaceOutputStandard o) {
fixed4c =tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo =fixed3(1,1,0);
o.Alpha = 0.1;
}
ENDCG
}
FallBack"Diffuse"
}
溶解效果Shader
溶解效果Shader
Shader"Dissolve/Dissolve_TexturCoords"{
Properties{
_Color ("主颜色",Color) = (1,1,1,1)// 主色
_MainTex ("模型贴图",2D) ="white"{}// 主材质
_DissolveText ("溶解贴图",2D) ="white"{}// 溶解贴图
_Tile("溶解贴图的平铺大小",Range(0, 1)) = 1// 平铺值,设置溶解贴图大小
_Amount ("溶解值",Range(0, 1)) = 0.5// 溶解度
_DissSize("溶解大小",Range(0, 1)) = 0.1// 溶解范围大小
_DissColor ("溶解主色",Color) = (1,1,1,1)// 溶解颜色
_AddColor ("叠加色,与主色叠加为开始色[R|G|B>0表示启用]",Color) = (1,1,1,1)// 改色与溶解色融合形成开始色
}
SubShader{
Tags{"RenderType"="Opaque"}
LOD200
Culloff
CGPROGRAM
#pragma target 3.0
#pragma surface surf BlinnPhong
sampler2D_MainTex;
sampler2D_DissolveText;
fixed4_Color;// 主色
half_Tile;// 平铺值
half_Amount;// 溶解度
half_DissSize;// 溶解范围
half4_DissColor;// 溶解颜色
half4_AddColor;// 叠加色
// 最终色
statichalf3finalColor =float3(1,1,1);
structInput {
float2uv_MainTex;// 只需要主材质的UV信息
};
voidsurf (InputIN,inoutSurfaceOutputo) {
// 对主材质进行采样
fixed4tex =tex2D(_MainTex, IN.uv_MainTex);
// 设置主材质和颜色
o.Albedo = tex.rgb * _Color.rgb;
// 对裁剪材质进行采样,取R色值
floatClipTex =tex2D(_DissolveText, IN.uv_MainTex/_Tile).r;
// 裁剪量 = 裁剪材质R - 外部设置量
floatClipAmount = ClipTex - _Amount;
if(_Amount > 0)
{
// 如果裁剪材质的R色值 < 设置的裁剪值 那么此点将被裁剪
if(ClipAmount < 0)
{
//如果输入向量中的值小于1 ,丢弃此向量
clip(-0.1);
}
// 然后处理没有被裁剪的值
else
{
// 针对没有被裁剪的点,【裁剪量】小于【裁剪大小】的做处理
// 如果设置了叠加色,那么该色为ClipAmount/_DissSize(这样会形成渐变效果)
if(ClipAmount < _DissSize)
{
if(_AddColor.x == 0)
finalColor.x = _DissColor.x;
else
finalColor.x = ClipAmount/_DissSize;
if(_AddColor.y == 0)
finalColor.y = _DissColor.y;
else
finalColor.y = ClipAmount/_DissSize;
if(_AddColor.z == 0)
finalColor.z = _DissColor.z;
else
finalColor.z = ClipAmount/_DissSize;
// 融合
o.Albedo = o.Albedo * finalColor * 2;
}
}
}
o.Alpha = tex.a * _Color.a;
}
ENDCG
}//endsubshader
}
附:溶解贴图网上有
水流效果Shader
水流效果Shader
Shader"Custom/waterShader"
{
//------------------------------------【属性值】------------------------------------
Properties
{
//主纹理
_MainTex ("Albedo (RGB)",2D) ="white"{}
//左右偏移量和流动速度
_XScorllSpeed("XScorllSpeed",Range(0,1))=0
_YScorllSpeed("YScorllSpeed",Range(0,1))=0
}
SubShader
{
Tags{"RenderType"="Opaque"}
LOD200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
//编译指令: 指定着色器编译目标为Shader Model 3.0
#pragma target 3.0
//变量的声明
sampler2D_MainTex;
fixed_XScorllSpeed;
fixed_YScorllSpeed;
//表面输入结构
structInput
{
float2uv_MainTex;//纹理坐标
};
voidsurf(InputIN,inoutSurfaceOutputStandard o)
{
fixed2scrollUV = IN.uv_MainTex;
fixedXScorllSpeed = _XScorllSpeed*_Time;
fixedYScorllSpeed = _YScorllSpeed*_Time;
scrollUV+=fixed2(XScorllSpeed,YScorllSpeed);
fixed4c =tex2D(_MainTex, scrollUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
//备胎为漫反射
FallBack"Diffuse"
}
自定义光照模型,边缘光,卡通效果搭配使用(综合)Shader"MyShader/DavidShader"{
Properties{
_MainTex("Main Texture",2D) ="white"{}
_BumpTex("Bump Texture",2D) ="bump"{}
_Emission("Emission",Color) = (1,1,0,1)
IsEnter("IsEnter",int) = 0
_Amount("Amount",Range(-1,1))= 0
}
SubShader{
Tags{"RenderType"="Opaque"}
LOD200
CGPROGRAM
#pragma surface surf ZZW vertex:vert
#pragma target 3.0
//自定义光照模型,Output结构,光照方向,光照衰减度
half4LightingZZW(SurfaceOutputo,half3lightDir,halfatten){
//向量的点乘,光强度
half4NDot =dot(o.Normal,lightDir);
////这是半Lambert光照模型的公式,加亮
//NDot = NDot*0.5+0.5;
half4result ;
//_LightColor0光照颜色的影响,不乘就不收影响
result.rgb = o.Albedo*_LightColor0.rgb*(NDot*atten);
result.a = o.Alpha;
returnresult;
}
structInput{
fixed2uv_MainTex;
fixed2uv_BumpTex;
float3viewDir;//视角方向
};
fixed_Amount;
voidvert(inoutappdata_fullv){
v.vertex.xyz += v.normal*_Amount;
}
sampler2D_MainTex;
sampler2D_BumpTex;
fixed4_Emission;
fixedIsEnter;
voidsurf(InputIN,inoutSurfaceOutputo){
fixed4albedo =tex2D(_MainTex,IN.uv_MainTex);
o.Albedo = albedo.rgb;
fixed4normal =tex2D(_BumpTex,IN.uv_BumpTex);
o.Normal =UnpackNormal(normal);
if(IsEnter>0){
//将视角方向归一化
float3view =normalize(IN.viewDir);
//点乘
floatvalue =dot(view,o.Normal);
//限制在0,1之间
value = 1-saturate(value);
o.Emission = _Emission*value*value;
}
}
ENDCG
}
FallBack"Diffuse"
}
0 0
- Shader学习笔记3
- 风宇冲shader学习笔记
- unity3d shader 学习笔记
- Shader 学习笔记 20151031
- Shader 学习笔记 20151102
- Shader 学习笔记 20151103
- Shader 学习笔记 20151104
- Shader 学习笔记 20151105
- Shader 学习笔记 20151110
- Shader 学习笔记 20151112
- Shader 学习笔记 20151113
- Shader 学习笔记 20151121
- Shader 学习笔记 20151124
- Shader 学习笔记 20151201
- shader学习笔记二
- shader学习笔记一
- shader学习笔记三
- shader学习笔记三
- Material Design学习之 Snackbars
- 使用Spring AOP添加统计时间的功能
- 编程应用
- GameOverPlane飞入和飞出
- css负边距之详解
- Shader学习笔记3
- 直接插入排序
- IMYWebView 无缝切换 UIWebView 为 WKWebView
- 摆花
- Android开发学习之路--基于vitamio的视频播放器(一)
- 值传递和引用传递
- install alilang
- iOS 多线程(一)多线程基础
- CUDA学习--内存处理之共享内存(3)