Skip to content

Instantly share code, notes, and snippets.

@thelucre
Last active March 17, 2017 02:12
Show Gist options
  • Save thelucre/889ee4cd257ea5f79580f27246455785 to your computer and use it in GitHub Desktop.
Save thelucre/889ee4cd257ea5f79580f27246455785 to your computer and use it in GitHub Desktop.
Color Shader
Shader "Custom/Color" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
}
SubShader {
Pass {
CGPROGRAM
// Our two programs
#pragma vertex vert
#pragma fragment frag
// vertex shader
float4 vert (float4 vertex : POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, vertex);
}
// color from the material
fixed4 _Color;
// pixel shader, no inputs needed
fixed4 frag () : SV_Target
{
return _Color; // just return it
}
ENDCG
}
}
FallBack "Diffuse"
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorShaderScript : ShaderBaseScript {
void Update()
{
mat.SetColor("_Color", Color.white * new Vector4(
0.5f * Mathf.Sin(Time.timeSinceLevelLoad) + 0.5f,
0.5f * -Mathf.Sin(Time.timeSinceLevelLoad) + 0.5f,
0.5f * Mathf.Cos(Time.timeSinceLevelLoad) + 0.5f,
1)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment