SampleUVMapping.hlsl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // This structure abstract uv mapping inside one struct.
  2. // It represent a mapping of any uv (with its associated tangent space for derivative if SurfaceGradient mode) - UVSet0 to 4, planar, triplanar
  3. #ifndef __SAMPLEUVMAPPING_HLSL__
  4. #define __SAMPLEUVMAPPING_HLSL__
  5. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
  6. #define UV_MAPPING_UVSET 0
  7. #define UV_MAPPING_PLANAR 1
  8. #define UV_MAPPING_TRIPLANAR 2
  9. struct UVMapping
  10. {
  11. int mappingType;
  12. float2 uv; // Current uv or planar uv
  13. // Triplanar specific
  14. float2 uvZY;
  15. float2 uvXZ;
  16. float2 uvXY;
  17. float3 normalWS; // vertex normal
  18. float3 triplanarWeights;
  19. #ifdef SURFACE_GRADIENT
  20. // tangent basis to use when mappingType is UV_MAPPING_UVSET
  21. // these are vertex level in world space
  22. float3 tangentWS;
  23. float3 bitangentWS;
  24. // TODO: store also object normal map for object triplanar
  25. #endif
  26. };
  27. // Multiple includes of the file to handle all variations of textures sampling for regular, lod and bias
  28. // Regular sampling functions
  29. #define ADD_FUNC_SUFFIX(Name) Name
  30. #define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, unused) SAMPLE_TEXTURE2D(textureName, samplerName, uvMapping)
  31. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingInternal.hlsl"
  32. #undef ADD_FUNC_SUFFIX
  33. #undef SAMPLE_TEXTURE_FUNC
  34. // Lod sampling functions
  35. #define ADD_FUNC_SUFFIX(Name) MERGE_NAME(Name, Lod)
  36. #define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, uvMapping, lod)
  37. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingInternal.hlsl"
  38. #undef ADD_FUNC_SUFFIX
  39. #undef SAMPLE_TEXTURE_FUNC
  40. // Bias sampling functions
  41. #define ADD_FUNC_SUFFIX(Name) MERGE_NAME(Name, Bias)
  42. #define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, bias) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, uvMapping, bias)
  43. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/SampleUVMappingInternal.hlsl"
  44. #undef ADD_FUNC_SUFFIX
  45. #undef SAMPLE_TEXTURE_FUNC
  46. // Macro to improve readibility of surface data
  47. #define SAMPLE_UVMAPPING_TEXTURE2D(textureName, samplerName, uvMapping) SampleUVMapping(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, 0.0) // Last 0.0 is unused
  48. #define SAMPLE_UVMAPPING_TEXTURE2D_LOD(textureName, samplerName, uvMapping, lod) SampleUVMappingLod(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, lod)
  49. #define SAMPLE_UVMAPPING_TEXTURE2D_BIAS(textureName, samplerName, uvMapping, bias) SampleUVMappingBias(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, bias)
  50. #define SAMPLE_UVMAPPING_NORMALMAP(textureName, samplerName, uvMapping, scale) SampleUVMappingNormal(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, 0.0)
  51. #define SAMPLE_UVMAPPING_NORMALMAP_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalLod(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, lod)
  52. #define SAMPLE_UVMAPPING_NORMALMAP_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalBias(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, bias)
  53. #define SAMPLE_UVMAPPING_NORMALMAP_AG(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalAG(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, 0.0)
  54. #define SAMPLE_UVMAPPING_NORMALMAP_AG_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalAGLod(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, lod)
  55. #define SAMPLE_UVMAPPING_NORMALMAP_AG_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalAGBias(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, bias)
  56. #define SAMPLE_UVMAPPING_NORMALMAP_RGB(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalRGB(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, 0.0)
  57. #define SAMPLE_UVMAPPING_NORMALMAP_RGB_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalRGBLod(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, lod)
  58. #define SAMPLE_UVMAPPING_NORMALMAP_RGB_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalRGBBias(TEXTURE2D_ARGS(textureName, samplerName), uvMapping, scale, bias)
  59. #endif //__SAMPLEUVMAPPING_HLSL__