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
|
#ifndef POIFRAG
#define POIFRAG
float _MainEmissionStrength;
float _IgnoreFog;
half _GIEmissionMultiplier;
float _IridescenceTime;
float _AlphaToMask;
float _ForceOpaque;
float _commentIfZero_EnableGrabpass;
float _AlphaPremultiply;
float2 _MainTexPan;
float _MainTextureUV;
float _commentIfZero_LightingAdditiveEnable;
float4 frag(v2f i, uint facing: SV_IsFrontFace): SV_Target
{
#ifdef FORWARD_ADD_PASS
#if !defined(POI_LIGHTING)
return 0;
#endif
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && defined(DIRECTIONAL)
return 0;
#endif
#endif
#ifdef FORWARD_ADD_PASS
if (float(1) == 0)
{
return 0;
}
#endif
UNITY_SETUP_INSTANCE_ID(i);
// Color
float4 albedo = 1;
float4 finalColor = 1;
// Lighting
float bakedCubemap = 0; // Whether or not metallic should run before or after lighting multiplication
float3 finalSpecular0 = 0;
float3 finalSpecular1 = 0;
float3 finalSSS = 0;
fixed lightingAlpha = 1;
float3 finalEnvironmentalRim = 0;
// Emissions
float3 finalEmission = 0;
float3 finalLighting = 1;
float3 emissionLighting = 1;
float3 IridescenceEmission = 0;
float3 spawnInEmission = 0;
float3 voronoiEmission = 0;
float3 matcapEmission = 0;
float3 depthTouchEmission = 0;
float3 decalEmission = 0;
float3 glitterEmission = 0;
float3 panosphereEmission = 0;
float3 backFaceEmission = 0;
float3 dissolveEmission = 0;
float3 rimLightEmission = 0;
float3 flipbookEmission = 0;
float3 textOverlayEmission = 0;
float3 videoEmission = 0;
/**********************************************************************
Initialize the base data that's needed everywhere else in the shader
**********************************************************************/
calculateAttenuation(i);
InitializeMeshData(i, facing);
initPoiMods();
initializeCamera(i);
calculateTangentData();
#ifdef POI_BLACKLIGHT
createBlackLightMask();
if (_BlackLightMaskDebug)
{
return float4(blackLightMask.rgb, 1);
}
#endif
// This has to happen in the initializbecause it alters UV data globally
#ifdef POI_PARALLAX
calculateandApplyParallax();
#endif
// Basically every texture relies on the maintex sampler to function and that's why this is here.
float4 mainTexture = UNITY_SAMPLE_TEX2D(_MainTex, TRANSFORM_TEX(poiMesh.uv[float(0)], _MainTex) + _Time.x * float4(0,0,0,0));
half3 detailMask = 1;
calculateNormals(detailMask);
calculateVertexLightingData(i);
/**********************************************************************
Calculate Light Maps
**********************************************************************/
#ifdef POI_DATA
calculateLightingData(i);
#endif
#ifdef POI_LIGHTING
calculateBasePassLightMaps();
#endif
/**********************************************************************
Calculate Color Data
**********************************************************************/
initTextureData(albedo, mainTexture, backFaceEmission, dissolveEmission, detailMask);
#ifdef POI_DECAL
applyDecals(albedo, decalEmission);
#endif
#ifdef POI_IRIDESCENCE
if (_IridescenceTime == 0)
{
applyIridescence(albedo, IridescenceEmission);
}
#endif
#ifdef POI_VORONOI
applyVoronoi(albedo, voronoiEmission);
#endif
#ifdef POI_MSDF
ApplyTextOverlayColor(albedo, textOverlayEmission);
#endif
#ifdef POI_ENVIRONMENTAL_RIM
finalEnvironmentalRim = calculateEnvironmentalRimLighting(albedo);
#endif
#if defined(POI_METAL) || defined(POI_CLEARCOAT)
CalculateReflectionData();
#endif
#ifdef POI_DATA
distanceFade(albedo);
#endif
#ifdef POI_RANDOM
albedo.a *= i.angleAlpha;
#endif
#ifdef MATCAP
applyMatcap(albedo, matcapEmission);
#endif
#ifdef PANOSPHERE
applyPanosphereColor(albedo, panosphereEmission);
#endif
#ifdef POI_FLIPBOOK
applyFlipbook(albedo, flipbookEmission);
#endif
#ifdef POI_GLITTER
applyGlitter(albedo, glitterEmission);
#endif
#ifdef POI_RIM
applyRimLighting(albedo, rimLightEmission);
#endif
#ifdef POI_DEPTH_COLOR
applyDepthColor(albedo, depthTouchEmission, finalEmission, i.worldDirection);
#endif
#ifdef POI_IRIDESCENCE
if (_IridescenceTime == 1)
{
applyIridescence(albedo, IridescenceEmission);
}
#endif
#ifdef POI_VIDEO
applyScreenEffect(albedo, videoEmission);
#endif
applySpawnIn(albedo, spawnInEmission, poiMesh.uv[0], poiMesh.localPos);
/**********************************************************************
Handle a few alpha options
**********************************************************************/
if (float(0) == 1)
{
if (float(0) == 0)
{
applyDithering(albedo);
}
}
albedo.a = max(float(0), albedo.a);
if (float(0) == 0)
{
albedo.a = 1;
}
if (float(0) >= 1)
{
clip(albedo.a - float(0.5));
}
if (float(0))
{
albedo.rgb *= saturate(albedo.a + 0.0000000001);
}
/**********************************************************************
Lighting Time :)
**********************************************************************/
#ifdef POI_LIGHTING
finalLighting = calculateFinalLighting(albedo.rgb, finalColor);
#ifdef SUBSURFACE
finalSSS = calculateSubsurfaceScattering();
//finalSSS = calculateSubsurfaceScattering(albedo);
#endif
#endif
float4 finalColorBeforeLighting = albedo;
finalColor = finalColorBeforeLighting;
#ifdef POI_SPECULAR
finalSpecular0 = calculateSpecular(finalColorBeforeLighting);
#endif
#ifdef POI_PARALLAX
calculateAndApplyInternalParallax(finalColor);
#endif
#ifdef POI_ALPHA_TO_COVERAGE
ApplyAlphaToCoverage(finalColor);
#endif
if (float(0) == 1)
{
if (float(0) == 1)
{
applyDithering(finalColor);
}
}
#ifdef POI_METAL
calculateMetallicness();
bool probeExists = shouldMetalHappenBeforeLighting();
if (!probeExists)
{
ApplyMetallicsFake(finalColor, albedo);
}
#endif
#ifdef POI_LIGHTING
emissionLighting = finalLighting;
#if defined(FORWARD_ADD_PASS) && defined(POI_METAL)
finalLighting *= 1 - metalicMap;
#endif
applyLighting(finalColor, finalLighting);
#endif
#ifdef POI_BRDF
poiBRDF(finalColor, finalColorBeforeLighting);
#endif
#ifdef POI_METAL
if (probeExists)
{
ApplyMetallics(finalColor, albedo);
}
#endif
finalColor.rgb += finalSpecular0 + finalEnvironmentalRim + finalSSS;
#ifdef FORWARD_BASE_PASS
#ifdef POI_CLEARCOAT
calculateAndApplyClearCoat(finalColor);
#endif
#endif
finalColor.a = saturate(finalColor.a);
/**********************************************************************
Add Up all the emission values :D
**********************************************************************/
//#if defined(FORWARD_BASE_PASS) || defined(POI_META_PASS)
finalEmission += finalColorBeforeLighting.rgb * float(0) * albedo.a;
finalEmission += wireframeEmission;
finalEmission += IridescenceEmission;
finalEmission += spawnInEmission;
finalEmission += voronoiEmission;
finalEmission += matcapEmission;
finalEmission += depthTouchEmission;
finalEmission += decalEmission;
finalEmission += glitterEmission;
finalEmission += panosphereEmission;
finalEmission += backFaceEmission;
finalEmission += rimLightEmission;
finalEmission += flipbookEmission;
finalEmission += videoEmission;
finalEmission += textOverlayEmission;
finalEmission += dissolveEmission;
#ifdef POI_EMISSION
finalEmission += calculateEmissionNew(finalColorBeforeLighting.rgb, finalColor);
#endif
//#endif
// Compensate for HDR lights
#if defined(FORWARD_ADD_PASS)
finalEmission *= emissionLighting; // TODO: add in vertex lights
#else
finalEmission *= max(1, emissionLighting);
#endif
/**********************************************************************
Meta Pass Hype :D
**********************************************************************/
#ifdef POI_META_PASS
UnityMetaInput meta;
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, meta);
meta.Emission = finalEmission * float(1);
meta.Albedo = saturate(finalColor.rgb);
#ifdef POI_SPECULAR
meta.SpecularColor = poiLight.color.rgb * float4(1,1,1,1).rgb * lerp(1, albedo.rgb, float(0)) * float4(1,1,1,1).a;
#else
meta.SpecularColor = poiLight.color.rgb * albedo.rgb;
#endif
return UnityMetaFragment(meta);
#endif
/**********************************************************************
Apply Emission to finalColor
**********************************************************************/
finalColor.rgb += finalEmission;
/**********************************************************************
Grabpass features
**********************************************************************/
if (_commentIfZero_EnableGrabpass)
{
applyGrabEffects(finalColor);
}
/**********************************************************************
Unity Fog
**********************************************************************/
#ifdef FORWARD_BASE_PASS
if (float(0) == 0)
{
UNITY_APPLY_FOG(i.fogCoord, finalColor);
}
#endif
#ifdef FORWARD_ADD_PASS
if (float(0) > 0)
{
finalColor.rgb *= finalColor.a;
}
#endif
if (float(0) == 0)
{
finalColor.a = 1;
}
#ifdef FORWARD_ADD_PASS
//finalColor.rgb = smoothstep(float(0), float(0.5), 1 - (.5 * poiLight.nDotL + .5));
#endif
#ifdef POI_DEBUG
displayDebugInfo(finalColor);
#endif
#ifdef POI_AUDIOLINK
if (_AudioLinkTextureVisualization)
{
finalColor = poiMods.audioLinkTexture;
}
#endif
//finalColor.rgb = frac(finalColor.rgb);
return finalColor;
}
#endif
|