forked from ColinLeung-NiloCat/UnityURPToonLitShaderExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNiloInvLerpRemap.hlsl
More file actions
22 lines (20 loc) · 774 Bytes
/
NiloInvLerpRemap.hlsl
File metadata and controls
22 lines (20 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// https://github.com/ronja-tutorials/ShaderTutorials/blob/master/Assets/047_InverseInterpolationAndRemap/Interpolation.cginc
// edit float to half for optimization, because we usually use this to process color data(half)
#ifndef Include_NiloInvLerpRemap
#define Include_NiloInvLerpRemap
// just like smoothstep(), but linear, not clamped
half invLerp(half from, half to, half value)
{
return (value - from) / (to - from);
}
half invLerpClamp(half from, half to, half value)
{
return saturate(invLerp(from,to,value));
}
// full control remap, but slower
half remap(half origFrom, half origTo, half targetFrom, half targetTo, half value)
{
half rel = invLerp(origFrom, origTo, value);
return lerp(targetFrom, targetTo, rel);
}
#endif