所以我有这个着色器,我试图使闪烁,所以我使发射值在0和1之间来回,但它只有在我点击材料或在编辑器中滚动时才有效。我想不出来,请帮忙吗?
我检查了类似的东西,但它仍然无效,所以请帮助。
Renderer renderer;
Material material;
float emission;
// Use this for initialization
void Start () {
renderer = GetComponent<Renderer>();
material = renderer.material;
}
// Update is called once per frame
void Update () {
emission = Mathf.PingPong (Time.time, 1f);
Color color = Color.red;
Color finalColor = color * Mathf.LinearToGammaSpace (emission);
material.SetColor ("_EmissionColor", finalColor);
}
答案 0 :(得分:0)
尝试Mathf.sin(Time.time)来获得pingpong可能是你的问题解决了
或 使用blow shader
Shader "Custom/Emition" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_EmissionColor ("Bright", Float) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float _EmissionColor;
sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
output.uv = input.texcoord;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
fixed4 c = tex2D (_MainTex , input.uv) ;
/// change blow line
return c* float4(_EmissionColor,1,1,1);
}
ENDCG
}
}
FallBack "Diffuse"
}