美文网首页
几何变换_流光效果

几何变换_流光效果

作者: Rayson | 来源:发表于2020-07-01 14:58 被阅读0次

    C#

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class SetFloat : MonoBehaviour {
    
        // Use this for initialization
    
        private float dis = -1;
        private float r = 0.1f;
        void Start () {
            
        }
        
        // Update is called once per frame
        void Update () {
            dis+= Time.deltaTime*0.1f;
            GetComponent<Renderer> ().material.SetFloat("dis", dis);
            GetComponent<Renderer> ().material.SetFloat("r", r);
        }
    }
    
    

    Shader

    
    Shader "Unlit/V2f34"
    {
        SubShader{
                pass{
                    
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
    
                float dis; //动态范围
                float r;    //动态半径
    
                struct a2v
                {
                     float4 vertex : POSITION;
                };
    
    
                struct v2f {                
                    float4 pos:POSITION;
                    float4 color:COLOR;
                };          
    
                v2f vert(appdata_base v )
                    {
                        v2f o;
    
                        o.pos= UnityObjectToClipPos(v.vertex);      
    
                            float x= o.pos.x / o.pos.w;
                            if(x > dis && x < dis + r)
                                o.color=fixed4(1,0,0,1);
                            else if(x>1)
                                o.color=fixed4(0,0,1,1);
                            else
                                o.color = fixed4(x/2+0.5,x/2+0.5,x/2+0.5,1);
    
                        return o; 
                    }   
    
                fixed frag(v2f i):SV_TARGET
                    {
                        return i.color;
                    }
                ENDCG
                }
        }
        
    }
    
    

    相关文章

      网友评论

          本文标题:几何变换_流光效果

          本文链接:https://www.haomeiwen.com/subject/xxacqktx.html