gpt4 book ai didi

unity-game-engine - 在 Unity Shaderlab 中,如何使用 lerp 和 deltaTime 为某个值设置动画

转载 作者:行者123 更新时间:2023-12-02 21:21:09 24 4
gpt4 key购买 nike

如何使用自定义标准表面着色器将值设置为目标值的动画?

例如:

...
float targetAlpha; //Set by the property block, or a C# script
float currrentAlpha; //Used internally only.

void surf (Input IN, inout SurfaceOutputStandard o)
{
currrentAlpha = lerp(currrentAlpha, targetAlpha, unity_DeltaTime.x);

o.Alpha = currrentAlpha;
}

此代码不起作用,但应该演示目标是什么:设置 targetAlpha 时,着色器将逐渐淡入该值。

最佳答案

有几种方法可以做到这一点。其中之一是使用内置着色器变量:

    Shader "Custom/Test" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_TargetAlpha ("TargetAlpha", Range(0, 1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows alpha:fade

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

sampler2D _MainTex;

struct Input {
float2 uv_MainTex;
};

half _Alpha;
fixed4 _Color;
half _TargetAlpha;


void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = lerp(o.Alpha, _TargetAlpha, clamp(_SinTime.w, 0, 1));
}
ENDCG
}
FallBack "Diffuse"
}

关于unity-game-engine - 在 Unity Shaderlab 中,如何使用 lerp 和 deltaTime 为某个值设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com