A game about forced loneliness, made by TACStudios
1// UNITY_SHADER_NO_UPGRADE
2
3#ifndef BUILTIN_SHADER_VARIABLES_INCLUDED
4#define BUILTIN_SHADER_VARIABLES_INCLUDED
5
6#if defined(STEREO_INSTANCING_ON) && (defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN))
7#define UNITY_STEREO_INSTANCING_ENABLED
8#endif
9
10#if defined(STEREO_MULTIVIEW_ON) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_VULKAN)) && !(defined(SHADER_API_SWITCH))
11 #define UNITY_STEREO_MULTIVIEW_ENABLED
12#endif
13
14#if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
15#define USING_STEREO_MATRICES
16#endif
17
18#if defined(USING_STEREO_MATRICES)
19// Current pass transforms.
20#define glstate_matrix_projection unity_StereoMatrixP[unity_StereoEyeIndex] // goes through GL.GetGPUProjectionMatrix()
21#define unity_MatrixV unity_StereoMatrixV[unity_StereoEyeIndex]
22#define unity_MatrixInvV unity_StereoMatrixInvV[unity_StereoEyeIndex]
23#define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]
24#define unity_MatrixInvVP unity_StereoMatrixInvVP[unity_StereoEyeIndex]
25
26// Camera transform (but the same as pass transform for XR).
27#define unity_CameraProjection unity_StereoCameraProjection[unity_StereoEyeIndex] // Does not go through GL.GetGPUProjectionMatrix()
28#define unity_CameraInvProjection unity_StereoCameraInvProjection[unity_StereoEyeIndex]
29#define unity_WorldToCamera unity_StereoMatrixV[unity_StereoEyeIndex] // Should be unity_StereoWorldToCamera but no use-case in XR pass
30#define unity_CameraToWorld unity_StereoMatrixInvV[unity_StereoEyeIndex] // Should be unity_StereoCameraToWorld but no use-case in XR pass
31#define _WorldSpaceCameraPos unity_StereoWorldSpaceCameraPos[unity_StereoEyeIndex]
32#endif
33
34#define UNITY_LIGHTMODEL_AMBIENT (glstate_lightmodel_ambient * 2)
35
36// ----------------------------------------------------------------------------
37
38// Time (t = time since current level load) values from Unity
39float4 _Time; // (t/20, t, t*2, t*3)
40float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
41float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
42float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
43float4 _TimeParameters; // t, sin(t), cos(t)
44
45#if !defined(USING_STEREO_MATRICES)
46float3 _WorldSpaceCameraPos;
47#endif
48
49// x = 1 or -1 (-1 if projection is flipped)
50// y = near plane
51// z = far plane
52// w = 1/far plane
53float4 _ProjectionParams;
54
55// x = width
56// y = height
57// z = 1 + 1.0/width
58// w = 1 + 1.0/height
59float4 _ScreenParams;
60
61// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
62// x = 1-far/near
63// y = far/near
64// z = x/far
65// w = y/far
66// or in case of a reversed depth buffer (UNITY_REVERSED_Z is 1)
67// x = -1+far/near
68// y = 1
69// z = x/far
70// w = 1/far
71float4 _ZBufferParams;
72
73// x = orthographic camera's width
74// y = orthographic camera's height
75// z = unused
76// w = 1.0 if camera is ortho, 0.0 if perspective
77float4 unity_OrthoParams;
78
79// scaleBias.x = flipSign
80// scaleBias.y = scale
81// scaleBias.z = bias
82// scaleBias.w = unused
83uniform float4 _ScaleBias;
84uniform float4 _ScaleBiasRt;
85
86float4 unity_CameraWorldClipPlanes[6];
87
88#if !defined(USING_STEREO_MATRICES)
89// Projection matrices of the camera. Note that this might be different from projection matrix
90// that is set right now, e.g. while rendering shadows the matrices below are still the projection
91// of original camera.
92float4x4 unity_CameraProjection;
93float4x4 unity_CameraInvProjection;
94float4x4 unity_WorldToCamera;
95float4x4 unity_CameraToWorld;
96#endif
97
98// ----------------------------------------------------------------------------
99
100// Block Layout should be respected due to SRP Batcher
101CBUFFER_START(UnityPerDraw)
102// Space block Feature
103float4x4 unity_ObjectToWorld;
104float4x4 unity_WorldToObject;
105float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
106real4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
107
108// Light Indices block feature
109// These are set internally by the engine upon request by RendererConfiguration.
110real4 unity_LightData;
111real4 unity_LightIndices[2];
112
113float4 unity_ProbesOcclusion;
114
115// Reflection Probe 0 block feature
116// HDR environment map decode instructions
117real4 unity_SpecCube0_HDR;
118
119// Lightmap block feature
120float4 unity_LightmapST;
121float4 unity_LightmapIndex;
122float4 unity_DynamicLightmapST;
123
124// SH block feature
125real4 unity_SHAr;
126real4 unity_SHAg;
127real4 unity_SHAb;
128real4 unity_SHBr;
129real4 unity_SHBg;
130real4 unity_SHBb;
131real4 unity_SHC;
132CBUFFER_END
133
134#if defined(USING_STEREO_MATRICES)
135CBUFFER_START(UnityStereoViewBuffer)
136float4x4 unity_StereoMatrixP[2];
137float4x4 unity_StereoMatrixInvP[2];
138float4x4 unity_StereoMatrixV[2];
139float4x4 unity_StereoMatrixInvV[2];
140float4x4 unity_StereoMatrixVP[2];
141float4x4 unity_StereoMatrixInvVP[2];
142
143float4x4 unity_StereoCameraProjection[2];
144float4x4 unity_StereoCameraInvProjection[2];
145
146float3 unity_StereoWorldSpaceCameraPos[2];
147float4 unity_StereoScaleOffset[2];
148CBUFFER_END
149#endif
150
151#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) && defined(SHADER_STAGE_VERTEX)
152// OVR_multiview
153// In order to convey this info over the DX compiler, we wrap it into a cbuffer.
154#if !defined(UNITY_DECLARE_MULTIVIEW)
155#define UNITY_DECLARE_MULTIVIEW(number_of_views) CBUFFER_START(OVR_multiview) uint gl_ViewID; uint numViews_##number_of_views; CBUFFER_END
156#define UNITY_VIEWID gl_ViewID
157#endif
158#endif
159
160#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) && defined(SHADER_STAGE_VERTEX)
161#define unity_StereoEyeIndex UNITY_VIEWID
162UNITY_DECLARE_MULTIVIEW(2);
163#elif defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
164static uint unity_StereoEyeIndex;
165#elif defined(UNITY_SINGLE_PASS_STEREO)
166CBUFFER_START(UnityStereoEyeIndex)
167int unity_StereoEyeIndex;
168CBUFFER_END
169#endif
170
171float4x4 glstate_matrix_transpose_modelview0;
172
173// ----------------------------------------------------------------------------
174
175real4 glstate_lightmodel_ambient;
176real4 unity_AmbientSky;
177real4 unity_AmbientEquator;
178real4 unity_AmbientGround;
179real4 unity_IndirectSpecColor;
180float4 unity_FogParams;
181real4 unity_FogColor;
182
183#if !defined(USING_STEREO_MATRICES)
184float4x4 glstate_matrix_projection;
185float4x4 unity_MatrixV;
186float4x4 unity_MatrixInvV;
187float4x4 unity_MatrixVP;
188float4x4 unity_MatrixInvVP;
189float4 unity_StereoScaleOffset;
190int unity_StereoEyeIndex;
191#endif
192
193real4 unity_ShadowColor;
194
195// ----------------------------------------------------------------------------
196
197// Unity specific
198TEXTURECUBE(unity_SpecCube0);
199SAMPLER(samplerunity_SpecCube0);
200
201// Main lightmap
202TEXTURE2D(unity_Lightmap);
203SAMPLER(samplerunity_Lightmap);
204TEXTURE2D_ARRAY(unity_Lightmaps);
205SAMPLER(samplerunity_Lightmaps);
206
207// Dual or directional lightmap (always used with unity_Lightmap, so can share sampler)
208TEXTURE2D(unity_LightmapInd);
209TEXTURE2D_ARRAY(unity_LightmapsInd);
210
211TEXTURE2D(unity_ShadowMask);
212SAMPLER(samplerunity_ShadowMask);
213TEXTURE2D_ARRAY(unity_ShadowMasks);
214SAMPLER(samplerunity_ShadowMasks);
215
216// ----------------------------------------------------------------------------
217
218// TODO: all affine matrices should be 3x4.
219// TODO: sort these vars by the frequency of use (descending), and put commonly used vars together.
220// Note: please use UNITY_MATRIX_X macros instead of referencing matrix variables directly.
221float4x4 _PrevViewProjMatrix;
222float4x4 _ViewProjMatrix;
223float4x4 _NonJitteredViewProjMatrix;
224float4x4 _ViewMatrix;
225float4x4 _ProjMatrix;
226float4x4 _InvViewProjMatrix;
227float4x4 _InvViewMatrix;
228float4x4 _InvProjMatrix;
229float4 _InvProjParam;
230float4 _ScreenSize; // {w, h, 1/w, 1/h}
231float4 _FrustumPlanes[6]; // {(a, b, c) = N, d = -dot(N, P)} [L, R, T, B, N, F]
232
233float4x4 OptimizeProjectionMatrix(float4x4 M)
234{
235 // Matrix format (x = non-constant value).
236 // Orthographic Perspective Combined(OR)
237 // | x 0 0 x | | x 0 x 0 | | x 0 x x |
238 // | 0 x 0 x | | 0 x x 0 | | 0 x x x |
239 // | x x x x | | x x x x | | x x x x | <- oblique projection row
240 // | 0 0 0 1 | | 0 0 x 0 | | 0 0 x x |
241 // Notice that some values are always 0.
242 // We can avoid loading and doing math with constants.
243 M._21_41 = 0;
244 M._12_42 = 0;
245 return M;
246}
247
248#endif // BUILTIN_SHADER_VARIABLES_INCLUDED