着色器和纹理根据方向滚动

Shader and Texture Scrolling depending on Direction

我试图在 Unity 中使用它的 uv 滚动纹理,但我没有得到我需要的结果。

目标是有两个组成部分,速度和方向。我想用标准化值定义方向,速度应该根据方向影响滚动速度。

如果我在运行时更改速度,我不想出现一些问题,但也许这不应该由 GPU 处理。

我怎样才能更好地做到这一点,也许使用矩阵?

这是一个例子,但结果不如预期。

uv.xy = uv.xy + frac(_Time.y * float2(_Direction.x, _Direction.y));

希望我正确理解了你的问题。在属性中定义三个变量怎么样:

fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
sampler2D _Texture

然后在 surf() 中你应该这样做:

void surf(Input IN, inout SurfaceOutput o)
{
    fixed2 scrolledUV = IN._Texture;

    fixed xScrollValue = _ScrollXSpeed * _Time;
    fixed yScrollValue = _ScrollYSpeed * _Time;

    //Apply offset
    scrolledUV += fixed2(xScrollValue, yScrollValue);

    half4 c = tex2D(_Texture, scrolledUV);
    o.Albedo = c.rgb;
    o.Alpha = c.a;
}