Advertisement
Guest User

Cutoff.Shader

a guest
Dec 23rd, 2021
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Cutoff"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Color", Color) = (1,1,1,1)      
  6.         _MainTex ("Albedo (RGB)", 2D) = "white" {}    
  7.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
  8.         _Metallic ("Metallic", Range(0,1)) = 0.0
  9.         _PosSlider ("Slider", float) = 0.0
  10.         _Stretch ("Stretch", float) = 7
  11.     }
  12.     SubShader
  13.     {
  14.         Tags { "RenderType"="Opaque" }
  15.         LOD 200
  16.         //  Blend SrcAlpha OneMinusSrcAlpha
  17.         Cull Off
  18.  
  19.         CGPROGRAM
  20.         // Physically based Standard lighting model, and enable shadows on all light types
  21.         #pragma surface surf Standard vertex:vert keepalpha  
  22.  
  23.         // Use shader model 3.0 target, to get nicer looking lighting
  24.         #pragma target 3.0
  25.  
  26.         sampler2D _MainTex;
  27.  
  28.         struct Input
  29.         {
  30.             float2 uv_MainTex;
  31.             float3 localPos;
  32.             float vFace : VFACE;
  33.         };
  34.  
  35.         half _Glossiness;
  36.         half _Metallic;
  37.         fixed4 _Color;
  38.         half _PosSlider;
  39.         half _Stretch;
  40.        
  41.         void vert (inout appdata_full v, out Input o) {
  42.             UNITY_INITIALIZE_OUTPUT(Input,o);
  43.             o.localPos = v.vertex.xyz;
  44.            
  45.         }
  46.  
  47.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  48.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  49.         // #pragma instancing_options assumeuniformscaling
  50.         UNITY_INSTANCING_BUFFER_START(Props)
  51.         // put more per-instance properties here
  52.         UNITY_INSTANCING_BUFFER_END(Props)
  53.  
  54.         void surf (Input IN, inout SurfaceOutputStandard o)
  55.         {
  56.             // Albedo comes from a texture tinted by color
  57.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  58.            
  59.             //  the object position and a slider that moves over the object
  60.             float objectPosSliding = IN.localPos.y  + _PosSlider;
  61.  
  62.             // the cutoff that will be clipped
  63.             float cutoff = step(objectPosSliding, 0.5);
  64.             // lerp the color of the albedo towards the cutoff point
  65.             c = lerp(c, _Color, saturate(objectPosSliding * _Stretch));
  66.             //
  67.             float4 final = (IN.vFace>0) ? c : _Color;
  68.             o.Albedo = final;
  69.             //
  70.             float4 e = lerp(0, _Color, saturate(objectPosSliding * _Stretch));
  71.             // color the backfaces in _Color, and the the rest in the f
  72.             o.Emission = (IN.vFace>0) ? e : _Color;
  73.             // clip everything above the cutoff;
  74.             clip(cutoff - 0.06);
  75.            
  76.             // Metallic and smoothness come from slider variables
  77.             o.Metallic = _Metallic;
  78.             o.Smoothness = _Glossiness;
  79.             o.Alpha =1;
  80.         }
  81.         ENDCG
  82.     }
  83.     FallBack "Diffuse"
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement