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

写在后面

听说国家队要出第二季,这是真的吗?!!
Unity Shader实现图像渐变_第1张图片

你可能感兴趣的:(游戏,Unity,unity,c#,游戏引擎)