UE5 动态扫描波

发布于:2025-08-02 ⋅ 阅读:(15) ⋅ 点赞:(0)

UE5自定义mesh,自定义材质实现动态扫描效果。

一、效果

二、实现

一、创建mesh

二、创建材质

三、着色器代码

float4 rgb = float4(baseColor.x,baseColor.y,baseColor.z,0.3);
{
    float startLength = frac(time/1.0)*radius;//[0.1,0.9]
    float endLength = startLength+width;
    float halfWidth = (endLength - startLength)/2.0;
    float curLength = length(pos.xy);
    float centerLength = startLength + halfWidth;

    if(curLength > startLength && curLength < endLength)
    {

        float disToCenter = abs(curLength-centerLength);
        return  lerp(rgb,baseColor,disToCenter / halfWidth);
    }
}

{
    float startLength = frac(time/1.0+0.2)*radius;//[0.1,0.9]
    float endLength = startLength+width;
    float halfWidth = (endLength - startLength)/2.0;
    float curLength = length(pos.xy);
    float centerLength = startLength + halfWidth;

    if(curLength > startLength && curLength < endLength)
    {
        float disToCenter = abs(curLength-centerLength);
        return  lerp(rgb,baseColor,disToCenter / halfWidth);
    }
}

{
    float startLength = frac(time/1.0+0.4)*radius;//[0.1,0.9]
    float endLength = startLength+width;
    float halfWidth = (endLength - startLength)/2.0;
    float curLength = length(pos.xy);
    float centerLength = startLength + halfWidth;

    if(curLength > startLength && curLength < endLength)
    {
        float disToCenter = abs(curLength-centerLength);
        return  lerp(rgb,baseColor,disToCenter / halfWidth);
    }
}

{
    float startLength = frac(time/1.0+0.6)*radius;//[0.1,0.9]
    float endLength = startLength+width;
    float halfWidth = (endLength - startLength)/2.0;
    float curLength = length(pos.xy);
    float centerLength = startLength + halfWidth;

    if(curLength > startLength && curLength < endLength)
    {
        float disToCenter = abs(curLength-centerLength);
        return  lerp(rgb,baseColor,disToCenter / halfWidth);
    }
}

{
    float startLength = frac(time/1.0+0.8)*radius;//[0.1,0.9]
    float endLength = startLength+width;
    float halfWidth = (endLength - startLength)/2.0;
    float curLength = length(pos.xy);
    float centerLength = startLength + halfWidth;

    if(curLength > startLength && curLength < endLength)
    {
        float disToCenter = abs(curLength-centerLength);
        return  lerp(rgb,baseColor,disToCenter / halfWidth);
    }
}


return  baseColor;