几何变换_流光效果
2020-07-01 本文已影响0人
Rayson
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
}
}
}