Distortion.hlsl 925 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef UNITY_POSTFX_DISTORTION
  2. #define UNITY_POSTFX_DISTORTION
  3. float4 _Distortion_Amount;
  4. float4 _Distortion_CenterScale;
  5. float2 Distort(float2 uv)
  6. {
  7. // Note: lens distortion is automatically disabled in VR so we won't bother handling stereo uvs
  8. #if DISTORT
  9. {
  10. uv = (uv - 0.5) * _Distortion_Amount.z + 0.5;
  11. float2 ruv = _Distortion_CenterScale.zw * (uv - 0.5 - _Distortion_CenterScale.xy);
  12. float ru = length(float2(ruv));
  13. UNITY_BRANCH
  14. if (_Distortion_Amount.w > 0.0)
  15. {
  16. float wu = ru * _Distortion_Amount.x;
  17. ru = tan(wu) * (1.0 / (ru * _Distortion_Amount.y));
  18. uv = uv + ruv * (ru - 1.0);
  19. }
  20. else
  21. {
  22. ru = (1.0 / ru) * _Distortion_Amount.x * atan(ru * _Distortion_Amount.y);
  23. uv = uv + ruv * (ru - 1.0);
  24. }
  25. }
  26. #endif
  27. return uv;
  28. }
  29. #endif // UNITY_POSTFX_DISTORTION