A game about forced loneliness, made by TACStudios
1
2// These functions are use to hide the handling of triplanar mapping
3// Normal need a specific treatment as they use special encoding for both base and detail map
4// Also we use multiple inclusion to handle the various variation for lod and bias
5
6// param can be unused, lod or bias
7real4 ADD_FUNC_SUFFIX(SampleUVMapping)(TEXTURE2D_PARAM(textureName, samplerName), UVMapping uvMapping, real param)
8{
9 if (uvMapping.mappingType == UV_MAPPING_TRIPLANAR)
10 {
11 real3 triplanarWeights = uvMapping.triplanarWeights;
12 real4 val = real4(0.0, 0.0, 0.0, 0.0);
13
14 if (triplanarWeights.x > 0.0)
15 val += triplanarWeights.x * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvZY, param);
16 if (triplanarWeights.y > 0.0)
17 val += triplanarWeights.y * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXZ, param);
18 if (triplanarWeights.z > 0.0)
19 val += triplanarWeights.z * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXY, param);
20
21 return val;
22 }
23 else // UV_MAPPING_UVSET / UV_MAPPING_PLANAR
24 {
25 return SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param);
26 }
27}
28
29// Nested multiple includes of the file to handle all variations of normal map (AG, RG or RGB)
30
31// This version is use for the base normal map (BC5 or DXT5nm)
32#define ADD_NORMAL_FUNC_SUFFIX(Name) Name
33#if defined(UNITY_ASTC_NORMALMAP_ENCODING)
34#define UNPACK_NORMAL_FUNC UnpackNormalAG
35#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG
36#elif defined(UNITY_NO_DXT5nm)
37#define UNPACK_NORMAL_FUNC UnpackNormalRGB
38#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGB
39#else
40#define UNPACK_NORMAL_FUNC UnpackNormalmapRGorAG
41#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGorAG
42#endif
43#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingNormalInternal.hlsl"
44#undef ADD_NORMAL_FUNC_SUFFIX
45#undef UNPACK_NORMAL_FUNC
46#undef UNPACK_DERIVATIVE_FUNC
47
48// This version is for normalmap with AG encoding only. Use with details map encoded with others properties (like smoothness).
49#define ADD_NORMAL_FUNC_SUFFIX(Name) MERGE_NAME(Name, AG)
50#define UNPACK_NORMAL_FUNC UnpackNormalAG
51#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG
52#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingNormalInternal.hlsl"
53#undef ADD_NORMAL_FUNC_SUFFIX
54#undef UNPACK_NORMAL_FUNC
55#undef UNPACK_DERIVATIVE_FUNC
56
57// This version is for normalmap with RGB encoding only, i.e uncompress or BC7.
58#define ADD_NORMAL_FUNC_SUFFIX(Name) MERGE_NAME(Name, RGB)
59#define UNPACK_NORMAL_FUNC UnpackNormalRGB
60#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGB
61#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingNormalInternal.hlsl"
62#undef ADD_NORMAL_FUNC_SUFFIX
63#undef UNPACK_NORMAL_FUNC
64#undef UNPACK_DERIVATIVE_FUNC