当前位置:网站首页>[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 6: Trojan horse
- Chapter 1 Introduction to CRM core business
- Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
- A few simple steps to teach you how to see the K-line diagram
- Chapter 3 business function development (safe exit)
- Wireshark分析抓包数据*.cap
- Chapter 2 building CRM project development environment (building development environment)
- Tips for short-term operation of spot silver that cannot be ignored
- Backup Alibaba cloud instance OSS browser
猜你喜欢

socket编程之常用api介绍与socket、select、poll、epoll高并发服务器模型代码实现

Discuss | what preparations should be made before ar application is launched?

Nunjuks template engine

线程池和单例模式以及文件操作

Chapter 2 build CRM project development environment (database design)
![[4500 word summary] a complete set of skills that a software testing engineer needs to master](/img/82/acae52928b3ab48e9ecbf4ec436e5e.jpg)
[4500 word summary] a complete set of skills that a software testing engineer needs to master

『HarmonyOS』DevEco的下载安装与开发环境搭建

回归测试的分类

Skills of embedded C language program debugging and macro use

元宇宙带来的创意性改变
随机推荐
Discuss | what preparations should be made before ar application is launched?
Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
Interviewer: why is the page too laggy and how to solve it? [test interview question sharing]
CVPR 2022丨学习用于小样本语义分割的非目标知识
4种常见的缓存模式,你都知道吗?
回归问题的评价指标和重要知识点总结
保证接口数据安全的10种方案
[network attack and defense principle and technology] Chapter 4: network scanning technology
ICer知识点杂烩(后附大量题目,持续更新中)
Hash, bitmap and bloom filter for mass data De duplication
“解密”华为机器视觉军团:华为向上,产业向前
[principle and technology of network attack and Defense] Chapter 6: Trojan horse
AI 击败了人类,设计了更好的经济机制
Hutool - 轻量级 DB 操作解决方案
磁盘存储链式的B树与B+树
Tips of the week 136: unordered containers
String type, constant type and container type of go language
备份阿里云实例-oss-browser
Download, installation and development environment construction of "harmonyos" deveco
List selection JS effect with animation