Unity Shader实现图像渐变

Unity Shader实现图像渐变

写在前面

使用Shader实现图像渐变

效果

在这里插入图片描述

方法

(1)使用Shader里的combine src1 lerp(src2) scr3
其中src1是指图片1,src3是图片2。渐变效果由src2的A通道决定,当其值越接近0,就使用src3,其值越接近1,就使用src1

//渲染纹理和固定颜色合并
SetTexture[_MainTexture]
{
    
    
    //声明了固定颜色
    ConstantColor[_ConstantColor]
    combine texture + constant quad
}
SetTexture[_PreviousTexture]
{
    
    
    combine texture + previous    
} 

(2)然后使用C#的material.SetTexture方法去设置Shader中的src1src3

image.material.SetTexture("_Texture"+indexPos,texture);

代码

项目地址:

https://github.com/hahahappyboy/UnityProjects/tree/main/ShaderLerp

写在后面

听说国家队要出第二季,这是真的吗?!!
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/iiiiiiimp/article/details/127170580