Advertisement
tonynogo

Demo 45 - Section

Jul 6th, 2017
7,572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Section" {
  2.  
  3.     Properties {
  4.         _Color1 ("Outside color", Color) = (1.0, 1.0, 1.0, 1.0)
  5.         _Color2 ("Section color", Color) = (1.0, 1.0, 1.0, 1.0)
  6.         _EdgeWidth ("Edge width", Range(0.9, 0.1)) = 0.9
  7.         _Val ("Height value", float) = 0
  8.     }
  9.  
  10.     SubShader {
  11.         Tags { "Queue"="Geometry" }
  12.  
  13.         //  PASS 1
  14.         CGPROGRAM
  15.         #pragma surface surf Standard
  16.  
  17.         struct Input {
  18.             float3 worldPos;
  19.         };
  20.  
  21.         fixed4 _Color1;
  22.         float _Val;
  23.  
  24.         void surf(Input IN, inout SurfaceOutputStandard o)
  25.         {
  26.             if(IN.worldPos.y > _Val)
  27.                 discard;
  28.             o.Albedo = _Color1;
  29.         }
  30.  
  31.         ENDCG
  32.  
  33.         //  PASS 2
  34.         Pass {
  35.  
  36.             Cull Front
  37.  
  38.             CGPROGRAM
  39.             #pragma vertex vert
  40.             #pragma fragment frag
  41.             #include "UnityCG.cginc"
  42.  
  43.             struct v2f {
  44.                 float4 pos : SV_POSITION;
  45.                 float4 worldPos : TEXCOORD0;
  46.             };
  47.  
  48.             v2f vert(appdata_base v)
  49.             {
  50.                 v2f o;
  51.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  52.                 o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  53.                 return o;
  54.             }
  55.  
  56.             fixed4 _Color2;
  57.             float _Val;
  58.  
  59.             fixed4 frag(v2f i) : SV_Target {
  60.                 if(i.worldPos.y > _Val)
  61.                     discard;
  62.  
  63.                 return _Color2;
  64.             }
  65.  
  66.             ENDCG
  67.         }
  68.  
  69.         //  PASS 3
  70.         Pass {
  71.             CGPROGRAM
  72.             #pragma vertex vert
  73.             #pragma fragment frag
  74.             #include "UnityCG.cginc"
  75.  
  76.             struct v2f {
  77.                 float4 pos : SV_POSITION;
  78.                 float4 worldPos : TEXCOORD0;
  79.             };
  80.  
  81.             float _EdgeWidth;
  82.  
  83.             v2f vert(appdata_base v)
  84.             {
  85.                 v2f o;
  86.                 v.vertex.xyz *= _EdgeWidth;
  87.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  88.                 o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  89.                 return o;
  90.             }
  91.  
  92.             fixed4 _Color2;
  93.             float _Val;
  94.  
  95.             fixed4 frag(v2f i) : SV_Target {
  96.                 if(i.worldPos.y > _Val)
  97.                     discard;
  98.  
  99.                 return _Color2;
  100.             }
  101.  
  102.             ENDCG
  103.         }
  104.  
  105.         //  PASS 4
  106.         Cull Front
  107.  
  108.         CGPROGRAM
  109.         #pragma surface surf Standard vertex:vert
  110.         struct Input {
  111.             float3 worldPos;
  112.         };
  113.  
  114.         float _EdgeWidth;
  115.  
  116.         void vert(inout appdata_base v)
  117.         {
  118.             v.vertex.xyz *= _EdgeWidth;
  119.         }
  120.  
  121.         fixed4 _Color1;
  122.         float _Val;
  123.  
  124.         void surf(Input IN, inout SurfaceOutputStandard o)
  125.         {
  126.             if(IN.worldPos.y > _Val)
  127.                 discard;
  128.  
  129.             o.Albedo = _Color1;
  130.         }
  131.  
  132.         ENDCG
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement