30 lines
1.4 KiB
HLSL
30 lines
1.4 KiB
HLSL
// SPDX-License-Identifier: (Not available for this version, you are only allowed to use this software if you have express permission from the copyright holder and agreed to the latest NiloToonURP EULA)
|
|
// Copyright (c) 2021 Kuroneko ShaderLab Limited
|
|
|
|
// For more information, visit -> https://github.com/ColinLeung-NiloCat/UnityURPToonLitShaderExample
|
|
|
|
// using
|
|
// https://github.com/ronja-tutorials/ShaderTutorials/blob/master/Assets/047_InverseInterpolationAndRemap/Interpolation.cginc
|
|
// but edit float to half for optimization, because we usually use this to process color data(half)
|
|
|
|
// #pragma once is a safe guard best practice in almost every .hlsl,
|
|
// doing this can make sure your .hlsl's user can include this .hlsl anywhere anytime without producing any multi include conflict
|
|
#pragma once
|
|
|
|
// just like smoothstep(), but linear, not clamped
|
|
half invLerp(half from, half to, half value)
|
|
{
|
|
return (value - from) / (to - from); // TODO: this line will produce "floating point division by zero" warning, but we don't want to fix it because it is slower
|
|
}
|
|
// just like smoothstep(), but linear
|
|
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);
|
|
}
|