Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / FlexibleCelShader / Shaders / CelNoOutline.shader
  1. Shader "FlexibleCelShader/Cel No Outline"
  2. {
  3. Properties
  4. {
  5. _Color("Global Color Modifier", Color) = (1, 1, 1, 1)
  6. _MainTex("Texture", 2D) = "white" {}
  7. _NormalTex("Normal", 2D) = "bump" {}
  8. _EmmisTex("Emission", 2D) = "black" {}
  9. _RampLevels("Ramp Levels", Range(2, 50)) = 2
  10. _LightScalar("Light Scalar", Range(0, 10)) = 1
  11. _HighColor("High Light Color", Color) = (1, 1, 1, 1)
  12. _HighIntensity("High Light Intensity", Range(0, 10)) = 1.5
  13. _LowColor("Low Light Color", Color) = (1, 1, 1, 1)
  14. _LowIntensity("Low Light Intensity", Range(0, 10)) = 1
  15. _OutlineColor("Outline Color", Color) = (0, 0, 0, 1)
  16. _OutlineSize("Outline Size", float) = 10
  17. _RimColor("Hard Edge Light Color", Color) = (1, 1, 1, 1)
  18. _RimAlpha("Hard Edge Light Brightness", Range(0, 1)) = 0
  19. _RimPower("Hard Edge Light Size", Range(0,1)) = 0
  20. _RimDropOff("Hard Edge Light Dropoff", range(0, 1)) = 0
  21. _FresnelColor("Soft Edge Light Color", Color) = (1,1,1,1)
  22. _FresnelBrightness("Soft Edge Light Brightness", Range(0, 1)) = 0
  23. _FresnelPower("Soft Edge Light Size", Range(0, 1)) = 0
  24. _FresnelShadowDropoff("Soft Edge Light Dropoff", range(0, 1)) = 0
  25. }
  26. SubShader
  27. {
  28. // This pass renders the object
  29. Cull back
  30. Pass
  31. {
  32. Tags{ "LightMode" = "ForwardBase" }
  33. CGPROGRAM
  34. #pragma vertex vert
  35. #pragma fragment frag
  36. #include "UnityCG.cginc"
  37. #include "Lighting.cginc"
  38. #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
  39. #include "AutoLight.cginc"
  40. struct v2f
  41. {
  42. float2 uv : TEXCOORD0;
  43. SHADOW_COORDS(1)
  44. float3 worldNormal : TEXCOORD2;
  45. float3 worldTangent : TEXCOORD3;
  46. float3 worldBitangent : TEXCOORD4;
  47. float4 worldPos : TEXCOORD5;
  48. float4 pos : SV_POSITION;
  49. };
  50. v2f vert(appdata_tan v)
  51. {
  52. v2f o;
  53. // UV data
  54. o.uv = v.texcoord;
  55. // Position data
  56. o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  57. o.pos = mul(UNITY_MATRIX_VP, o.worldPos);
  58. // Normal data
  59. o.worldNormal = UnityObjectToWorldNormal(v.normal);
  60. o.worldTangent = UnityObjectToWorldNormal(v.tangent);
  61. o.worldBitangent = cross(o.worldTangent, o.worldNormal);
  62. // Compute shadows data
  63. TRANSFER_SHADOW(o);
  64. return o;
  65. }
  66. float4 _Color;
  67. sampler2D _MainTex;
  68. uniform float4 _MainTex_ST;
  69. sampler2D _NormalTex;
  70. uniform float4 _NormalTex_ST;
  71. sampler2D _EmmisTex;
  72. uniform float4 _EmmisTex_ST;
  73. int _RampLevels;
  74. float _LightScalar;
  75. float _HighIntensity;
  76. float4 _HighColor;
  77. float _LowIntensity;
  78. float4 _LowColor;
  79. float _RimPower;
  80. float _RimAlpha;
  81. float4 _RimColor;
  82. float _RimDropOff;
  83. float _FresnelBrightness;
  84. float _FresnelPower;
  85. float4 _FresnelColor;
  86. float _FresnelShadowDropoff;
  87. fixed4 frag(v2f i) : SV_Target
  88. {
  89. _RampLevels -= 1;
  90. // Get view direction && light direction for rim lighting
  91. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.worldPos.xyz);
  92. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  93. // Sample textures
  94. fixed4 col = tex2D(_MainTex, i.uv * _MainTex_ST.xy + _MainTex_ST.zw);
  95. fixed3 tangentNormal = tex2D(_NormalTex, i.uv * _NormalTex_ST.xy + _NormalTex_ST.zw) * 2 - 1;
  96. fixed4 emmision = tex2D(_EmmisTex, i.uv * _EmmisTex_ST.xy + _EmmisTex_ST.zw);
  97. // Get normal
  98. float3 worldNormal = float3(i.worldTangent * tangentNormal.r + i.worldBitangent * tangentNormal.g + i.worldNormal * tangentNormal.b);
  99. // Rim Lighting
  100. half factor = dot(viewDirection, worldNormal);
  101. half fresnelFactor = 1 - min(pow(max(1 - factor, 0), (1 - _FresnelPower) * 10), 1);
  102. // Get shadow attenuation
  103. fixed shadow = SHADOW_ATTENUATION(i);
  104. // Calculate light intensity
  105. float intensity = dot(worldNormal, lightDirection);
  106. intensity = clamp(intensity * _LightScalar, 0, 1);
  107. // Factor in the shadow
  108. intensity *= shadow;
  109. // Determine level
  110. float rampLevel = round(intensity * _RampLevels);
  111. // Get light multiplier based on level
  112. float lightMultiplier = _LowIntensity + ((_HighIntensity - _LowIntensity) / (_RampLevels)) * rampLevel;
  113. // Get color multiplier based on level
  114. float4 highColor = (rampLevel / _RampLevels) * _HighColor;
  115. float4 lowColor = ((_RampLevels - rampLevel) / _RampLevels) * _LowColor;
  116. float4 mixColor = (highColor + lowColor) / 2;
  117. // Apply light multiplier and color
  118. col *= lightMultiplier;
  119. col *= _Color * mixColor;
  120. // Apply soft Fresnel
  121. float rampPercentSoftFresnel = 1 - ((1 - rampLevel / _RampLevels) * (1 - _FresnelShadowDropoff));
  122. col.rgb = col.rgb + _FresnelColor*(_FresnelBrightness*10 - fresnelFactor*_FresnelBrightness*10) * rampPercentSoftFresnel;
  123. // Apply hard rim lighting
  124. _RimAlpha *= 1 - ((1 - rampLevel / _RampLevels) * (1 - _RimDropOff));
  125. if (factor <= _RimPower) {
  126. col.rgb = _RimColor.rgb * _RimAlpha + col.rgb * (1 - _RimAlpha);
  127. }
  128. // Apply emmision lighting
  129. half eIntensity = max(emmision.r, emmision.g);
  130. eIntensity = max(eIntensity, emmision.b);
  131. col = emmision*eIntensity + col*(1 - eIntensity);
  132. return col;
  133. }
  134. ENDCG
  135. } // End Main Pass
  136. // Shadow casting
  137. UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
  138. }
  139. CustomEditor "CelCustomEditor"
  140. }