Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fixed4 c = lerp(_ColorA, _ColorB, tex.y / _Middle) * step(tex.y, _Middle);
- c += lerp(_ColorB, _ColorC, (tex.y - _Middle) / (1 - _Middle)) * step(_Middle, tex.y);
- private Texture2D _tex; //Texture that will go into the shader
- private Renderer _rend; //Renderer of the object
- private void Awake () {
- _rend = this.GetComponent<Renderer> ();
- //create new texture, width == amount of colors
- _tex = new Texture2D (4, 1);
- //Set each pixel to specified color (StarGradient is function below)
- _tex.SetPixels32 (StarGradient (
- new Color32 (255, 186, 0, 1),
- new Color32 (224, 100, 45, 1),
- new Color32 (118, 73, 41, 1),
- new Color32 (60, 73, 55, 1))
- );
- _tex.filterMode = FilterMode.Trilinear;
- _tex.wrapMode = TextureWrapMode.Clamp;
- _tex.Apply ();
- //Pass _tex to the material
- _rend.material.SetTexture ("_RampTex", _tex);
- }
- //Returns a Color32 array of specified colors
- private Color32[] StarGradient(Color32 a, Color32 b, Color32 c, Color32 d) {
- Color32[] _colors = new Color32[4];
- _colors [0] = a;
- _colors [1] = b;
- _colors [2] = c;
- _colors [3] = d;
- return _colors;
- }
- private void Awake () {
- _rend = this.GetComponent<Renderer> ();
- //create new texture, width == amount of colors
- _tex = new Texture2D (4, 1);
- //Set each pixel to specified color (StarGradient is function below)
- _tex.SetPixels32 (StarGradient (
- new Color32 (255, 186, 0, 1),
- new Color32 (224, 100, 45, 1),
- new Color32 (118, 73, 41, 1),
- new Color32 (60, 73, 55, 1))
- );
- _tex.filterMode = FilterMode.Trilinear;
- _tex.wrapMode = TextureWrapMode.Clamp;
- _tex.Apply ();
- //Pass _tex to the material
- _rend.material.SetTexture ("_RampTex", _tex);
- }
- //Returns a Color32 array of specified colors
- private Color32[] StarGradient(Color32 a, Color32 b, Color32 c, Color32 d) {
- Color32[] _colors = new Color32[4];
- _colors [0] = a;
- _colors [1] = b;
- _colors [2] = c;
- _colors [3] = d;
- return _colors;
- }
- SubShader {
- Tags {"Queue"="Background" "IgnoreProjector"="True"}
- LOD 100
- ZWrite On
- Pass {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- fixed4 _ColorTop;
- fixed4 _ColorMidTop;
- fixed4 _ColorMidBot;
- fixed4 _ColorBot;
- float _MiddleBot;
- float _MiddleTop;
- struct v2f {
- float4 pos : SV_POSITION;
- float4 texcoord : TEXCOORD0;
- };
- v2f vert (appdata_full v) {
- v2f o;
- o.pos = UnityObjectToClipPos (v.vertex);
- o.texcoord = v.texcoord;
- return o;
- }
- fixed4 frag (v2f i) : COLOR {
- fixed4 c = lerp(_ColorBot, _ColorMidBot, i.texcoord.y / _MiddleBot) * step(i.texcoord.y, _MiddleBot);
- c += lerp(_ColorMidBot, _ColorMidTop, (i.texcoord.y - _MiddleBot) /(_MiddleTop - _MiddleBot) ) * step(_MiddleBot,i.texcoord.y) * step(i.texcoord.y,_MiddleTop);
- c += lerp(_ColorMidTop, _ColorTop, (i.texcoord.y - _MiddleTop) / (1 - _MiddleTop)) * step(_MiddleTop, i.texcoord.y);
- c.a = 1;
- return c;
- }
- ENDCG
- }
- }
Add Comment
Please, Sign In to add comment