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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
#pragma once
// Fixed function emulation is done in a high-level language where we need variable names etc.
#define GFX_HIGH_LEVEL_FF (GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 || GFX_SUPPORTS_D3D11)
// We need the set of "known" glstate parameters for both non-OpenGL rendering runtimes and
// the CgBatch compiler (so that it can report errors for unsupported ones).
// Hence they are in a separate file here.
const char* GetShaderInstanceMatrixParamName(int paramIndex);
const char* GetShaderInstanceVectorParamName(int paramIndex);
const char* GetBuiltinVectorParamName(int paramIndex);
const char* GetBuiltinMatrixParamName(int paramIndex);
const char* GetBuiltinTexEnvParamName(int paramIndex);
bool IsShaderInstanceMatrixParam(const char* name, int* paramIndex=0);
bool IsShaderInstanceVectorParam(const char* name, int* paramIndex);
bool IsVectorBuiltinParam(const char* name, int* paramIndex=0);
bool IsMatrixBuiltinParam(const char* name, int* paramIndex=0);
bool IsTexEnvBuiltinParam(const char* name, int* paramIndex=0);
void InitializeBuiltinShaderParamNames ();
void CleanupBuiltinShaderParamNames ();
bool IsBuiltinArrayName(const char* name);
// Matrices set by unity as "per-instance" data for each object.
enum ShaderBuiltinInstanceMatrixParam {
kShaderInstanceMatMVP = 0,
kShaderInstanceMatMV,
kShaderInstanceMatM,
kShaderInstanceMatInvM,
kShaderInstanceMatTransMV,
kShaderInstanceMatInvTransMV,
kShaderInstanceMatTexture0,
kShaderInstanceMatTexture1,
kShaderInstanceMatTexture2,
kShaderInstanceMatTexture3,
kShaderInstanceMatTexture4,
kShaderInstanceMatTexture5,
kShaderInstanceMatTexture6,
kShaderInstanceMatTexture7,
#if GFX_HIGH_LEVEL_FF
kShaderInstanceMatNormalMatrix,
#endif
kShaderInstanceMatCount
};
enum ShaderBuiltinInstanceVectorParam {
kShaderInstanceVecScale,
kShaderInstanceVecCount
};
enum BuiltinShaderMatrixParam {
kShaderMatView,
kShaderMatProj,
kShaderMatViewProj,
kShaderMatWorldToCamera,
kShaderMatCameraToWorld,
kShaderMatWorldToShadow,
kShaderMatWorldToShadow1,
kShaderMatWorldToShadow2,
kShaderMatWorldToShadow3,
kShaderMatLightmapMatrix,
kShaderMatProjector,
kShaderMatProjectorDistance,
kShaderMatProjectorClip,
kShaderMatGUIClip,
kShaderMatLightMatrix,
kShaderMatCount
};
enum BuiltinShaderVectorParam {
kShaderVecLight0Diffuse = 0,
kShaderVecLight1Diffuse,
kShaderVecLight2Diffuse,
kShaderVecLight3Diffuse,
kShaderVecLight4Diffuse,
kShaderVecLight5Diffuse,
kShaderVecLight6Diffuse,
kShaderVecLight7Diffuse,
kShaderVecLight0Position,
kShaderVecLight1Position,
kShaderVecLight2Position,
kShaderVecLight3Position,
kShaderVecLight4Position,
kShaderVecLight5Position,
kShaderVecLight6Position,
kShaderVecLight7Position,
kShaderVecLight0SpotDirection,
kShaderVecLight1SpotDirection,
kShaderVecLight2SpotDirection,
kShaderVecLight3SpotDirection,
kShaderVecLight4SpotDirection,
kShaderVecLight5SpotDirection,
kShaderVecLight6SpotDirection,
kShaderVecLight7SpotDirection,
kShaderVecLight0Atten,
kShaderVecLight1Atten,
kShaderVecLight2Atten,
kShaderVecLight3Atten,
kShaderVecLight4Atten,
kShaderVecLight5Atten,
kShaderVecLight6Atten,
kShaderVecLight7Atten,
kShaderVecLightModelAmbient,
kShaderVecWorldSpaceLightPos0,
kShaderVecLightColor0,
kShaderVecWorldSpaceCameraPos,
kShaderVecProjectionParams,
kShaderVecScreenParams,
kShaderVecZBufferParams,
kShaderVecLightPositionRange,
kShaderVecUnityAmbient, //@TODO: kill it; replace all uses with LightModelAmbient
kShaderVecLightmapFade,
kShaderVecShadowOffset0,
kShaderVecShadowOffset1,
kShaderVecShadowOffset2,
kShaderVecShadowOffset3,
kShaderVecLightShadowData,
kShaderVecLightShadowBias,
kShaderVecLightSplitsNear,
kShaderVecLightSplitsFar,
kShaderVecShadowSplitSpheres0,
kShaderVecShadowSplitSpheres1,
kShaderVecShadowSplitSpheres2,
kShaderVecShadowSplitSpheres3,
kShaderVecShadowSplitSqRadii,
kShaderVecShadowFadeCenterAndType,
kShaderVecSHAr,
kShaderVecSHAg,
kShaderVecSHAb,
kShaderVecSHBr,
kShaderVecSHBg,
kShaderVecSHBb,
kShaderVecSHC,
kShaderVecTime,
kShaderVecSinTime,
kShaderVecCosTime,
kShaderVecPiTime,
kShaderVecDeltaTime,
kShaderVecVertexLightPosX0,
kShaderVecVertexLightPosY0,
kShaderVecVertexLightPosZ0,
kShaderVecVertexLightAtten0,
kShaderVecUnityLightmapST,
kShaderVecUnityFogStart,
kShaderVecUnityFogEnd,
kShaderVecUnityFogDensity,
kShaderVecUnityFogColor,
kShaderVecColorSpaceGrey,
kShaderVecNPOTScale,
kShaderVecCameraWorldClipPlanes0,
kShaderVecCameraWorldClipPlanes1,
kShaderVecCameraWorldClipPlanes2,
kShaderVecCameraWorldClipPlanes3,
kShaderVecCameraWorldClipPlanes4,
kShaderVecCameraWorldClipPlanes5,
// common textures texel size
kShaderVecWhiteTexelSize,
kShaderVecBlackTexelSize,
kShaderVecRedTexelSize,
kShaderVecGrayTexelSize,
kShaderVecGreyTexelSize,
kShaderVecGrayscaleRampTexelSize,
kShaderVecGreyscaleRampTexelSize,
kShaderVecBumpTexelSize,
kShaderVecLightmapTexelSize,
kShaderVecUnityLightmapTexelSize,
kShaderVecUnityLightmapIndTexelSize,
kShaderVecUnityLightmapThirdTexelSize,
kShaderVecLightTextureB0TexelSize,
kShaderVecGUIClipTexelSize,
kShaderVecDitherMaskLODSize,
kShaderVecRandomRotationTexelSize,
#if GFX_HIGH_LEVEL_FF
kShaderVecFFColor,
kShaderVecFFTextureEnvColor0,
kShaderVecFFTextureEnvColor1,
kShaderVecFFTextureEnvColor2,
kShaderVecFFTextureEnvColor3,
kShaderVecFFTextureEnvColor4,
kShaderVecFFTextureEnvColor5,
kShaderVecFFTextureEnvColor6,
kShaderVecFFTextureEnvColor7,
kShaderVecFFMatEmission,
kShaderVecFFMatAmbient,
kShaderVecFFMatDiffuse,
kShaderVecFFMatSpecular,
kShaderVecFFMatShininess,
kShaderVecFFAlphaTestRef,
kShaderVecFFFogColor,
kShaderVecFFFogParams,
#endif
kShaderVecCount
};
enum BuiltinShaderTexEnvParam {
kShaderTexEnvWhite = 0,
kShaderTexEnvBlack,
kShaderTexEnvRed,
kShaderTexEnvGray,
kShaderTexEnvGrey, // TODO: synonims
kShaderTexEnvGrayscaleRamp,
kShaderTexEnvGreyscaleRamp, // TODO: synonims
kShaderTexEnvBump,
kShaderTexEnvLightmap,
kShaderTexEnvUnityLightmap,
kShaderTexEnvUnityLightmapInd,
kShaderTexEnvUnityLightmapThird,
kShaderTexEnvDitherMaskLOD,
kShaderTexEnvRandomRotation,
kShaderTexEnvCount
};
#define BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES \
"glstate_matrix_mvp", \
"glstate_matrix_modelview0", \
"_Object2World", \
"_World2Object", \
"glstate_matrix_transpose_modelview0", \
"glstate_matrix_invtrans_modelview0", \
"glstate_matrix_texture0", \
"glstate_matrix_texture1", \
"glstate_matrix_texture2", \
"glstate_matrix_texture3", \
"glstate_matrix_texture4", \
"glstate_matrix_texture5", \
"glstate_matrix_texture6", \
"glstate_matrix_texture7" \
#define BUILTIN_SHADER_PARAMS_INSTANCE_VECTORS \
"unity_Scale" \
#define BUILTIN_SHADER_PARAMS_MATRICES \
"unity_MatrixV", \
"glstate_matrix_projection", \
"unity_MatrixVP", \
"_WorldToCamera", \
"_CameraToWorld", \
"_World2Shadow", \
"_World2Shadow1", \
"_World2Shadow2", \
"_World2Shadow3", \
"unity_LightmapMatrix", \
"_Projector", \
"_ProjectorDistance", \
"_ProjectorClip", \
"_GUIClipTextureMatrix", \
"_LightMatrix0" \
#define BUILTIN_SHADER_PARAMS_VECTORS \
"unity_LightColor0", \
"unity_LightColor1", \
"unity_LightColor2", \
"unity_LightColor3", \
"unity_LightColor4", \
"unity_LightColor5", \
"unity_LightColor6", \
"unity_LightColor7", \
"unity_LightPosition0", \
"unity_LightPosition1", \
"unity_LightPosition2", \
"unity_LightPosition3", \
"unity_LightPosition4", \
"unity_LightPosition5", \
"unity_LightPosition6", \
"unity_LightPosition7", \
"unity_SpotDirection0", \
"unity_SpotDirection1", \
"unity_SpotDirection2", \
"unity_SpotDirection3", \
"unity_SpotDirection4", \
"unity_SpotDirection5", \
"unity_SpotDirection6", \
"unity_SpotDirection7", \
"unity_LightAtten0", \
"unity_LightAtten1", \
"unity_LightAtten2", \
"unity_LightAtten3", \
"unity_LightAtten4", \
"unity_LightAtten5", \
"unity_LightAtten6", \
"unity_LightAtten7", \
"glstate_lightmodel_ambient", \
"_WorldSpaceLightPos0", \
"_LightColor0", \
"_WorldSpaceCameraPos", \
"_ProjectionParams", \
"_ScreenParams", \
"_ZBufferParams", \
"_LightPositionRange", \
"unity_Ambient", \
"unity_LightmapFade", \
"_ShadowOffsets0", \
"_ShadowOffsets1", \
"_ShadowOffsets2", \
"_ShadowOffsets3", \
"_LightShadowData", \
"unity_LightShadowBias", \
"_LightSplitsNear", \
"_LightSplitsFar", \
"unity_ShadowSplitSpheres0", \
"unity_ShadowSplitSpheres1", \
"unity_ShadowSplitSpheres2", \
"unity_ShadowSplitSpheres3", \
"unity_ShadowSplitSqRadii", \
"unity_ShadowFadeCenterAndType", \
"unity_SHAr", \
"unity_SHAg", \
"unity_SHAb", \
"unity_SHBr", \
"unity_SHBg", \
"unity_SHBb", \
"unity_SHC", \
"_Time", \
"_SinTime", \
"_CosTime", \
"_PiTime", \
"unity_DeltaTime", \
"unity_4LightPosX0", \
"unity_4LightPosY0", \
"unity_4LightPosZ0", \
"unity_4LightAtten0", \
"unity_LightmapST", \
"unity_FogStart", \
"unity_FogEnd", \
"unity_FogDensity", \
"unity_FogColor", \
"unity_ColorSpaceGrey", \
"unity_NPOTScale", \
"unity_CameraWorldClipPlanes0", \
"unity_CameraWorldClipPlanes1", \
"unity_CameraWorldClipPlanes2", \
"unity_CameraWorldClipPlanes3", \
"unity_CameraWorldClipPlanes4", \
"unity_CameraWorldClipPlanes5", \
\
"white_TexelSize", \
"black_TexelSize", \
"red_TexelSize", \
"gray_TexelSize", \
"grey_TexelSize", \
"grayscaleRamp_TexelSize", \
"greyscaleRamp_TexelSize", \
"bump_TexelSize", \
"lightmap_TexelSize", \
"unity_Lightmap_TexelSize", \
"unity_LightmapInd_TexelSize", \
"unity_LightmapThird_TexelSize", \
"_LightTextureB0_TexelSize", \
"_GUIClipTexture_TexelSize", \
"_DitherMaskLOD_TexelSize", \
"unity_RandomRotation16_TexelSize"
#define BUILTIN_SHADER_PARAMS_VECTORS_SYNONYMS \
/* aliases for unity_LightColorN */ \
"glstate_light0_diffuse", \
"glstate_light1_diffuse", \
"glstate_light2_diffuse", \
"glstate_light3_diffuse", \
/* aliases for unity_LightPositionN */ \
"glstate_light0_position", \
"glstate_light1_position", \
"glstate_light2_position", \
"glstate_light3_position", \
/* aliases for unity_LightAttenN */ \
"glstate_light0_attenuation", \
"glstate_light1_attenuation", \
"glstate_light2_attenuation", \
"glstate_light3_attenuation", \
/* aliases for unity_SpotDirectionN */ \
"glstate_light0_spotDirection", \
"glstate_light1_spotDirection", \
"glstate_light2_spotDirection", \
"glstate_light3_spotDirection"
#define BUILTIN_SHADER_PARAMS_TEXENVS \
"white", \
"black", \
"red", \
"gray", \
"grey", \
"grayscaleRamp", \
"greyscaleRamp", \
"bump", \
"lightmap", \
"unity_Lightmap", \
"unity_LightmapInd", \
"unity_LightmapThird", \
"_DitherMaskLOD", \
"unity_RandomRotation16"
#if GFX_HIGH_LEVEL_FF
#define BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES_FF \
"_glesNormalMatrix" \
#define BUILTIN_SHADER_PARAMS_VECTORS_FF \
"_glesFFColor", \
"_glesTextureEnvColor0", \
"_glesTextureEnvColor1", \
"_glesTextureEnvColor2", \
"_glesTextureEnvColor3", \
"_glesTextureEnvColor4", \
"_glesTextureEnvColor5", \
"_glesTextureEnvColor6", \
"_glesTextureEnvColor7", \
"_glesFrontMaterial.emission", \
"_glesFrontMaterial.ambient", \
"_glesFrontMaterial.diffuse", \
"_glesFrontMaterial.specular", \
"_glesFrontMaterial.shininess", \
"_glesAlphaTestReference", \
"_glesFogColor", \
"_glesFogParams" \
#endif
|