当前位置:网站首页>[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 1: Introduction
- JS pull down the curtain JS special effect display layer
- Win11C盘满了怎么清理?Win11清理C盘的方法
- How to clean when win11 C disk is full? Win11 method of cleaning C disk
- Summary of debian10 system problems
- 2021年全国平均工资出炉,你达标了吗?
- Download, installation and development environment construction of "harmonyos" deveco
- Chapter 1 Introduction to CRM core business
- 五种网络IO模型
- 讨论| 坦白局,工业 AR 应用为什么难落地?
猜你喜欢
Wireshark analyzes packet capture data * cap
Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
What skills can you master to be a "master tester" when doing software testing?
A few simple steps to teach you how to see the K-line diagram
How to clean when win11 C disk is full? Win11 method of cleaning C disk
< code random recording two brushes> linked list
In depth understanding of USB communication protocol
海量数据去重的hash,bitmap与布隆过滤器Bloom Filter
Discuss | frankly, why is it difficult to implement industrial AR applications?
Improve application security through nonce field of play integrity API
随机推荐
Tips for this week 131: special member functions and ` = Default`
Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
< code random recording two brushes> linked list
Performance test process and plan
上市十天就下线过万台,欧尚Z6产品实力备受点赞
golang 客户端服务端登录
直播软件搭建,canvas文字加粗
万字保姆级长文——Linkedin元数据管理平台Datahub离线安装指南
PHP面试题 foreach($arr as &$value)与foreach($arr as $value)的用法
[paper sharing] where's crypto?
【demo】循环队列及条件锁实现goroutine间的通信
In depth understanding of USB communication protocol
通过 Play Integrity API 的 nonce 字段提高应用安全性
Yunjing network technology interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Wireshark analyzes packet capture data * cap
socket编程之常用api介绍与socket、select、poll、epoll高并发服务器模型代码实现
[principles and technologies of network attack and Defense] Chapter 5: denial of service attack
More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised
Is it safe to open an online futures account now? How many regular futures companies are there in China?
手撕Nacos源码(先撕客户端源码)