当前位置:网站首页>[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
2022-07-07 18:26:00 【InfoQ】
Realization effect :

branch Pass Rendering :
- Perspective effect Pass, Use... When rendering ZTest Greater, The first rendering is the front occlusion Cube, At this time, there is Cube Depth value of . Then render the model , The depth test of the uncovered part of the model fails , Does not render , The occluded part passed the depth test , Normal display .
- Normal rendering Pass, The first rendering is the front occlusion Cube, At this time, there is Cube Depth value of . Then render the model , The depth test of the occluded part of the model failed , Does not render , The unobstructed part is displayed normally .
- ZTest Less: If the depth is less than the current cache, pass
- ZTest Greater: If the depth is greater than the current cache, pass
- ZTest LEqual: If the depth is less than or equal to the current cache, it passes
- ZTest GEqual: If the depth is greater than or equal to the current cache, it passes through
- ZTest Equal: If the depth is equal to the current cache
- ZTest NotEqual: If the depth is not equal to the current cache, pass
- ZTest Always: Pass anyway
Shader Code :
// primary Pass unchanged , Insert a Pass, Used to display the occluded part of the model
Shader "Test/Model_XRay"
{
Properties
{
_MainTex ("Diffuse (RGB)", 2D) = "grey" {}
_Color("Color (RGBA)", Color) = (1,1,1,1)
_XRayColor("XRay Color", Color) = (1,1,1,1)
}
SubShader
{
Tags
{
"RenderType"="Opaque"
"Queue"="AlphaTest+1"
"IgnoreProjector"="True"
}
LOD 200
Fog { Mode Off }
// Rendering X Perspective effect Pass
Pass
{
Blend SrcAlpha One
ZWrite Off
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _XRayColor;
struct v2f
{
float4 pos : SV_POSITION;
float3 normal : normal;
float3 viewDir : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.viewDir = ObjSpaceViewDir(v.vertex); // Calculate the vector from vertex to camera
o.normal = v.normal;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// Calculate the color concentration by using the dot multiplication value of the normal and the line of sight vector
float3 normal = normalize(i.normal);
float3 viewDir = normalize(i.viewDir);
float rim = 1 - dot(normal, viewDir);
return _XRayColor * rim;
}
ENDCG
}
Pass
{
CGPROGRAM
// Defining vertices / Chip shader code
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
// Define the input of the vertex shader
struct a2v
{
float4 vertex : POSITION;
float2 uv :TEXCOORD0;
};
// Define the output of vertex shaders 、 Input of the slice shader
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return tex2D(_MainTex,i.uv);
}
ENDCG
}
}
FallBack "Diffuse"
}边栏推荐
- [principle and technology of network attack and Defense] Chapter 7: password attack technology Chapter 8: network monitoring technology
- 小试牛刀之NunJucks模板引擎
- PHP面试题 foreach($arr as &$value)与foreach($arr as $value)的用法
- 科学家首次观察到“电子漩涡” 有助于设计出更高效的电子产品
- 开发一个小程序商城需要多少钱?
- 用存储过程、定时器、触发器来解决数据分析问题
- ICer知识点杂烩(后附大量题目,持续更新中)
- [demo] circular queue and conditional lock realize the communication between goroutines
- 2021年全国平均工资出炉,你达标了吗?
- Five simple ways to troubleshoot with Stace
猜你喜欢
![[tpm2.0 principle and Application guide] Chapter 5, 7 and 8](/img/38/93fd986916193803bbd90805f832fa.png)
[tpm2.0 principle and Application guide] Chapter 5, 7 and 8
![[principle and technology of network attack and Defense] Chapter 6: Trojan horse](/img/2f/bd35ca141fad5c85f78fd6340ada1d.png)
[principle and technology of network attack and Defense] Chapter 6: Trojan horse

Performance test process and plan

Taffydb open source JS database

回归测试的分类

CVPR 2022丨学习用于小样本语义分割的非目标知识
![[answer] if the app is in the foreground, the activity will not be recycled?](/img/b7/a749d7220c22f92080b71fd3859b8d.png)
[answer] if the app is in the foreground, the activity will not be recycled?

More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised

Datasimba launched wechat applet, and datanuza accepted the test of the whole scene| StartDT Hackathon

Wireshark analyzes packet capture data * cap
随机推荐
golang 客户端服务端登录
财富证券证券怎么开户?通过链接办理股票开户安全吗
Easy to understand [linear regression of machine learning]
AntiSamy:防 XSS 攻击的一种解决方案使用教程
Do you really understand sticky bag and half bag? 3 minutes to understand it
Debian10 compile and install MySQL
Cf:c. factors and powers of two [DP + sort + Select Board + select several numbers equal to the minimum number of known sums]
In depth understanding of USB communication protocol
2022年理财有哪些产品?哪些适合新手?
Management by objectives [14 of management]
[network attack and defense principle and technology] Chapter 4: network scanning technology
JS pull down the curtain JS special effect display layer
AI defeated mankind and designed a better economic mechanism
“解密”华为机器视觉军团:华为向上,产业向前
List selection JS effect with animation
你真的理解粘包与半包吗?3分钟搞懂它
[principles and technologies of network attack and Defense] Chapter 5: denial of service attack
debian10系统问题总结
[trusted computing] Lesson 13: TPM extended authorization and key management
[demo] circular queue and conditional lock realize the communication between goroutines