Advertisement
netgrind

Unity simple gradient shader

Apr 26th, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. Shader "Custom/Gradient" {
  2.     Properties {
  3.         _direction("Direction",Range(0,1)) = 0
  4.         _color1 ("Color 1", Color) = (1,.5,.5,1)
  5.         _color2 ("Color 2", Color) = (.5,1,1,1)
  6.     }
  7.     SubShader {
  8.         Pass{
  9.        
  10.             CGPROGRAM
  11.             #pragma vertex vert
  12.             #pragma fragment frag
  13.  
  14.             float4 _color1;
  15.             float4 _color2;
  16.             float4 _finalColor;
  17.             float _direction;
  18.            
  19.             struct appdata {
  20.                 float4 vertex : POSITION;
  21.                 float4 tex : TEXCOORD0;
  22.                 float3 normal : NORMAL;
  23.             };
  24.             struct v2f {
  25.                 float4 vertex : TEXCOORD;
  26.                 float4 pos : POSITION;
  27.                 float4 color : COLOR;
  28.             };
  29.             v2f vert(appdata v) {
  30.                 v2f o;
  31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  32.                 o.vertex = v.tex;
  33.                 return o;
  34.             };
  35.             half4 frag(v2f i) : COLOR {
  36.                 _finalColor.a = 1;
  37.                 _finalColor.r = ((_color1.r*i.vertex.y*_direction+_color1.r*i.vertex.x*(1-_direction))+(_color2.r*(1-i.vertex.y)*_direction+_color2.r*(1-i.vertex.x)*(1-_direction)));
  38.                 _finalColor.g = ((_color1.g*i.vertex.y*_direction+_color1.g*i.vertex.x*(1-_direction))+(_color2.g*(1-i.vertex.y)*_direction+_color2.g*(1-i.vertex.x)*(1-_direction)));
  39.                 _finalColor.b = ((_color1.b*i.vertex.y*_direction+_color1.b*i.vertex.x*(1-_direction))+(_color2.b*(1-i.vertex.y)*_direction+_color2.b*(1-i.vertex.x)*(1-_direction)));
  40.                 return _finalColor;
  41.             };
  42.  
  43.             ENDCG
  44.         }
  45.     }
  46.     FallBack "Diffuse"
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement