No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DynamicScalingClamping.hlsl 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef UNITY_DYNAMIC_SCALING_CLAMPING_INCLUDED
  2. #define UNITY_DYNAMIC_SCALING_CLAMPING_INCLUDED
  3. // Functions to clamp UVs to use when RTHandle system is used.
  4. float2 ClampUV(float2 UV, float2 texelSize, float numberOfTexels, float2 scale)
  5. {
  6. float2 maxCoord = scale - numberOfTexels * texelSize;
  7. return min(UV, maxCoord);
  8. }
  9. float2 ClampUV(float2 UV, float2 texelSize, float numberOfTexels)
  10. {
  11. return ClampUV(UV, texelSize, numberOfTexels, _RTHandleScale.xy);
  12. }
  13. float2 ClampAndScaleUV(float2 UV, float2 texelSize, float numberOfTexels, float2 scale)
  14. {
  15. float2 maxCoord = 1.0f - numberOfTexels * texelSize;
  16. return min(UV, maxCoord) * scale;
  17. }
  18. float2 ClampAndScaleUV(float2 UV, float2 texelSize, float numberOfTexels)
  19. {
  20. return ClampAndScaleUV(UV, texelSize, numberOfTexels, _RTHandleScale.xy);
  21. }
  22. // This is assuming half a texel offset in the clamp.
  23. float2 ClampUVForBilinear(float2 UV, float2 texelSize)
  24. {
  25. return ClampUV(UV, texelSize, 0.5f);
  26. }
  27. float2 ClampUVForBilinear(float2 UV)
  28. {
  29. return ClampUV(UV, _ScreenSize.zw, 0.5f);
  30. }
  31. float2 ClampAndScaleUVForBilinear(float2 UV, float2 texelSize)
  32. {
  33. return ClampAndScaleUV(UV, texelSize, 0.5f);
  34. }
  35. // This is assuming full screen buffer and half a texel offset for the clamping.
  36. float2 ClampAndScaleUVForBilinear(float2 UV)
  37. {
  38. return ClampAndScaleUV(UV, _ScreenSize.zw, 0.5f);
  39. }
  40. float2 ClampAndScaleUVForPoint(float2 UV)
  41. {
  42. return min(UV, 1.0f) * _RTHandleScale.xy;
  43. }
  44. #endif