noradninja

Vita/Deferred/Standard

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