noradninja

Vita/Deferred/Standard Alpha Clip

Jun 5th, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.66 KB | None | 0 0
  1. Shader "Vita/Deferred/Standard Alpha Clip"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  6.         _Cutoff ("Alpha Clip", Range (0.0,1.0)) = 0.5
  7.         _SpecColor ("Specular Color", Color) = (1,1,1,1)
  8.         [NoScaleOffset] _Specular ("Specular (RGB)", 2D) = "white" {}
  9.         [PowerSlider(2.0)] _Specularity ("Specularity", Range (0.03, 2)) = 0.0
  10.         [PowerSlider(2.0)] _Shininess ("Glossiness", Range (0.03, 1)) = 0.0
  11.         [NoScaleOffset] _Emissive ("Emission (RGB)", 2D) = "white" {}
  12.         [PowerSlider(2.0)] _EmissiveBright ("Emissive Brightness", Range (0.00, 1)) = 0.0
  13.         [NoScaleOffset] _BumpMap ("Normal Map (RGB)", 2D) = "bump" {}
  14.         _BumpScale("Scale", Range (-2,2)) = 1.0
  15.     }
  16.     SubShader
  17.     {
  18.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  19.         LOD 200
  20.        
  21.         CGPROGRAM
  22. //Pragmas/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23.         #pragma surface surf VitaBlinnPhong addshadow noshadowmask alphatest:_Cutoff exclude_path:deferred
  24.         #pragma target 3.0
  25. //Define Inputs from Properties///////////////////////////////////////////////////////////////////////////////////////////////////
  26.         sampler2D _MainTex;
  27.         sampler2D _BumpMap;
  28.         sampler2D _Specular;
  29.         sampler2D _Emissive;
  30.         fixed _Shininess;
  31.         fixed _Specularity;
  32.         fixed _BumpScale;
  33.         fixed _EmissiveBright;
  34. //Define Surface Outputs//////////////////////////////////////////////////////////////////////////////////////////////////////////
  35.         struct VitaSurfaceOutput
  36.         {
  37.             half3 Albedo;
  38.             half3 Normal;
  39.             half3 Emission;
  40.             half Specular;
  41.             half3 GlossColor;
  42.             half Alpha;
  43.         };
  44. //Forward render support *mostly* so we can preview in the scene view/////////////////////////////////////////////////////////////
  45.         inline half4 LightingVitaBlinnPhong(VitaSurfaceOutput s, half3 lightDir, half3 halfDir, half atten)
  46.         {
  47.             half diff = max (0, dot (s.Normal, lightDir));
  48.             half nh = max (0, dot (s.Normal, halfDir));
  49.             half3 spec = pow (nh, s.Specular*128);
  50.             half3 specCol = spec * s.GlossColor;
  51.  
  52.             half4 c;
  53.             c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * specCol) * atten;
  54.             c.a = s.Alpha;
  55.             return c;
  56.         }
  57. //Deferred prepass render support/////////////////////////////////////////////////////////////////////////////////////////////////
  58.         inline fixed4 LightingVitaBlinnPhong_PrePass (VitaSurfaceOutput s, fixed4 light)
  59.         {
  60.             fixed3 spec = light.a * (s.GlossColor * s.Specular); //light.a stores brightness per light, mult with gloss and specular contributions to get total specular reflection
  61.             fixed4 c;
  62.             c.rgb = (s.Albedo * light.rgb + light.rgb * spec); //Blinn-Phong lighting model for deferred prepass only needs surface, light, and specular color
  63.             c.a = s.Alpha;
  64.             return c;
  65.         }
  66. //Define minimal Inputs needed////////////////////////////////////////////////////////////////////////////////////////////////////
  67.         struct Input {
  68.             float2 uv_MainTex;
  69.         };
  70. //Define surface//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  71.         void surf (Input IN, inout VitaSurfaceOutput o) {
  72. //Texture Inputs//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73.             fixed4 col = tex2D (_MainTex, IN.uv_MainTex); //Albedo map
  74.             fixed4 norm = tex2D(_BumpMap, IN.uv_MainTex); //Normal map
  75.             fixed4 smap = tex2D(_Specular, IN.uv_MainTex); //Specular map
  76.             fixed4 emap = tex2D(_Emissive, IN.uv_MainTex); //Emissive map
  77. //Slider Inputs///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78.             fixed eval = _EmissiveBright; //Emissive brightness slider
  79.             fixed scale = _BumpScale; //normal scaling
  80.             fixed sval= _Specularity; //Specularity slider
  81. //Color Inputs and Calcs//////////////////////////////////////////////////////////////////////////////////////////////////////////
  82.             fixed4 scol = _SpecColor; //Specular color
  83.             fixed4 specular = (smap * sval) * scol; //multi specular color to (specmapRGB * specularity slider)- this adjusts how sharp the spec reflection is
  84. //Surface Outputs   //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85.             o.Albedo = col.rgb; //set color from Albedo map
  86.             o.Specular = _Shininess; //set specular from calculated value
  87.             o.GlossColor = specular; //overall glossy/dull modulator for specular hilight
  88.             o.Emission = emap * eval; //emission map contribution adjustable with slider
  89.             o.Normal = UnpackScaleNormal(norm, scale); //unpack and scale normal map
  90.             o.Alpha = col.a; //pull alpha from Albedo(A)
  91.         }
  92.         ENDCG
  93.     }
  94. }
Add Comment
Please, Sign In to add comment