A game about forced loneliness, made by TACStudios
1// UNITY_SHADER_NO_UPGRADE
2
3#ifndef UNITY_SHADER_VARIABLES_INCLUDED
4#define UNITY_SHADER_VARIABLES_INCLUDED
5
6#include "ShaderConfig.cs.hlsl"
7
8// CAUTION:
9// Currently the shaders compiler always include regualr Unity shaderVariables, so I get a conflict here were UNITY_SHADER_VARIABLES_INCLUDED is already define, this need to be fixed.
10// As I haven't change the variables name yet, I simply don't define anything, and I put the transform function at the end of the file outside the guard header.
11// This need to be fixed.
12
13#if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL)
14 #define USING_DIRECTIONAL_LIGHT
15#endif
16
17#if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
18 #define USING_STEREO_MATRICES
19#endif
20
21#if defined(USING_STEREO_MATRICES)
22 #define glstate_matrix_projection unity_StereoMatrixP[unity_StereoEyeIndex]
23 #define unity_MatrixV unity_StereoMatrixV[unity_StereoEyeIndex]
24 #define unity_MatrixInvV unity_StereoMatrixInvV[unity_StereoEyeIndex]
25 #define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]
26
27 #define unity_CameraProjection unity_StereoCameraProjection[unity_StereoEyeIndex]
28 #define unity_CameraInvProjection unity_StereoCameraInvProjection[unity_StereoEyeIndex]
29 #define unity_WorldToCamera unity_StereoWorldToCamera[unity_StereoEyeIndex]
30 #define unity_CameraToWorld unity_StereoCameraToWorld[unity_StereoEyeIndex]
31 #define _WorldSpaceCameraPos unity_StereoWorldSpaceCameraPos[unity_StereoEyeIndex]
32#endif
33
34#define UNITY_LIGHTMODEL_AMBIENT (glstate_lightmodel_ambient * 2)
35
36// ----------------------------------------------------------------------------
37
38CBUFFER_START(UnityPerCamera)
39 // Time (t = time since current level load) values from Unity
40 float4 _Time; // (t/20, t, t*2, t*3)
41 float4 _LastTime; // Last frame time (t/20, t, t*2, t*3)
42 float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
43 float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
44 float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
45 float4 _TimeParameters;
46
47#if !defined(USING_STEREO_MATRICES)
48 float3 _WorldSpaceCameraPos;
49#endif
50
51 // x = 1 or -1 (-1 if projection is flipped)
52 // y = near plane
53 // z = far plane
54 // w = 1/far plane
55 float4 _ProjectionParams;
56
57 // x = width
58 // y = height
59 // z = 1 + 1.0/width
60 // w = 1 + 1.0/height
61 float4 _ScreenParams;
62
63 // Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
64 // x = 1-far/near
65 // y = far/near
66 // z = x/far
67 // w = y/far
68 // or in case of a reversed depth buffer (UNITY_REVERSED_Z is 1)
69 // x = -1+far/near
70 // y = 1
71 // z = x/far
72 // w = 1/far
73 float4 _ZBufferParams;
74
75 // x = orthographic camera's width
76 // y = orthographic camera's height
77 // z = unused
78 // w = 1.0 if camera is ortho, 0.0 if perspective
79 float4 unity_OrthoParams;
80CBUFFER_END
81
82
83CBUFFER_START(UnityPerCameraRare)
84 float4 unity_CameraWorldClipPlanes[6];
85
86#if !defined(USING_STEREO_MATRICES)
87 // Projection matrices of the camera. Note that this might be different from projection matrix
88 // that is set right now, e.g. while rendering shadows the matrices below are still the projection
89 // of original camera.
90 float4x4 unity_CameraProjection;
91 float4x4 unity_CameraInvProjection;
92 float4x4 unity_WorldToCamera;
93 float4x4 unity_CameraToWorld;
94#endif
95CBUFFER_END
96
97// ----------------------------------------------------------------------------
98
99CBUFFER_START(UnityPerDraw)
100#ifdef UNITY_USE_PREMULTIPLIED_MATRICES
101 float4x4 glstate_matrix_mvp;
102 float4x4 glstate_matrix_modelview0;
103 float4x4 glstate_matrix_invtrans_modelview0;
104#endif
105
106 float4x4 unity_ObjectToWorld;
107 float4x4 unity_WorldToObject;
108 float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
109 float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
110
111 float4 unity_LightmapST;
112 float4 unity_DynamicLightmapST;
113
114 // SH lighting environment
115 float4 unity_SHAr;
116 float4 unity_SHAg;
117 float4 unity_SHAb;
118 float4 unity_SHBr;
119 float4 unity_SHBg;
120 float4 unity_SHBb;
121 float4 unity_SHC;
122
123 // x = Disabled(0)/Enabled(1)
124 // y = Computation are done in global space(0) or local space(1)
125 // z = Texel size on U texture coordinate
126 float4 unity_ProbeVolumeParams;
127 float4x4 unity_ProbeVolumeWorldToObject;
128 float3 unity_ProbeVolumeSizeInv;
129 float3 unity_ProbeVolumeMin;
130
131 // This contain occlusion factor from 0 to 1 for dynamic objects (no SH here)
132 float4 unity_ProbesOcclusion;
133
134 // HDR environment map decode instructions
135 half4 unity_SpecCube0_HDR;
136CBUFFER_END
137
138#if defined(USING_STEREO_MATRICES)
139CBUFFER_START(UnityStereoGlobals)
140 float4x4 unity_StereoMatrixP[2];
141 float4x4 unity_StereoMatrixV[2];
142 float4x4 unity_StereoMatrixInvV[2];
143 float4x4 unity_StereoMatrixVP[2];
144
145 float4x4 unity_StereoCameraProjection[2];
146 float4x4 unity_StereoCameraInvProjection[2];
147 float4x4 unity_StereoWorldToCamera[2];
148 float4x4 unity_StereoCameraToWorld[2];
149
150 float3 unity_StereoWorldSpaceCameraPos[2];
151 float4 unity_StereoScaleOffset[2];
152CBUFFER_END
153#endif
154
155#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) && defined(SHADER_STAGE_VERTEX)
156 #define unity_StereoEyeIndex UNITY_VIEWID
157 UNITY_DECLARE_MULTIVIEW(2);
158#elif defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
159 static uint unity_StereoEyeIndex;
160#elif defined(UNITY_SINGLE_PASS_STEREO)
161 CBUFFER_START(UnityStereoEyeIndex)
162 int unity_StereoEyeIndex;
163 CBUFFER_END
164#endif
165
166CBUFFER_START(UnityPerDrawRare)
167 float4x4 glstate_matrix_transpose_modelview0;
168CBUFFER_END
169
170// ----------------------------------------------------------------------------
171
172CBUFFER_START(UnityPerFrame)
173 float4 glstate_lightmodel_ambient;
174 float4 unity_AmbientSky;
175 float4 unity_AmbientEquator;
176 float4 unity_AmbientGround;
177 float4 unity_IndirectSpecColor;
178 float4 unity_FogParams;
179 half4 unity_FogColor;
180
181#if !defined(USING_STEREO_MATRICES)
182 float4x4 glstate_matrix_projection;
183 float4x4 unity_MatrixV;
184 float4x4 unity_MatrixInvV;
185 float4x4 unity_MatrixVP;
186 float4 unity_StereoScaleOffset;
187 int unity_StereoEyeIndex;
188#endif
189
190 float3 unity_ShadowColor;
191 uint _TaaFrameIndex; // [0, 7]
192CBUFFER_END
193
194// ----------------------------------------------------------------------------
195
196// These are the samplers available in the HDRenderPipeline.
197// Avoid declaring extra samplers as they are 4x SGPR each on GCN.
198SAMPLER(s_linear_clamp_sampler);
199SAMPLER(s_trilinear_clamp_sampler);
200
201// ----------------------------------------------------------------------------
202
203TEXTURE2D(_MainDepthTexture);
204SAMPLER(sampler_MainDepthTexture);
205
206// Main lightmap
207TEXTURE2D(unity_Lightmap);
208SAMPLER(samplerunity_Lightmap);
209TEXTURE2D_ARRAY(unity_Lightmaps);
210SAMPLER(samplerunity_Lightmaps);
211
212// Dual or directional lightmap (always used with unity_Lightmap, so can share sampler)
213TEXTURE2D(unity_LightmapInd);
214TEXTURE2D_ARRAY(unity_LightmapsInd);
215
216// Dynamic GI lightmap
217TEXTURE2D(unity_DynamicLightmap);
218SAMPLER(samplerunity_DynamicLightmap);
219
220TEXTURE2D(unity_DynamicDirectionality);
221
222// Default reflection probe
223TEXTURECUBE(unity_SpecCube0);
224SAMPLER(samplerunity_SpecCube0);
225
226// We can have shadowMask only if we have lightmap, so no sampler
227TEXTURE2D(unity_ShadowMask);
228TEXTURE2D_ARRAY(unity_ShadowMasks);
229
230// TODO: Change code here so probe volume use only one transform instead of all this parameters!
231TEXTURE3D(unity_ProbeVolumeSH);
232SAMPLER(samplerunity_ProbeVolumeSH);
233
234CBUFFER_START(UnityVelocityPass)
235 float4x4 unity_MatrixNonJitteredVP;
236 float4x4 unity_MatrixPreviousVP;
237 float4x4 unity_MatrixPreviousM;
238 float4x4 unity_MatrixPreviousMI;
239 //X : Use last frame positions (right now skinned meshes are the only objects that use this
240 //Y : Force No Motion
241 //Z : Z bias value
242 float4 unity_MotionVectorsParams;
243CBUFFER_END
244
245// ----------------------------------------------------------------------------
246
247// TODO: all affine matrices should be 3x4.
248// TODO: sort these vars by the frequency of use (descending), and put commonly used vars together.
249// Note: please use UNITY_MATRIX_X macros instead of referencing matrix variables directly.
250CBUFFER_START(UnityPerPass)
251float4x4 _PrevViewProjMatrix;
252float4x4 _ViewProjMatrix;
253float4x4 _NonJitteredViewProjMatrix;
254float4x4 _ViewMatrix;
255float4x4 _ProjMatrix;
256float4x4 _InvViewProjMatrix;
257float4x4 _InvViewMatrix;
258float4x4 _InvProjMatrix;
259float4 _InvProjParam;
260float4 _ScreenSize; // {w, h, 1/w, 1/h}
261float4 _FrustumPlanes[6]; // {(a, b, c) = N, d = -dot(N, P)} [L, R, T, B, N, F]
262CBUFFER_END
263
264float4x4 OptimizeProjectionMatrix(float4x4 M)
265{
266 // Matrix format (x = non-constant value).
267 // Orthographic Perspective Combined(OR)
268 // | x 0 0 x | | x 0 x 0 | | x 0 x x |
269 // | 0 x 0 x | | 0 x x 0 | | 0 x x x |
270 // | x x x x | | x x x x | | x x x x | <- oblique projection row
271 // | 0 0 0 1 | | 0 0 x 0 | | 0 0 x x |
272 // Notice that some values are always 0.
273 // We can avoid loading and doing math with constants.
274 M._21_41 = 0;
275 M._12_42 = 0;
276 return M;
277}
278
279// For the shader graph node preview, we use the legacy unity matrices because they are pipeline agnostic.
280#include "ShaderVariablesMatrixDefsLegacyUnity.hlsl"
281
282#include "ShaderVariablesFunctions.hlsl"
283
284#endif // UNITY_SHADER_VARIABLES_INCLUDED