Advertisement
tonynogo

Demo 53 - Vertex color depending ID

Jul 6th, 2017
2,836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/VertexID"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _Val ("Value 1", Range(1, 50)) = 2
  7.         _Val2 ("Value 2", Range(1, 50)) = 7
  8.         _Val3 ("Value 3", Range(1, 50)) = 5
  9.         _Color1 ("Color 1", Color) = (1, 1, 1, 1)
  10.         _Color2 ("Color 2", Color) = (1, 1, 1, 1)
  11.         _Color3 ("Color 3", Color) = (1, 1, 1, 1)
  12.     }
  13.     SubShader
  14.     {
  15.         Tags { "RenderType"="Opaque" }
  16.  
  17.         Pass
  18.         {
  19.             CGPROGRAM
  20.             #pragma vertex vert
  21.             #pragma fragment frag
  22.             #include "UnityCG.cginc"
  23.            
  24.             struct v2f {
  25.                 float4 pos : SV_POSITION;
  26.                 float2 uv : TEXCOORD0;
  27.                 fixed4 col : COLOR0;
  28.             };
  29.            
  30.             sampler2D _MainTex;
  31.             float4 _MainTex_ST;
  32.             float _Val;
  33.             float _Val2;
  34.             float _Val3;
  35.             fixed4 _Color1;
  36.             fixed4 _Color2;
  37.             fixed4 _Color3;
  38.  
  39.             v2f vert(appdata_base v, uint id : SV_VERTEXID) {
  40.                 v2f o;
  41.                 o.pos = UnityObjectToClipPos(v.vertex);
  42.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  43.                 o.col = fixed4(1, 1, 1, 1);
  44.                 if(fmod(id, floor(_Val)) == 0)
  45.                     o.col *= _Color1;
  46.  
  47.                 if(fmod(id, floor(_Val2)) == 0)
  48.                     o.col *= _Color2;
  49.  
  50.                 if(fmod(id, floor(_Val3)) == 0)
  51.                     o.col *= _Color3;
  52.  
  53.                 return o;
  54.             }
  55.  
  56.             fixed4 frag(v2f i) : SV_Target {
  57.                 fixed4 col = tex2D(_MainTex, i.uv);
  58.                 return i.col * col;
  59.             }
  60.            
  61.             ENDCG
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement