首页 技术 正文
技术 2022年11月10日
0 收藏 759 点赞 2,266 浏览 1378 个字

Alpha Test的阴影,

shader如下:

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "Custom/Alpha Test Shadow"
{
Properties
{
_Color ("Main Color", Color) = (,,,) // 必需
_MainTex("Main Texture", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(,)) = 0.5 // 必需
} SubShader
{
Tags
{
"Queue" = "AlphaTest"
"RenderType" = "TransparentCutout"
} Pass
{
Tags
{
"LightMode" = "ForwardBase"
}
Cull Off // 背面 CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase #include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc" float4 _Color;
sampler2D _MainTex;
float _Cutoff; struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
}; struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldNormal : TEXCOORD1;
float3 worldPos : TEXCOORD2;
SHADOW_COORDS()
}; v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
TRANSFER_SHADOW(o);
return o;
} fixed4 frag(v2f i) : SV_TARGET
{
fixed4 albedo = tex2D(_MainTex, i.uv) * _Color; clip(albedo.a - _Cutoff); fixed3 ambient = albedo.rgb * UNITY_LIGHTMODEL_AMBIENT.rgb; float3 worldLight = UnityWorldSpaceLightDir(i.worldPos);
fixed3 diff = albedo.rgb * _LightColor0.rgb * max(, dot(i.worldNormal, worldLight)); UNITY_LIGHT_ATTENUATION(atten, i, i.worldPos); fixed3 col = ambient + diff * atten; return fixed4(col, );
} ENDCG
}
} Fallback "Transparent/Cutout/VertexLit" // 必需,阴影投射pass
}

效果如下:

Unity shader学习之Alpha Test的阴影

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902