当前位置:网站首页>[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"
}
边栏推荐
- 回归问题的评价指标和重要知识点总结
- Cf:c. factors and powers of two [DP + sort + Select Board + select several numbers equal to the minimum number of known sums]
- 线程池和单例模式以及文件操作
- 体总:安全有序恢复线下体育赛事,力争做到国内赛事应办尽办
- Chapter 3 business function development (safe exit)
- [trusted computing] Lesson 12: TPM authorization and conversation
- socket编程之常用api介绍与socket、select、poll、epoll高并发服务器模型代码实现
- 云景网络科技面试题【杭州多测师】【杭州多测师_王sir】
- Understanding of 12 methods of enterprise management
- sqlite sql 异常 near “with“: syntax error
猜你喜欢
Explain it in simple terms. CNN convolutional neural network
Chapter 3 business function development (to remember account and password)
用存储过程、定时器、触发器来解决数据分析问题
讨论| 坦白局,工业 AR 应用为什么难落地?
DataSimba推出微信小程序,DataNuza接受全场景考验? | StartDT Hackathon
Skills of embedded C language program debugging and macro use
[paper sharing] where's crypto?
[PaddleSeg源码阅读] PaddleSeg Validation 中添加 Boundary IoU的计算(1)——val.py文件细节提示
Chapter 2 building CRM project development environment (building development environment)
socket編程之常用api介紹與socket、select、poll、epoll高並發服務器模型代碼實現
随机推荐
zdog. JS rocket turn animation JS special effects
Click on the top of today's headline app to navigate in the middle
Taffydb open source JS database
Afghan interim government security forces launched military operations against a hideout of the extremist organization "Islamic state"
Mobile app takeout ordering personal center page
数学分析_笔记_第11章:Fourier级数
[demo] circular queue and conditional lock realize the communication between goroutines
Understanding of 12 methods of enterprise management
2022年理财有哪些产品?哪些适合新手?
AntiSamy:防 XSS 攻击的一种解决方案使用教程
Tips of the week 136: unordered containers
List selection JS effect with animation
“解密”华为机器视觉军团:华为向上,产业向前
持续测试(CT)实战经验分享
低代码助力企业数字化转型会让程序员失业?
< code random recording two brushes> linked list
【蓝桥杯集训100题】scratch从小到大排序 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第17题
Kubernetes DevOps CD工具对比选型
String type, constant type and container type of go language
行业案例|数字化经营底座助力寿险行业转型