A game about forced loneliness, made by TACStudios
1// Shadergraph-friendly implementation of LODDitheringTransition.
2// The function as defined in Common.hlsl terminates on clip(f).
3// However, since it does not return or output anything, shadergraph
4// doesn't recognize it as code that gets used. This file can be removed
5// and replaced with a string custom function if Shader Graph ever adds
6// support for flagging custom function nodes as used, even if not
7// connected to anything.
8#ifndef SHADERGRAPH_CROSSFADE_INCLUDED
9#define SHADERGRAPH_CROSSFADE_INCLUDED
10#ifndef UNITY_MATERIAL_INCLUDED
11uint2 ComputeFadeMaskSeed(float3 V, uint2 positionSS)
12{
13 uint2 fadeMaskSeed;
14
15 // Is this a reasonable quality gate?
16#if defined(SHADER_QUALITY_HIGH)
17 if (IsPerspectiveProjection())
18 {
19 // Start with the world-space direction V. It is independent from the orientation of the camera,
20 // and only depends on the position of the camera and the position of the fragment.
21 // Now, project and transform it into [-1, 1].
22 float2 pv = PackNormalOctQuadEncode(V);
23 // Rescale it to account for the resolution of the screen.
24 pv *= _ScreenParams.xy;
25 // The camera only sees a small portion of the sphere, limited by hFoV and vFoV.
26 // Therefore, we must rescale again (before quantization), roughly, by 1/tan(FoV/2).
27 pv *= UNITY_MATRIX_P._m00_m11;
28 // Truncate and quantize.
29 fadeMaskSeed = asuint((int2)pv);
30 }
31 else
32#endif
33 {
34 // Can't use the view direction, it is the same across the entire screen.
35 fadeMaskSeed = positionSS;
36 }
37
38 return fadeMaskSeed;
39}
40#endif
41void LODDitheringTransitionSG_float(float3 viewDirWS, float4 screenPos, out float multiplyAlpha)
42{
43#if !defined(SHADER_STAGE_RAY_TRACING)
44 float p = GenerateHashedRandomFloat(ComputeFadeMaskSeed(viewDirWS, screenPos.xy));
45 float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
46 multiplyAlpha = f < 0 ? 0.0f : 1.0f;
47#endif
48}
49void LODDitheringTransitionSG_half(float3 viewDirWS, float4 screenPos, out half halfAlpha)
50{
51#if !defined(SHADER_STAGE_RAY_TRACING)
52 float p = GenerateHashedRandomFloat(ComputeFadeMaskSeed(viewDirWS, screenPos.xy));
53 float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
54 float multiplyAlpha = f < 0 ? 0.0f : 1.0f;
55 halfAlpha = (half)multiplyAlpha;
56#endif
57}
58#endif