-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDepthLookingGlassMotif.shader
111 lines (96 loc) · 4.01 KB
/
DepthLookingGlassMotif.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
107
108
109
110
111
/*
* 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/DepthLookingGlassMotif"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_StartColor ("Start Color", Color) = (0, 0, 1, 1)
_EndColor ("End Color", Color) = (0, 1, 0, 1)
}
SubShader
{
Tags
{
"Queue"="AlphaTest-1"
}
LOD 100
Pass
{
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Packages/com.meta.xr.sdk.core/Shaders/EnvironmentDepth/BiRP/EnvironmentOcclusionBiRP.cginc"
struct Attributes
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Interpolators
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 posWorld : TEXCOORD1;
float4 grabPos : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _StartColor;
float4 _EndColor;
uniform float4 _CameraDepthTexture_TexelSize;
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
Interpolators vert(Attributes v)
{
Interpolators o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(Interpolators, o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.posWorld = mul(unity_ObjectToWorld, v.vertex).xyz;
o.grabPos = ComputeGrabScreenPos(o.vertex);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
return o;
}
float invLerp(float from, float to, float value)
{
return (value - from) / (to - from);
}
fixed4 frag(Interpolators i) : SV_Target {
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float2 screenPosUV = i.grabPos.xy / i.grabPos.w;
// screenPosUV.y = 1.0f - screenPosUV.y; // uncomment for BiRP
float virtualLinearDepth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,screenPosUV));
const float4 depthSpace = mul(_EnvironmentDepthReprojectionMatrices[unity_StereoEyeIndex], float4(i.posWorld, 1.0));
const float3 uv = float3(depthSpace.xy / depthSpace.w * 0.5f + 0.5f, unity_StereoEyeIndex);
const float inputDepthEye = _EnvironmentDepthTexture.Sample(sampler_EnvironmentDepthTexture, uv).r;
const float inputDepthNdc = inputDepthEye * 2.0 - 1.0;
float envLinearDepth = 1.0f / (inputDepthNdc + _EnvironmentDepthZBufferParams.y) * _EnvironmentDepthZBufferParams.x;
float linearDepth = min(envLinearDepth, virtualLinearDepth);
const float remapped = invLerp(0.3, 7.0, linearDepth);
fixed4 col = lerp(_StartColor, _EndColor, remapped);
col.a = 1;
return col;
}
ENDCG
}
}
}