Burnout.shader 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
  3. Shader "FORGE3D/Burnout" {
  4. Properties {
  5. _Diffuse ("Diffuse", 2D) = "black" {}
  6. _Normal ("Normal", 2D) = "white" {}
  7. _DiffusePower ("Diffuse Power", Float) = 1
  8. _SpecularAdd ("Specular Add", Float) = 0
  9. _SpecularMult ("Specular Mult", Float) = 0
  10. _SpecularA ("Specular A", Float) = 0
  11. _SpecularB ("Specular B", Float) = 1
  12. _SpecularRatio ("Specular Ratio", Float) = 5.276861
  13. _FresnelPower ("Fresnel Power", Float) = 0
  14. _FresnelMult ("Fresnel Mult", Float) = 0
  15. _FresnelColor("Fresnel Color", Color) = (4.0, 0.7, 0.004, 1.0)
  16. //
  17. _Cut ("AlphaTest Cutoff", Float) = 1.0
  18. _LoopTex("Loop Texture", 2D) = "white" {}
  19. _MaskTex("Corrupt Mask", 2D) = "white" {}
  20. _BurnoutMask("Burnout mask", 2D) = ""{}
  21. _WipeEm("Buronout Emission mask", 2D) = ""{}
  22. _WipeOp("Burnout Opacity mask", 2D) = ""{}
  23. _BurnColor("Burn Color", Color) = (4.0, 0.7, 0.004, 1.0)
  24. _FresnelExp("Burnout fresnel Power", Float) = 0.0
  25. _BurnOut("Burnout", Float) = 0.0
  26. _BurnUVOffset("Burnout offset", Float) = 0.0
  27. }
  28. SubShader
  29. {
  30. //AlphaTest Greater [_Cut]
  31. Blend One OneMinusSrcAlpha
  32. Tags { "RenderType"="Transparent" }
  33. Cull Off
  34. Pass
  35. {
  36. Name "ForwardBase"
  37. Tags
  38. {
  39. "LightMode"="ForwardBase"
  40. }
  41. CGPROGRAM
  42. #pragma vertex vert
  43. #pragma fragment frag
  44. #include "UnityCG.cginc"
  45. #include "AutoLight.cginc"
  46. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
  47. #pragma target 3.0
  48. uniform float4 _LightColor0;
  49. uniform sampler2D _Normal; uniform float4 _Normal_ST;
  50. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  51. // uniform sampler2D _Glow; uniform float4 _Glow_ST;
  52. uniform samplerCUBE _Cubemap;
  53. uniform float _DiffusePower;
  54. uniform float _SpecularRatio;
  55. uniform float _SpecularA;
  56. uniform float _SpecularB;
  57. uniform float _SpecularMult;
  58. uniform float _SpecularAdd;
  59. uniform float _ReflectionMult;
  60. uniform float _ReflectionDesaturation;
  61. uniform float _FresnelPower;
  62. uniform float _FresnelMult;
  63. uniform float4 _FresnelColor;
  64. //
  65. float _BurnOut;
  66. float _FresnelExp;
  67. float _BurnUVOffset;
  68. sampler2D _BurnoutMask;
  69. sampler2D _LoopTex;
  70. sampler2D _MaskTex;
  71. sampler2D _WipeEm;
  72. sampler2D _WipeOp;
  73. float4 _BurnColor;
  74. float _Cut;
  75. struct VertexInput
  76. {
  77. float4 vertex : POSITION;
  78. float3 normal : NORMAL;
  79. float4 tangent : TANGENT;
  80. float2 texcoord0 : TEXCOORD0;
  81. };
  82. struct VertexOutput
  83. {
  84. float4 pos : SV_POSITION;
  85. float2 uv0 : TEXCOORD0;
  86. float4 posWorld : TEXCOORD1;
  87. float3 normalDir : TEXCOORD2;
  88. float3 tangentDir : TEXCOORD3;
  89. float3 binormalDir : TEXCOORD4;
  90. LIGHTING_COORDS(5,6)
  91. };
  92. // Vertex
  93. VertexOutput vert (VertexInput v)
  94. {
  95. VertexOutput o;
  96. o.uv0 = TRANSFORM_TEX( v.texcoord0, _Diffuse );
  97. o.normalDir = mul(float4(v.normal,0), unity_WorldToObject).xyz;
  98. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  99. o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  100. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  101. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  102. // TRANSFER_VERTEX_TO_FRAGMENT(o)
  103. return o;
  104. }
  105. // Spherical Gaussian Power Function
  106. float powx(float x, float n)
  107. {
  108. n = n * 1.4427f + 1.4427f;
  109. return exp2(x * n - n);
  110. }
  111. // Desaturate
  112. float Desaturate(float3 color)
  113. {
  114. return color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
  115. }
  116. // Fragment
  117. float4 frag(VertexOutput i) : COLOR
  118. {
  119. // normal and transforms
  120. i.normalDir = normalize(i.normalDir);
  121. float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
  122. // normal calculation
  123. float4 normalMap = tex2D(_Normal, i.uv0);
  124. float2 n = ((float2(normalMap.g,normalMap.a).rg*2.0)-1.0).rg;
  125. float3 normalLocal = mul( tangentTransform, normalize((normalize(i.normalDir)+(normalize(i.tangentDir)*n.g)+(normalize(i.binormalDir)*n.r))) ).xyz.rgb;
  126. float3 normalDir = normalize(mul( normalLocal, tangentTransform ));
  127. // light
  128. float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
  129. float attenuation = LIGHT_ATTENUATION(i);
  130. float3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb;
  131. // view, half, reflect
  132. float3 viewDir = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  133. float3 reflectDir = reflect( -viewDir, normalDir );
  134. float3 halfDir = normalize(viewDir + lightDir);
  135. float4 diffuseMap = tex2D(_Diffuse, i.uv0);
  136. float ndl = pow(saturate(dot(normalDir, lightDir)), _DiffusePower);
  137. float specDot = max(0.0, dot(normalDir, halfDir));
  138. float spec = max(0, _SpecularRatio) * powx(specDot, max(0, _SpecularA)) + powx(specDot, max(0, _SpecularB)) * diffuseMap.g;
  139. spec = saturate(spec) * ndl * attenuation;
  140. float3 diffuse = (diffuseMap.rgb * attenuation) *
  141. ((ndl + _SpecularMult * spec) * _LightColor0.rgb) +
  142. _SpecularAdd * spec * _LightColor0.rgb;
  143. float3 fresnel = saturate(powx(saturate(1 - abs(dot(viewDir, normalDir))), _FresnelPower) * _FresnelMult) * diffuseMap.a * _FresnelColor;
  144. float3 ambientColor = (diffuseMap.rgb * ambient);
  145. float3 finalColor = ambientColor + diffuse + fresnel;
  146. //
  147. float2 uvPan = float2(i.uv0.x + _Time.x * 1, i.uv0.y);
  148. float4 loop_ = tex2D (_LoopTex, uvPan * 2) * 200;
  149. float4 crptMask = tex2D (_MaskTex, i.uv0 * 1);
  150. float localFresnel = saturate(dot(normalize(viewDir), normalize(normalDir)));
  151. float2 c = float2(0.0, 1 ) * _BurnOut + pow((1 - localFresnel), _FresnelExp);
  152. c = float2(0.0, 1.2) - c;
  153. float3 wipe = tex2D(_WipeEm, c);
  154. float3 opacityWipe = tex2D(_WipeOp, (1 - (c + _BurnUVOffset)));
  155. float wipeMask = crptMask.r * opacityWipe.r;
  156. float4 crptMask_g = crptMask.g * float4(15.0, 1.0, 0.0, 0.0);
  157. float4 crptMask_b = crptMask.b * float4(15.0, 1.0, 0.0, 0.0);
  158. float4 loop1 = (loop_ * crptMask_g) + crptMask_b;
  159. float3 burnoutMask = tex2D(_BurnoutMask, i.uv0);
  160. float3 burnwipe = dot( burnoutMask, float3(0.22, 0.707, 0.071) ) * wipe * _BurnColor.rgb * _BurnColor.a * 300;
  161. clip(wipeMask - _Cut);
  162. return float4(loop1.rgb + burnwipe + finalColor, 1);
  163. }
  164. ENDCG
  165. }
  166. }
  167. FallBack "Transparent"
  168. }