当前位置:网站首页>Shadow implementation of unity vertex animation
Shadow implementation of unity vertex animation
2022-06-12 01:14:00 【Break The Sky】
Shader "Custom/Chapter11-Billboard" {
Properties
{
_MainTex("Main Tex",2D) = "White"{
}
_Color("Color Tint",Color) = (1,1,1,1)
_VerticalBillboarding("Vertical Restraints",Range(0,1)) = 1
}
SubShader
{
Tags {
"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "DisableBatching" = "True"}
pass
{
Tags {
"LightMode" = "ForwardBase"}
ZWrite off
Blend SrcAlpha OneMinusSrcAlpha
Cull off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
#include "unityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _VerticalBillboarding;
struct a2v
{
float4 vertex :POSITION;
float4 texcoord:TEXCOORD0;
};
struct v2f
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
//V2F_SHADOW_CASTER;
};
v2f vert(a2v v)
{
v2f o;
float3 center = float3(0,0,0);// Set the anchor of the billboard
float3 viewer =mul(_World2Object,float4(_WorldSpaceCameraPos,1));// Obtain the view coordinates in the model space
float3 normalDir = viewer-center;// According to the angle of view and the position of the anchor , Calculate the target normal direction
float3 upDir = abs(normalDir.y>0.999?float3(0,0,1):float3(0,1,0));// Calculate the upward direction , The premise is that it is not parallel to the normal direction ,
float3 rightDir = normalize(cross(upDir,normalDir));// Get the right direction according to the up direction and the normal direction
upDir = normalize(cross(normalDir,rightDir));// According to the right direction and the normal direction, the upward defense line is obtained
float3 centerOffs = v.vertex.xyz-center;// Calculate the offset between the current vertex and the anchor
// Update model coordinates
float3 localPos = center+rightDir*centerOffs.x+upDir*centerOffs.y+normalDir*centerOffs.z;
// Model space coordinates are converted to coordinates in clipping space
o.pos = mul(UNITY_MATRIX_MVP,float4(localPos,1));
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
//TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
return o;
}
fixed4 frag(v2f i):SV_TARGET
{
fixed4 c = tex2D(_MainTex,i.uv);
c.rgb*=_Color.rgb;
//SHADOW_CASTER_FRAGMENT(i);
return c;
}
ENDCG
}
Pass {
Tags {
"LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _VerticalBillboarding;
struct v2f {
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert(appdata_base v) {
v2f o;
float4 offset;
o.uv=TRANSFORM_TEX(v.texcoord,_MainTex);
float3 center = float3(0,0,0);// Set the anchor of the billboard
float3 viewer =mul(_World2Object,float4(_WorldSpaceCameraPos,1));// Obtain the view coordinates in the model space
float3 normalDir = viewer-center;// According to the angle of view and the position of the anchor , Calculate the target normal direction
float3 upDir = abs(normalDir.y>0.999?float3(0,0,1):float3(0,1,0));// Calculate the upward direction , The premise is that it is not parallel to the normal direction ,
float3 rightDir = normalize(cross(upDir,normalDir));// Get the right direction according to the up direction and the normal direction
upDir = normalize(cross(normalDir,rightDir));// According to the right direction and the normal direction, the upward defense line is obtained
float3 centerOffs = v.vertex.xyz-center;// Calculate the offset between the current vertex and the anchor
// Update model coordinates
float3 localPos = center+rightDir*centerOffs.x+upDir*centerOffs.y+normalDir*centerOffs.z;
// Model space coordinates are converted to coordinates in clipping space
//TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
o.pos = mul(UNITY_MATRIX_MVP,float4(localPos,1));
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed4 tex=tex2D(_MainTex,i.uv);
if(tex.a<0.5){
discard;
}
SHADOW_CASTER_FRAGMENT(i);
}
ENDCG
}
}
Fallback "VertexLit"
}
边栏推荐
- Lambda快速入门
- In the field of enabling finance, the transformation of state secrets makes security compliance more solid
- Some suggestions on writing code to reproduce the paper!
- Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
- Nat. Comm. | supercomputing +ai: providing navigation for natural product biosynthesis route planning
- Websocket server practice
- Global and Chinese medical styrene block copolymer industry prospect research and investment planning proposal report 2022-2028
- Such a change in people's understanding of the industrial Internet is not achieved overnight
- I worked as a software testing engineer in a large factory and wrote "one day's complete workflow"
- DevOps落地实践点滴和踩坑记录-(1)
猜你喜欢

In depth description of Weibull distribution (1) principle and formula

System. Commandline option

【项目实训】微信公众号获取用户openid

Before applying data warehouse ODBC, you need to understand these problems first

Make good use of these 28 tools, and the development efficiency soars

New knowledge: monkey improved app crawler

MATLAB basic application 02 wind stock data introduction and use case:

Comparison of OpenCV basic codes of ros2 foxy~galactic~humble

flowable 工作流

Weekly CTF 第一周:神奇的磁带
随机推荐
Practice of Flink CDC + Hudi massive data entering the lake in SF
In depth description of Weibull distribution (2) meaning of parameters and formulas
Interpretation of the guiding opinions on the digital transformation of banking and insurance industry by Analysys analysis
Article 7: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [module device selection, list and data]
Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
Big sword
我在某大厂做软件测试工程师的《一天完整工作流程》
Three times a day (in serial...)
[answer] business use cases and system use cases are mixed together
Article 3: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [defense ppt]
System.CommandLine选项Option
MATLAB basic application 02 wind stock data introduction and use case:
只会基础的功能测试的我,被炒鱿鱼了····
Lambda中间操作distinct
jvm: 线程上下文类加载器(TheadContextClassLoader)
JMeter operation process that can be understood at a glance
Crawler case 05 - parsing websites using XPath
I'm fired because I can only test basic functions····
中创专利|中国5G标准必要专利达1.8万项,尊重知识产权,共建知识产权强国
[answer] what does UML use to represent hexagonal architecture