-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDepthScanEffectMotif.shader
106 lines (90 loc) · 3.37 KB
/
DepthScanEffectMotif.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Shader "Meta/DepthScanEffectMotif"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (0, 0, 1, 1)
_Girth ("Girth", float) = 0.4
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Cull Off
ZWRITE Off
LOD 100
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ HARD_OCCLUSION SOFT_OCCLUSION
#include "UnityCG.cginc"
#include "Packages/com.meta.xr.sdk.core/Shaders/EnvironmentDepth/BiRP/EnvironmentOcclusionBiRP.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 posWorld : TEXCOORD1;
float4 color : COLOR0;
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Girth;
v2f vert (appdata v)
{
v2f output;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.vertex = UnityObjectToClipPos(v.vertex.xyz);
META_DEPTH_INITIALIZE_VERTEX_OUTPUT(output, v.vertex)
output.color = v.color;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
return output;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 col = _Color;
col *= i.color;
float virtualSceneDepth = length(i.posWorld - _WorldSpaceCameraPos);
const float4 depthSpace =
mul(_EnvironmentDepthReprojectionMatrices[unity_StereoEyeIndex], float4(i.posWorld, 1.0));
const float2 uvCoords = (depthSpace.xy / depthSpace.w + 1.0f) * 0.5f;
float environmentDepth = SampleEnvironmentDepthLinear(uvCoords);
col *= (1 - (clamp(abs(environmentDepth - virtualSceneDepth), 0.0f, _Girth) / _Girth));
if(abs(environmentDepth - virtualSceneDepth) > _Girth)
discard;
return col;
}
ENDHLSL
}
}
}