Files
cocos4/editor/assets/chunks/common/graph-expression/base.chunk
T

36 lines
1.0 KiB
Plaintext

// base coordinates & color expressions for shader-graph
// fraction is saturation percentage, 0 means gray
vec3 Desaturation(vec3 color, float fraction)
{
vec3 gray = vec3(dot(color, GRAY_VECTOR));
return mix(color, gray, fraction);
}
vec2 Rotator(vec2 uv, vec2 centerUV, float time, float speed)
{
uv -= centerUV;
vec3 dir = vec3(uv.x, 0.0, uv.y);
float dirLength = length(dir);
dir /= dirLength + EPSILON;
dir = RotationVecFromAxisY(dir, time * speed) * dirLength;
return vec2(dir.x, dir.z) + centerUV;
}
// return 0.0 when out of range
// hardness: 0 - 1
float SphereMask(vec2 center, vec2 point, float radius, float hardness)
{
float length = length(center - point);
float coef = pow(saturate(length / radius), saturate(1.0 - hardness));
return length > radius ? 0.0 : coef;
}
float SphereMask(vec3 center, vec3 point, float radius, float hardness)
{
float length = length(center - point);
float coef = pow(saturate(length / radius), saturate(1.0 - hardness));
return length > radius ? 0.0 : coef;
}