80 lines
2.0 KiB
HLSL
80 lines
2.0 KiB
HLSL
#ifndef _GRADIENTDISSOLVE
|
|
#define _GRADIENTDISSOLVE
|
|
|
|
half3 MergeColors(half3 background, half3 sample, half minB, half maxB)
|
|
{
|
|
half3 _out = background;
|
|
sample = lerp(minB, maxB, sample);
|
|
if (sample.r < 0.5)
|
|
{
|
|
_out.r *= sample.r*2;
|
|
}
|
|
else
|
|
{
|
|
_out.r += (sample.r-0.5)*2;
|
|
}
|
|
if (sample.g < 0.5)
|
|
{
|
|
_out.g *= sample.g*2;
|
|
}
|
|
else
|
|
{
|
|
_out.g += (sample.g-0.5)*2;
|
|
}
|
|
if (sample.b < 0.5)
|
|
{
|
|
_out.b *= sample.b*2;
|
|
}
|
|
else
|
|
{
|
|
_out.b += (sample.b-0.5)*2;
|
|
}
|
|
return _out;
|
|
|
|
}
|
|
|
|
void GradientedDissolve_float(
|
|
UnityTexture2D NoiseTexture, UnityTexture2D BaseTexture, UnityTexture2D GUITexture,
|
|
UnitySamplerState NoiseSS,
|
|
half2 UV, half2 UV2,
|
|
half3 OffsetColor,
|
|
half NoisePow, half Width, half Th,
|
|
half MinBrightness, half MaxBrightness,
|
|
out half4 _out
|
|
)
|
|
{
|
|
_out = SAMPLE_TEXTURE2D(BaseTexture, NoiseSS, UV);
|
|
|
|
half noise = SAMPLE_TEXTURE2D(NoiseTexture, NoiseSS, UV).r;
|
|
noise = pow(noise, NoisePow);
|
|
noise = noise * (1-UV.x);
|
|
noise += Th;
|
|
bool inRange = UV2.x >= 0.0 && UV2.x <= 1.0 && UV2.y >= 0.0 && UV2.y <= 1.0;
|
|
|
|
if (inRange)
|
|
{
|
|
half3 guiSample = SAMPLE_TEXTURE2D_LOD(GUITexture, NoiseSS, UV2, 0).xyz;
|
|
half3 guiSampleLow = SAMPLE_TEXTURE2D_LOD(GUITexture, NoiseSS, UV2, 3).xyz;
|
|
if (noise > 1.0)
|
|
{
|
|
noise = 1.0;
|
|
//_out.xyz = _out.xyz * (guiSample+OffsetColor);
|
|
_out.xyz = MergeColors(_out.xyz, guiSample, MinBrightness, MaxBrightness);
|
|
}
|
|
else if ((noise + Width ) > 1.0)
|
|
{
|
|
noise = (noise + Width - 1.0)/Width;
|
|
float3 gui = lerp(guiSampleLow, guiSampleLow, noise);
|
|
//float3 full = _out.xyz * gui;
|
|
float3 full = MergeColors(_out.xyz, guiSample, MinBrightness, MaxBrightness);
|
|
_out.xyz = lerp(_out, full, noise);
|
|
}
|
|
else {
|
|
noise = 0.0;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|