yum-archive/2ner

A toon shader for Unity's BIRP.

git clone https://git.yummers.dev/yum-archive/2ner

yumbuncha shitttt0a8d744

master
18.0 KiB600 linesraw
1#ifndef __2NER_INC
2#define __2NER_INC
3
4#define HANDLE_SHADOWS_BLENDING_IN_GI
5
6#include "UnityCG.cginc"
7#include "UnityStandardCoreMinimal.cginc"
8#include "UnityLightingCommon.cginc"
9#include "AutoLight.cginc"
10
11#include "custom30.cginc"
12#include "eyes.cginc"
13#include "face_me.cginc"
14#include "false_color_visualization.cginc"
15#include "features.cginc"
16#include "fog.cginc"
17#include "globals.cginc"
18#include "harnack_tracing.cginc"
19#include "interpolators.cginc"
20#include "letter_grid.cginc"
21#include "matcaps.cginc"
22#include "math.cginc"
23#include "poi.cginc"
24#include "shatter_wave.cginc"
25#include "ssao.cginc"
26#include "ssfd.cginc"
27#include "tessellation.cginc"
28#include "trochoid.cginc"
29#include "unigram_letter_grid.cginc"
30#include "vertex_domain_warping.cginc"
31#include "yum_brdf.cginc"
32#include "yum_pbr.cginc"
33#include "yum_lighting.cginc"
34
35v2f vert(appdata v) {
36#if defined(OUTLINE_PASS) && !defined(_OUTLINES)
37  // The outline pass will be entirely elided when locked. This just lets us
38  // hide outlines when not locked.
39  return (v2f) (0.0/0.0);
40#endif
41#if defined(_RAYMARCHED_FOG) && !defined(FORWARD_BASE_PASS)
42  return (v2f) (0.0/0.0);
43#endif
44#if defined(DEPTH_PREPASS) && !defined(_DEPTH_PREPASS)
45  return (v2f) (0.0/0.0);
46#endif
47#if defined(EXTRA_STENCIL_COLOR_PASS) && !defined(_EXTRA_STENCIL_COLOR_PASS)
48  return (v2f) (0.0/0.0);
49#endif
50#if defined(MASKED_STENCIL1_PASS)
51#if !defined(_MASKED_STENCIL1)
52  return (v2f) (0.0/0.0);
53#endif
54  float masked_stencil1_mask = _Masked_Stencil1_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
55  [branch]
56  if (masked_stencil1_mask < 0.5) {
57    return (v2f) (0.0/0.0);
58  }
59#endif
60#if defined(MASKED_STENCIL2_PASS)
61#if !defined(_MASKED_STENCIL2)
62  return (v2f) (0.0/0.0);
63#endif
64  float masked_stencil2_mask = _Masked_Stencil2_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
65  [branch]
66  if (masked_stencil2_mask < 0.5) {
67    return (v2f) (0.0/0.0);
68  }
69#endif
70#if defined(MASKED_STENCIL3_PASS)
71#if !defined(_MASKED_STENCIL3)
72  return (v2f) (0.0/0.0);
73#endif
74  float masked_stencil3_mask = _Masked_Stencil3_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
75  [branch]
76  if (masked_stencil3_mask < 0.5) {
77    return (v2f) (0.0/0.0);
78  }
79#endif
80#if defined(MASKED_STENCIL4_PASS)
81#if !defined(_MASKED_STENCIL4)
82  return (v2f) (0.0/0.0);
83#endif
84  float masked_stencil4_mask = _Masked_Stencil4_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
85  [branch]
86  if (masked_stencil4_mask < 0.5) {
87    return (v2f) (0.0/0.0);
88  }
89#endif
90#if defined(EXTRA_STENCIL_COLOR_PASS) && !defined(_EXTRA_STENCIL_COLOR_PASS)
91	return (v2f) (0.0/0.0);
92#endif
93#if defined(FORWARD_ADD_PASS) & defined(_UNLIT)
94  return (v2f) (0.0/0.0);
95#endif
96
97  v2f o;
98
99  UNITY_SETUP_INSTANCE_ID(v);
100  UNITY_INITIALIZE_OUTPUT(v2f, o);
101  UNITY_TRANSFER_INSTANCE_ID(v, o);
102  UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
103
104#if defined(_SPHERIZE)
105  {
106    float3 tgt_normal = normalize(o.objPos.xyz);
107    float3 tgt_tangent = normalize(float3(tgt_normal.y, -tgt_normal.x, 0));
108    float3 tgt_pos = tgt_normal * _Spherize_Radius;
109    v.normal = normalize(lerp(v.normal, tgt_normal, _Spherize_Strength));
110    v.vertex.xyz = lerp(v.vertex.xyz, tgt_pos, _Spherize_Strength);
111  }
112#endif
113#if !defined(_TESSELLATION) && defined(_SHATTER_WAVE)
114  shatterWaveVert(v.vertex.xyz, v.normal, v.tangent);
115#endif
116
117#if defined(_VERTEX_DOMAIN_WARPING)
118  v.vertex.xyz = domainWarpVertexPosition(v.vertex.xyz);
119#endif
120
121#if defined(_TROCHOID)
122  o.orig_pos = v.vertex.xyz;
123  v.vertex.xyz = trochoid_map(v.vertex.xyz);
124#endif
125
126#if defined(OUTLINE_PASS)
127  [branch]
128  if (!_Outlines_Enabled_Dynamic) {
129    return (v2f) (0.0/0.0);
130  }
131#if defined(_OUTLINE_MASK)
132  float thickness = _Outline_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
133  thickness = (_Outline_Mask_Invert == 0 ? thickness : 1 - thickness);
134#else
135  float thickness = 1;
136#endif
137  v.vertex.xyz += _Outline_Width * v.normal * thickness;
138  v.normal *= -1;
139  v.tangent *= -1;
140#endif  // OUTLINE_PASS
141
142#if defined(_FACE_ME)
143  face_me(v);
144#endif
145
146#if defined(_FOCAL_LENGTH_CONTROL)
147  [branch]
148  if (_Focal_Length_Enabled_Dynamic) {
149    float4 fl_worldPos_unscaled = mul(unity_ObjectToWorld, v.vertex);
150    float4 fl_viewPos_unscaled = mul(UNITY_MATRIX_V, fl_worldPos_unscaled);
151
152    float4 fl_objPos = float4(v.vertex.xyz * _Focal_Length_Multiplier, v.vertex.w);
153    float4 fl_worldPos = mul(unity_ObjectToWorld, fl_objPos);
154    float4 fl_viewPos = mul(UNITY_MATRIX_V, fl_worldPos);
155    fl_viewPos.xy /= _Focal_Length_Multiplier;
156
157    float2 fl_compensation = fl_viewPos_unscaled.xy - fl_viewPos.xy;
158    fl_viewPos.xy += fl_compensation;
159
160    o.pos = mul(UNITY_MATRIX_P, fl_viewPos);
161  } else {
162    o.pos = UnityObjectToClipPos(v.vertex);
163  }
164#else
165  o.pos = UnityObjectToClipPos(v.vertex);
166#endif
167
168#if defined(_TESSELLATION)
169  o.tpos = v.vertex;
170#endif
171  o.uv01.xy = v.uv0;
172#if defined(LIGHTMAP_ON)
173  o.uv01.zw = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
174#else
175  o.uv01.zw = v.uv1;
176#endif
177  o.uv23.xy = v.uv2;
178  o.uv23.zw = v.uv3;
179#if defined(_MIRROR_UVS_IN_MIRROR)
180  [branch]
181  if (isInMirror()) {
182    o.uv01.x = 1.0 - o.uv01.x;
183    o.uv01.z = 1.0 - o.uv01.z;
184    o.uv23.x = 1.0 - o.uv23.x;
185    o.uv23.z = 1.0 - o.uv23.z;
186  }
187#endif
188  o.objPos = v.vertex;
189
190  // These are used to convert normals from tangent space to world space.
191  o.normal = v.normal;
192  o.tangent = v.tangent;
193
194  UNITY_TRANSFER_LIGHTING(o, v.uv1);
195  UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos);
196  TRANSFER_SHADOW(o);
197#if defined(SHADOW_CASTER_PASS)
198	TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
199#endif
200
201#if defined(V2F_COLOR)
202  // Vertex color
203  o.color = v.color;
204#endif
205
206  // Calculate vertex lights
207  #ifdef VERTEXLIGHT_ON
208    float3 worldPos = mul(unity_ObjectToWorld, v.vertex);
209    #if defined(_WRAPPED_LIGHTING)
210      o.vertexLight = Shade4PointLightsWrapped(
211        unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
212        unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
213        unity_4LightAtten0, worldPos, o.normal, _Wrap_NoL_Diffuse_Strength);
214    #else
215      o.vertexLight = Shade4PointLights(
216        unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
217        unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
218        unity_4LightAtten0, worldPos, o.normal);
219    #endif
220  #else
221    o.vertexLight = 0;
222  #endif
223
224  return o;
225}
226
227//ifex _Fur_Enabled==0
228[maxvertexcount(30)]
229void geom(triangle v2f input[3], inout TriangleStream<v2f> stream) {
230#if defined(_FUR)
231#if defined(_FUR_MASK)
232  float fur_mask = _Fur_Mask.SampleLevel(bilinear_repeat_s, input[0].uv01.xy * _Fur_Mask_ST.xy, 0);
233#else
234  float fur_mask = 1;
235#endif
236
237  stream.Append(input[0]);
238  stream.Append(input[1]);
239  stream.Append(input[2]);
240  stream.RestartStrip();
241
242  [branch]
243  if (fur_mask < 0.5) {
244    return;
245  }
246
247  float3 gravDirObj = normalize(mul(unity_WorldToObject, float3(0, -1, 0)));
248
249  // Compute gravity direction minus component that would compress this shell.
250  // Could compute average normal but this is probably good enough.
251  float3 gravDirNoRegress = gravDirObj - min(0, input[0].normal * dot(gravDirObj, input[0].normal));
252
253  float3 worldPos = mul(unity_ObjectToWorld, input[0].objPos).xyz;
254  float radius = length(_WorldSpaceCameraPos - worldPos);
255  uint fur_layers = lerp(_Fur_Layers - 3, 5, saturate((radius - _Fur_Min_Dist) / (_Fur_Max_Dist - _Fur_Min_Dist)));
256
257  [loop]
258  for (uint layer = 0; layer < fur_layers; layer++) {
259    float t = (float) layer / (float) max(fur_layers - 4, 1);
260
261    float offset = t * _Fur_Thickness;
262
263    v2f o = input[layer % 3];
264    float3 normal_ws = UnityObjectToWorldNormal(o.normal);
265
266    float3 dir = lerp(o.normal, gravDirNoRegress, t * t * _Fur_Gravity_Strength);
267
268    o.objPos.xyz += dir * offset;
269
270    float3 worldPos = mul(unity_ObjectToWorld, o.objPos).xyz;
271    o.pos = UnityWorldToClipPos(worldPos);
272    o.vertexLight.w = t;
273    stream.Append(o);
274  }
275#else
276  stream.Append(input[0]);
277  stream.Append(input[1]);
278  stream.Append(input[2]);
279  stream.RestartStrip();
280#endif  // _FUR
281}
282//endex
283
284float4 frag(v2f i, uint facing : SV_IsFrontFace
285#if defined(_HARNACK_TRACING) || defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || (defined(_CUSTOM30) && !defined(_DEPTH_PREPASS)) || defined(_RAYMARCHED_FOG) || defined(_TESSELLATION_HEIGHTMAP)
286  , out float depth : SV_DepthLessEqual
287#endif
288) : SV_Target {
289
290  UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
291  UNITY_SETUP_INSTANCE_ID(i);
292  UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
293
294#if defined(_CUSTOM30) && defined(_DEPTH_PREPASS) && !defined(FORWARD_BASE_PASS)
295  return 0;
296#endif
297
298  i.normal *= facing ? 1 : -1;
299  i.normal = UnityObjectToWorldNormal(i.normal);
300  i.tangent.xyz = UnityObjectToWorldNormal(i.tangent.xyz);
301
302  // Not necessarily normalized after interpolation
303  i.normal = normalize(i.normal);
304  i.tangent.xyz = normalize(i.tangent.xyz);
305
306#if defined(_SHATTER_WAVE) || defined(_SCREEN_SPACE_NORMALS)
307  calcNormalInScreenSpace(i.normal, i.objPos);
308  i.normal = UnityObjectToWorldNormal(i.normal);
309#endif
310
311  f2f f = (f2f) 0;
312  f.worldPos = mul(unity_ObjectToWorld, i.objPos);
313  f.binormal = cross(i.normal, i.tangent.xyz) * i.tangent.w;
314  f.eyeVec = f.worldPos - _WorldSpaceCameraPos;
315  f.viewDir = normalize(f.eyeVec);
316  f.tbn = float3x3(
317    i.tangent.xyz,
318    f.binormal,
319    i.normal
320  );
321
322#if defined(_RAYMARCHED_FOG)
323  {
324    // Many fields are overspecified as .rgb or .xyz. This is because thry's
325    // shader locker will inline those fields (incorrectly) as float4. Unity's
326    // shader compiler doesn't like that, demanding exact type correspondence.
327    // Overspecifying gets around the issue.
328
329    FogParams fog_params = {
330      _Raymarched_Fog_Color.rgb,
331      _Raymarched_Fog_Direct_Light_Intensity,
332      _Raymarched_Fog_Indirect_Light_Intensity,
333      _Raymarched_Fog_Steps,
334      _Raymarched_Fog_Y_Cutoff,
335      _Raymarched_Fog_Dithering_Noise,
336      _Raymarched_Fog_Dithering_Noise_TexelSize,
337      _Raymarched_Fog_Density_Noise,
338      _Raymarched_Fog_Density_Noise_Scale,
339      _Raymarched_Fog_Velocity.xyz,
340      _Raymarched_Fog_Mean_Free_Path,
341      _Raymarched_Fog_Albedo,
342      _Raymarched_Fog_G,
343      _Raymarched_Fog_Height_Scale,
344      _Raymarched_Fog_Height_Offset,
345      _Raymarched_Fog_Turbulence,
346      _Raymarched_Fog_Step_Size,
347      _Raymarched_Fog_Step_Growth,
348      #if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE)
349      _Raymarched_Fog_Emitter_Texture,
350      _Raymarched_Fog_Emitter_Texture_TexelSize,
351      _Raymarched_Fog_Emitter_Texture_World_Pos.xyz,
352      normalize(_Raymarched_Fog_Emitter_Texture_World_Normal).xyz,
353      normalize(_Raymarched_Fog_Emitter_Texture_World_Tangent).xyz,
354      normalize(cross(_Raymarched_Fog_Emitter_Texture_World_Normal, _Raymarched_Fog_Emitter_Texture_World_Tangent)).xyz,
355      _Raymarched_Fog_Emitter_Texture_World_Scale.xy,
356      1.0f / _Raymarched_Fog_Emitter_Texture_World_Scale.xy,
357      _Raymarched_Fog_Emitter_Texture_Luminance,
358      _Raymarched_Fog_Emitter_Texture_Intensity,
359      #endif
360      #if defined(_RAYMARCHED_FOG_EMITTER_TEXTURE_WARPING)
361      _Raymarched_Fog_Emitter_Texture_Warping_Octaves,
362      _Raymarched_Fog_Emitter_Texture_Warping_Strength,
363      _Raymarched_Fog_Emitter_Texture_Warping_Scale,
364      _Raymarched_Fog_Emitter_Texture_Warping_Speed,
365      #endif
366      #if defined(_RAYMARCHED_FOG_DENSITY_EXPONENT)
367      _Raymarched_Fog_Density_Exponent,
368      #endif
369    };
370    FogResult fog_result = raymarched_fog(i, f, fog_params);
371    depth = fog_result.depth;
372    return fog_result.color;
373  }
374#endif
375
376#if defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || defined(_TESSELLATION_HEIGHTMAP)
377  {
378    [branch]
379    if (
380        false
381#if defined(_SHATTER_WAVE)
382        || any(_Shatter_Wave_Amplitude > 1E-4)
383#endif
384#if defined(_VERTEX_DOMAIN_WARPING)
385        || _Vertex_Domain_Warping_Octaves > 0.1
386#endif
387#if defined(_TESSELLATION_HEIGHTMAP_0)
388        || _Tessellation_Heightmap_0_Scale > 1E-4
389#endif
390#if defined(_TESSELLATION_HEIGHTMAP_1)
391        || _Tessellation_Heightmap_1_Scale > 1E-4
392#endif
393#if defined(_TESSELLATION_HEIGHTMAP_2)
394        || _Tessellation_Heightmap_2_Scale > 1E-4
395#endif
396#if defined(_TESSELLATION_HEIGHTMAP_3)
397        || _Tessellation_Heightmap_3_Scale > 1E-4
398#endif
399#if defined(_TESSELLATION_HEIGHTMAP_4)
400        || _Tessellation_Heightmap_4_Scale > 1E-4
401#endif
402#if defined(_TESSELLATION_HEIGHTMAP_5)
403        || _Tessellation_Heightmap_5_Scale > 1E-4
404#endif
405#if defined(_TESSELLATION_HEIGHTMAP_6)
406        || _Tessellation_Heightmap_6_Scale > 1E-4
407#endif
408#if defined(_TESSELLATION_HEIGHTMAP_7)
409        || _Tessellation_Heightmap_7_Scale > 1E-4
410#endif
411    ) {
412      float4 clip_pos = UnityObjectToClipPos(i.objPos);
413      depth = clip_pos.z / clip_pos.w;
414    } else {
415      // Perspective division takes place before the fragment shader, so we
416      // don't have to divide again.
417      depth = i.pos.z;
418    }
419  }
420#endif
421
422#if defined(_EYE_EFFECT_00)
423  EyeEffectOutput eye_effect_00 = EyeEffect_00(i);
424  i.uv01.xy = eye_effect_00.uv;
425#endif
426
427#if defined(_CUSTOM30)
428#if defined(FORWARD_BASE_PASS) || (!defined(_DEPTH_PREPASS) && defined(SHADOW_CASTER_PASS))
429#if defined(_CUSTOM30_BASICCUBE)
430  Custom30Output c30_out = BasicCube(i);
431#elif defined(_CUSTOM30_BASICWEDGE)
432  Custom30Output c30_out = BasicWedge(i);
433#elif defined(_CUSTOM30_BASICPLATFORM)
434  Custom30Output c30_out = BasicPlatform(i);
435#elif defined(_CUSTOM30_RAINBOW)
436  Custom30Output c30_out = Rainbow(i);
437#else
438  Custom30Output c30_out = (Custom30Output) 0;
439#endif
440  i.normal = c30_out.normal;
441  float4 c30_clipPos = UnityObjectToClipPos(i.objPos);
442  float4 c30_screenPos = ComputeScreenPos(c30_clipPos);
443  i.pos = c30_screenPos;
444#if !defined(_DEPTH_PREPASS)
445  depth = c30_out.depth;
446#endif
447#endif
448#endif
449
450  float ssao = 1;
451#if defined(_SSAO)
452	float2 debug;
453	ssao = get_ssao(i, f, debug);
454#endif
455  YumPbr pbr = GetYumPbr(i, f);
456	pbr.albedo.rgb *= ssao;
457
458#if defined(META_PASS)
459#if defined(_EMISSION)
460  return pbr.emission;
461#else
462  return 0;
463#endif
464#endif
465
466#if defined(_TROCHOID)
467  float3 normal_obj = trochoid_normal(i.orig_pos);
468
469  // We need tangents that are perpendicular to the new normal.
470  // A common way to generate them is to cross with a fixed "up" vector.
471  float3 tangent_obj = normalize(cross(normal_obj, float3(0, 1, 0)));
472  float3 binormal_obj = cross(normal_obj, tangent_obj);
473
474  i.normal = UnityObjectToWorldNormal(normal_obj);
475  i.tangent = float4(normalize(mul((float3x3)unity_ObjectToWorld, tangent_obj)), 1);
476  i.binormal = normalize(mul((float3x3)unity_ObjectToWorld, binormal_obj));
477  i.normal *= facing ? 1 : -1;
478
479  float theta = 1 - atan2(i.orig_pos.y, i.orig_pos.x) / PI;
480  float3 color = _Trochoid_Color_Ramp.SampleLevel(linear_clamp_s, float2(theta, 0.5), 0).rgb;
481  pbr.albedo.xyz = color;
482#endif
483
484#if defined(_HARNACK_TRACING)
485  HarnackTracingOutput harnack_output = HarnackTracing(i);
486  pbr.albedo = float4(1, 1, 1, 0.2);
487  pbr.smoothness = 0.95;
488  pbr.roughness_perceptual = 0.05;
489  pbr.roughness = pbr.roughness_perceptual * pbr.roughness_perceptual;
490  pbr.metallic = 0;
491#endif
492
493#if defined(_SSFD)
494  float ssfd_mask = ssfd(i.uv01.xy, _SSFD_Scale, _SSFD_Max_Fwidth, 0, _SSFD_Noise);
495  pbr.albedo *= (ssfd_mask > _SSFD_Threshold);
496#endif
497
498#if defined(OUTLINE_PASS)
499  pbr.smoothness = 0;
500  pbr.roughness = 1;
501  pbr.roughness_perceptual = 1;
502  pbr.metallic = 0;
503#endif
504
505#if defined(_EYE_EFFECT_00)
506  pbr.normal = eye_effect_00.normal;
507#endif
508
509#if defined(_LETTER_GRID)
510  LetterGridOutput letter_grid_output = LetterGrid(i);
511  pbr.albedo.rgb = lerp(pbr.albedo.rgb, letter_grid_output.albedo, letter_grid_output.albedo.a);
512  pbr.metallic = lerp(pbr.metallic, letter_grid_output.metallic, letter_grid_output.albedo.a);
513  pbr.roughness = lerp(pbr.roughness, letter_grid_output.roughness, letter_grid_output.albedo.a);
514#endif
515
516#if defined(_UNIGRAM_LETTER_GRID)
517  UnigramLetterGridOutput unigram_letter_grid_output = UnigramLetterGrid(i, facing);
518  pbr.albedo.rgb = lerp(pbr.albedo.rgb, unigram_letter_grid_output.albedo,
519      unigram_letter_grid_output.albedo.a);
520  pbr.metallic = lerp(pbr.metallic, unigram_letter_grid_output.metallic,
521      unigram_letter_grid_output.albedo.a);
522  pbr.roughness = lerp(pbr.roughness, unigram_letter_grid_output.roughness,
523      unigram_letter_grid_output.albedo.a);
524#endif
525
526  [branch]
527  if (_Mode == 1) {
528    clip(pbr.albedo.a - _Clip);
529    pbr.albedo.a = 1;
530  }
531
532#if defined(EXTRA_STENCIL_COLOR_PASS) && defined(_EXTRA_STENCIL_COLOR_PASS)
533  pbr.albedo = _ExtraStencilColor;
534#endif
535
536#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS) || defined(OUTLINE_PASS) || defined(EXTRA_STENCIL_COLOR_PASS)
537  YumLighting l = GetYumLighting(i, f, pbr);
538
539#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)
540  applyMatcapsAndRimLighting(i, f, pbr, l);
541  l.diffuse = max(0, l.diffuse);
542  l.specular = max(0, l.specular);
543#endif
544
545  pbr.albedo.rgb = visualizeInFalseColor(pbr.albedo.rgb);
546  pbr.albedo.rgb = applyQuasiShadows(pbr.albedo.rgb, l);
547
548#if defined(_UNLIT)
549  float4 lit = pbr.albedo;
550#else
551  float4 lit = YumBRDF(i, f, l, pbr);
552#endif
553
554#if defined(_HARNACK_TRACING)
555  pbr.albedo = harnack_output.color;
556  pbr.smoothness = 0;
557  pbr.roughness = 1;
558  pbr.roughness_perceptual = 1;
559  pbr.metallic = 0;
560  pbr.normal = harnack_output.normal;
561  l.NoL = saturate(dot(pbr.normal, l.dir));
562  l.NoL_wrapped_s = l.NoL;
563  l.NoL_wrapped_d = l.NoL;
564  float4 harnack_lit = YumBRDF(i, l, pbr);
565  //lit = alphaBlend(harnack_lit, lit);
566  lit = harnack_lit;
567  {
568    float4 clip_pos = mul(UNITY_MATRIX_VP, float4(harnack_output.worldPos, 1.0));
569    depth = clip_pos.z / clip_pos.w;
570  }
571#endif
572
573#if defined(_EMISSION) || (defined(_GLITTER) && defined(FORWARD_BASE_PASS)) || defined(OUTLINE_PASS)
574  lit.rgb += pbr.emission;
575#endif
576#if defined(_LETTER_GRID)
577  lit.rgb += letter_grid_output.emission * letter_grid_output.albedo.a;
578#endif
579#if defined(_UNIGRAM_LETTER_GRID)
580  lit.rgb += unigram_letter_grid_output.emission * unigram_letter_grid_output.albedo.a;
581#endif
582
583  UNITY_EXTRACT_FOG_FROM_EYE_VEC(i);
584  UNITY_APPLY_FOG(_unity_fogCoord, lit.rgb);
585
586  return lit;
587#elif defined(SHADOW_CASTER_PASS)
588  // Apply dithering for LOD if needed
589  #ifdef LOD_FADE_CROSSFADE
590    UnityApplyDitherCrossFade(i.pos.xy);
591  #endif
592
593  // Output proper shadow data
594  SHADOW_CASTER_FRAGMENT(i)
595#elif defined(MASKED_STENCIL1_PASS) || defined(MASKED_STENCIL2_PASS) || defined(MASKED_STENCIL3_PASS) || defined(MASKED_STENCIL4_PASS) || defined(DEPTH_PREPASS)
596  return 0;
597#endif
598}
599
600#endif  // __2NER_INC