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