SampleUVMappingInternal.hlsl 2.7 KB

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