简体   繁体   中英

Unity Shader Graph: How to speed up time from Time node?

I'm trying to use Sine Time output from Time node but I want it to be faster.

If this is done in a Unity c#, I would try to something like this

totalTime += Time.deltaTime * speed;

value = Mathf.PingPong(totalTime, 1);

but I can't do this in Shader Graph. How to solve this problem?

EDIT1: I also try to create custom node fuction but this will result in error.

static string PingPongFunction(
    [Slot(0, Binding.None)] Vector1 t,
    [Slot(1, Binding.None)] Vector1 length,
    [Slot(2, Binding.None)] out Vector1 Out)
{
    return
        @"
            {
                Out = Mathf.PingPong(t, length);
            }
        ";
}

Feed time as x to sin(x) and multiply time with a number to speed it up.

在此处输入图片说明

I would do it like this pass your time into A on the multiply node and then you can either manually set B to 2 to go twice as fast or add a new vector1 property so you can change it from the inspector.

着色器图示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM