Guest User

Untitled

a guest
Jun 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. fixed4 c = lerp(_ColorA, _ColorB, tex.y / _Middle) * step(tex.y, _Middle);
  2. c += lerp(_ColorB, _ColorC, (tex.y - _Middle) / (1 - _Middle)) * step(_Middle, tex.y);
  3.  
  4. private Texture2D _tex; //Texture that will go into the shader
  5. private Renderer _rend; //Renderer of the object
  6.  
  7. private void Awake () {
  8. _rend = this.GetComponent<Renderer> ();
  9.  
  10. //create new texture, width == amount of colors
  11. _tex = new Texture2D (4, 1);
  12.  
  13. //Set each pixel to specified color (StarGradient is function below)
  14. _tex.SetPixels32 (StarGradient (
  15. new Color32 (255, 186, 0, 1),
  16. new Color32 (224, 100, 45, 1),
  17. new Color32 (118, 73, 41, 1),
  18. new Color32 (60, 73, 55, 1))
  19. );
  20. _tex.filterMode = FilterMode.Trilinear;
  21. _tex.wrapMode = TextureWrapMode.Clamp;
  22. _tex.Apply ();
  23.  
  24. //Pass _tex to the material
  25. _rend.material.SetTexture ("_RampTex", _tex);
  26. }
  27.  
  28. //Returns a Color32 array of specified colors
  29. private Color32[] StarGradient(Color32 a, Color32 b, Color32 c, Color32 d) {
  30. Color32[] _colors = new Color32[4];
  31. _colors [0] = a;
  32. _colors [1] = b;
  33. _colors [2] = c;
  34. _colors [3] = d;
  35. return _colors;
  36. }
  37.  
  38. private void Awake () {
  39. _rend = this.GetComponent<Renderer> ();
  40.  
  41. //create new texture, width == amount of colors
  42. _tex = new Texture2D (4, 1);
  43.  
  44. //Set each pixel to specified color (StarGradient is function below)
  45. _tex.SetPixels32 (StarGradient (
  46. new Color32 (255, 186, 0, 1),
  47. new Color32 (224, 100, 45, 1),
  48. new Color32 (118, 73, 41, 1),
  49. new Color32 (60, 73, 55, 1))
  50. );
  51. _tex.filterMode = FilterMode.Trilinear;
  52. _tex.wrapMode = TextureWrapMode.Clamp;
  53. _tex.Apply ();
  54.  
  55. //Pass _tex to the material
  56. _rend.material.SetTexture ("_RampTex", _tex);
  57. }
  58.  
  59. //Returns a Color32 array of specified colors
  60. private Color32[] StarGradient(Color32 a, Color32 b, Color32 c, Color32 d) {
  61. Color32[] _colors = new Color32[4];
  62. _colors [0] = a;
  63. _colors [1] = b;
  64. _colors [2] = c;
  65. _colors [3] = d;
  66. return _colors;
  67. }
  68.  
  69. SubShader {
  70. Tags {"Queue"="Background" "IgnoreProjector"="True"}
  71. LOD 100
  72.  
  73. ZWrite On
  74.  
  75. Pass {
  76. CGPROGRAM
  77. #pragma vertex vert
  78. #pragma fragment frag
  79. #include "UnityCG.cginc"
  80.  
  81. fixed4 _ColorTop;
  82. fixed4 _ColorMidTop;
  83. fixed4 _ColorMidBot;
  84. fixed4 _ColorBot;
  85.  
  86. float _MiddleBot;
  87. float _MiddleTop;
  88.  
  89. struct v2f {
  90. float4 pos : SV_POSITION;
  91. float4 texcoord : TEXCOORD0;
  92. };
  93.  
  94. v2f vert (appdata_full v) {
  95. v2f o;
  96. o.pos = UnityObjectToClipPos (v.vertex);
  97. o.texcoord = v.texcoord;
  98. return o;
  99. }
  100.  
  101. fixed4 frag (v2f i) : COLOR {
  102.  
  103. fixed4 c = lerp(_ColorBot, _ColorMidBot, i.texcoord.y / _MiddleBot) * step(i.texcoord.y, _MiddleBot);
  104. c += lerp(_ColorMidBot, _ColorMidTop, (i.texcoord.y - _MiddleBot) /(_MiddleTop - _MiddleBot) ) * step(_MiddleBot,i.texcoord.y) * step(i.texcoord.y,_MiddleTop);
  105. c += lerp(_ColorMidTop, _ColorTop, (i.texcoord.y - _MiddleTop) / (1 - _MiddleTop)) * step(_MiddleTop, i.texcoord.y);
  106. c.a = 1;
  107.  
  108. return c;
  109. }
  110. ENDCG
  111. }
  112. }
Add Comment
Please, Sign In to add comment