ShaderGraph——石化

1、石化

原理:模型主贴图,逐渐过渡到石化图——“逐渐过渡”节点是Lerp,再用Slider节点控制插值,即可实现石化的过程
在这里插入图片描述
请添加图片描述

2、代码设置变量,控制石化进程

把Slider节点,转为属性,并将其在代码中的名称定义为_StoneAnim,场景运行时,我们每按一下A键,让_StoneAnim自加0.1f
转属性
在这里插入图片描述

代码控制

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StoneProgressControl : MonoBehaviour
{
    
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        
    }

    // Update is called once per frame
    void Update()
    {
    
    
        if(Input.GetKeyDown(KeyCode.A))
        {
    
    
            Material mat = GetComponent<Renderer>().material;
            mat.SetFloat("_StoneAnim", mat.GetFloat("_StoneAnim")+0.1f);
        }
    }
}

Material类型变量,可以重构到Start里

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StoneProgressControl : MonoBehaviour
{
    
    
    private Material mat;

    // Start is called before the first frame update
    void Start()
    {
    
    
         mat = GetComponent<Renderer>().material;
    }

    // Update is called once per frame
    void Update()
    {
    
    
        if(Input.GetKeyDown(KeyCode.A))
        {
    
    
            
            mat.SetFloat("_StoneAnim", mat.GetFloat("_StoneAnim")+0.1f);
        }
    }
}

3、修改ShaderGraph的路径,以便让Shader的分类看起来更整洁

它默认是在
在这里插入图片描述
在这里插入图片描述
我们自定义
在这里插入图片描述
在这里插入图片描述

4、效果动图

请添加图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42935398/article/details/124923542