Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
14 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/CustomLightingToon"
  4. {
  5. Properties
  6. {
  7. [HideInInspector] __dirty( "", Int ) = 1
  8. _ASEOutlineColor( "Outline Color", Color ) = (0,0,0,0)
  9. _ASEOutlineWidth( "Outline Width", Float ) = 0.02
  10. _ToonRamp("Toon Ramp", 2D) = "white" {}
  11. [HDR]_RimColor("Rim Color", Color) = (0,1,0.8758622,0)
  12. _RimPower("Rim Power", Range( 0 , 10)) = 0.5
  13. _RimOffset("Rim Offset", Float) = 0.24
  14. _Diffuse("Diffuse", 2D) = "white" {}
  15. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  16. }
  17. SubShader
  18. {
  19. Tags{ }
  20. Cull Front
  21. CGPROGRAM
  22. #pragma target 3.0
  23. #pragma surface outlineSurf Outline keepalpha noshadow noambient novertexlights nolightmap nodynlightmap nodirlightmap nofog nometa noforwardadd vertex:outlineVertexDataFunc
  24. uniform fixed4 _ASEOutlineColor;
  25. uniform fixed _ASEOutlineWidth;
  26. void outlineVertexDataFunc( inout appdata_full v, out Input o )
  27. {
  28. UNITY_INITIALIZE_OUTPUT( Input, o );
  29. v.vertex.xyz += ( v.normal * _ASEOutlineWidth );
  30. }
  31. inline fixed4 LightingOutline( SurfaceOutput s, half3 lightDir, half atten ) { return fixed4 ( 0,0,0, s.Alpha); }
  32. void outlineSurf( Input i, inout SurfaceOutput o ) { o.Emission = _ASEOutlineColor.rgb; o.Alpha = 1; }
  33. ENDCG
  34. Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" "IsEmissive" = "true" }
  35. Cull Back
  36. CGINCLUDE
  37. #include "UnityPBSLighting.cginc"
  38. #include "UnityCG.cginc"
  39. #include "UnityShaderVariables.cginc"
  40. #include "Lighting.cginc"
  41. #pragma target 3.0
  42. #ifdef UNITY_PASS_SHADOWCASTER
  43. #undef INTERNAL_DATA
  44. #undef WorldReflectionVector
  45. #undef WorldNormalVector
  46. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  47. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  48. #define WorldNormalVector(data,normal) fixed3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  49. #endif
  50. struct Input
  51. {
  52. float2 uv_texcoord;
  53. float3 worldNormal;
  54. float3 worldPos;
  55. float3 viewDir;
  56. INTERNAL_DATA
  57. };
  58. struct SurfaceOutputCustomLightingCustom
  59. {
  60. fixed3 Albedo;
  61. fixed3 Normal;
  62. half3 Emission;
  63. half Metallic;
  64. half Smoothness;
  65. half Occlusion;
  66. fixed Alpha;
  67. Input SurfInput;
  68. UnityGIInput GIData;
  69. };
  70. uniform sampler2D _Diffuse;
  71. uniform float4 _Diffuse_ST;
  72. uniform sampler2D _ToonRamp;
  73. uniform float _RimOffset;
  74. uniform float _RimPower;
  75. uniform float4 _RimColor;
  76. inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
  77. {
  78. UnityGIInput data = s.GIData;
  79. Input i = s.SurfInput;
  80. half4 c = 0;
  81. #if DIRECTIONAL
  82. float ase_lightAtten = data.atten;
  83. if( _LightColor0.a == 0)
  84. ase_lightAtten = 0;
  85. #else
  86. float3 ase_lightAttenRGB = gi.light.color / ( ( _LightColor0.rgb ) + 0.000001 );
  87. float ase_lightAtten = max( max( ase_lightAttenRGB.r, ase_lightAttenRGB.g ), ase_lightAttenRGB.b );
  88. #endif
  89. float2 uv_Diffuse = i.uv_texcoord * _Diffuse_ST.xy + _Diffuse_ST.zw;
  90. float3 ase_worldPos = i.worldPos;
  91. float3 ase_lightDir = normalize( UnityWorldSpaceLightDir( ase_worldPos ) );
  92. float temp_output_3_0 = dot( i.worldNormal , ase_lightDir );
  93. float2 temp_cast_0 = (saturate( (temp_output_3_0*0.5 + 0.5) )).xx;
  94. float3 ase_worldNormal = i.worldNormal;
  95. float3 ase_indirectDiffuse = ShadeSH9( float4( ase_worldNormal, 1 ) );
  96. float3 temp_cast_2 = (ase_lightAtten).xxx;
  97. c.rgb = ( ( ( tex2D( _Diffuse, uv_Diffuse ) * tex2D( _ToonRamp, temp_cast_0 ) ) * ( _LightColor0 * float4( ( ase_indirectDiffuse + temp_cast_2 ) , 0.0 ) ) ) + ( saturate( ( ( ase_lightAtten * temp_output_3_0 ) * pow( ( 1.0 - saturate( ( dot( i.worldNormal , i.viewDir ) + _RimOffset ) ) ) , _RimPower ) ) ) * ( _RimColor * _LightColor0 ) ) ).rgb;
  98. c.a = 1;
  99. return c;
  100. }
  101. inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
  102. {
  103. s.GIData = data;
  104. }
  105. void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
  106. {
  107. o.SurfInput = i;
  108. }
  109. ENDCG
  110. CGPROGRAM
  111. #pragma surface surf StandardCustomLighting keepalpha fullforwardshadows
  112. ENDCG
  113. Pass
  114. {
  115. Name "ShadowCaster"
  116. Tags{ "LightMode" = "ShadowCaster" }
  117. ZWrite On
  118. CGPROGRAM
  119. #pragma vertex vert
  120. #pragma fragment frag
  121. #pragma target 3.0
  122. #pragma multi_compile_shadowcaster
  123. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  124. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  125. # include "HLSLSupport.cginc"
  126. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  127. #define CAN_SKIP_VPOS
  128. #endif
  129. #include "UnityCG.cginc"
  130. #include "Lighting.cginc"
  131. #include "UnityPBSLighting.cginc"
  132. sampler3D _DitherMaskLOD;
  133. struct v2f
  134. {
  135. V2F_SHADOW_CASTER;
  136. float3 worldPos : TEXCOORD6;
  137. float4 tSpace0 : TEXCOORD1;
  138. float4 tSpace1 : TEXCOORD2;
  139. float4 tSpace2 : TEXCOORD3;
  140. float4 texcoords01 : TEXCOORD4;
  141. UNITY_VERTEX_INPUT_INSTANCE_ID
  142. };
  143. v2f vert( appdata_full v )
  144. {
  145. v2f o;
  146. UNITY_SETUP_INSTANCE_ID( v );
  147. UNITY_INITIALIZE_OUTPUT( v2f, o );
  148. UNITY_TRANSFER_INSTANCE_ID( v, o );
  149. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  150. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  151. fixed3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  152. fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  153. fixed3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  154. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  155. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  156. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  157. o.texcoords01 = float4( v.texcoord.xy, v.texcoord1.xy );
  158. o.worldPos = worldPos;
  159. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  160. return o;
  161. }
  162. fixed4 frag( v2f IN
  163. #if !defined( CAN_SKIP_VPOS )
  164. , UNITY_VPOS_TYPE vpos : VPOS
  165. #endif
  166. ) : SV_Target
  167. {
  168. UNITY_SETUP_INSTANCE_ID( IN );
  169. Input surfIN;
  170. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  171. surfIN.uv_texcoord.xy = IN.texcoords01.xy;
  172. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  173. fixed3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  174. surfIN.viewDir = worldViewDir;
  175. surfIN.worldPos = worldPos;
  176. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  177. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  178. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  179. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  180. SurfaceOutputCustomLightingCustom o;
  181. UNITY_INITIALIZE_OUTPUT( SurfaceOutputCustomLightingCustom, o )
  182. surf( surfIN, o );
  183. #if defined( CAN_SKIP_VPOS )
  184. float2 vpos = IN.pos;
  185. #endif
  186. SHADOW_CASTER_FRAGMENT( IN )
  187. }
  188. ENDCG
  189. }
  190. }
  191. Fallback "Diffuse"
  192. CustomEditor "ASEMaterialInspector"
  193. }
  194. /*ASEBEGIN
  195. Version=10003
  196. 468;546;979;430;2767.59;654.1011;3.999999;True;False
  197. Node;AmplifyShaderEditor.CommentaryNode;49;-2016,528;Float;False;507.201;385.7996;Comment;3;36;37;38;N . V;0;0
  198. Node;AmplifyShaderEditor.WorldNormalVector;36;-1968,576;Float;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;FLOAT;FLOAT;FLOAT
  199. Node;AmplifyShaderEditor.ViewDirInputsCoordNode;37;-1920,736;Float;False;World;0;4;FLOAT3;FLOAT;FLOAT;FLOAT
  200. Node;AmplifyShaderEditor.CommentaryNode;50;-1344,768;Float;False;1617.938;553.8222;;13;33;46;32;31;34;47;35;30;29;28;27;25;24;Rim Light;0;0
  201. Node;AmplifyShaderEditor.DotProductOpNode;38;-1664,656;Float;False;2;0;FLOAT3;0.0;False;1;FLOAT3;0,0,0;False;1;FLOAT
  202. Node;AmplifyShaderEditor.CommentaryNode;48;-2016,32;Float;False;540.401;320.6003;Comment;3;1;3;2;N . L;0;0
  203. Node;AmplifyShaderEditor.RangedFloatNode;24;-1264,1040;Float;False;Property;_RimOffset;Rim Offset;3;0;0.24;0;0;0;1;FLOAT
  204. Node;AmplifyShaderEditor.SimpleAddOpNode;25;-1056,928;Float;False;2;0;FLOAT;0.0;False;1;FLOAT;0.0;False;1;FLOAT
  205. Node;AmplifyShaderEditor.CommentaryNode;51;-1143.099,-115.6995;Float;False;723.599;290;Also know as Lambert Wrap or Half Lambert;3;5;4;15;Diffuse Wrap;0;0
  206. Node;AmplifyShaderEditor.WorldNormalVector;1;-1904,80;Float;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;FLOAT;FLOAT;FLOAT
  207. Node;AmplifyShaderEditor.WorldSpaceLightDirHlpNode;2;-1952,240;Float;False;1;0;FLOAT;0.0;False;1;FLOAT3
  208. Node;AmplifyShaderEditor.CommentaryNode;52;-880,320;Float;False;812;304;Comment;5;7;8;11;10;12;Attenuation and Ambient;0;0
  209. Node;AmplifyShaderEditor.DotProductOpNode;3;-1616,144;Float;False;2;0;FLOAT3;0.0;False;1;FLOAT3;0.0,0,0;False;1;FLOAT
  210. Node;AmplifyShaderEditor.RangedFloatNode;5;-1093.099,59.30051;Float;False;Constant;_WrapperValue;Wrapper Value;0;0;0.5;0;0;0;1;FLOAT
  211. Node;AmplifyShaderEditor.SaturateNode;27;-896,928;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  212. Node;AmplifyShaderEditor.OneMinusNode;29;-720,928;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  213. Node;AmplifyShaderEditor.LightAttenuation;7;-809.6001,504;Float;False;0;1;FLOAT
  214. Node;AmplifyShaderEditor.RangedFloatNode;28;-832,1056;Float;False;Property;_RimPower;Rim Power;2;0;0.5;0;10;0;1;FLOAT
  215. Node;AmplifyShaderEditor.ScaleAndOffsetNode;4;-827.6974,-65.69949;Float;False;3;0;FLOAT;0.0;False;1;FLOAT;1.0;False;2;FLOAT;0.0;False;1;FLOAT
  216. Node;AmplifyShaderEditor.IndirectDiffuseLighting;11;-624,448;Float;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3
  217. Node;AmplifyShaderEditor.PowerNode;30;-528,928;Float;False;2;0;FLOAT;0.0;False;1;FLOAT;0.0;False;1;FLOAT
  218. Node;AmplifyShaderEditor.SaturateNode;15;-594.4999,-58.89988;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  219. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;35;-544,816;Float;False;2;0;FLOAT;0.0;False;1;FLOAT;0.0;False;1;FLOAT
  220. Node;AmplifyShaderEditor.LightColorNode;47;-256,1216;Float;False;0;1;COLOR
  221. Node;AmplifyShaderEditor.SimpleAddOpNode;12;-384,480;Float;False;2;0;FLOAT3;0,0,0;False;1;FLOAT;0.0;False;1;FLOAT3
  222. Node;AmplifyShaderEditor.LightColorNode;8;-768,368;Float;False;0;1;COLOR
  223. Node;AmplifyShaderEditor.SamplerNode;6;-224,-80;Float;True;Property;_ToonRamp;Toon Ramp;0;0;Assets/AmplifyShaderEditor/Examples/Assets/Textures/Misc/WarmToonRamp.png;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1.0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1.0;False;5;FLOAT4;FLOAT;FLOAT;FLOAT;FLOAT
  224. Node;AmplifyShaderEditor.ColorNode;34;-368,1040;Float;False;Property;_RimColor;Rim Color;1;1;[HDR];0,1,0.8758622,0;0;5;COLOR;FLOAT;FLOAT;FLOAT;FLOAT
  225. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;31;-288,896;Float;False;2;0;FLOAT;0.0;False;1;FLOAT;0.0,0,0;False;1;FLOAT
  226. Node;AmplifyShaderEditor.SamplerNode;43;-224,-304;Float;True;Property;_Diffuse;Diffuse;4;0;Assets/AmplifyShaderEditor/Examples/Assets/Textures/Misc/Checkers.png;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1.0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1.0;False;5;FLOAT4;FLOAT;FLOAT;FLOAT;FLOAT
  227. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;10;-224,368;Float;False;2;0;COLOR;0,0,0,0;False;1;FLOAT3;0.0,0,0,0;False;1;COLOR
  228. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;42;192,-96;Float;False;2;0;FLOAT4;0.0,0,0,0;False;1;FLOAT4;0.0,0,0,0;False;1;FLOAT4
  229. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;46;-64,1024;Float;False;2;0;COLOR;0.0;False;1;COLOR;0,0,0,0;False;1;COLOR
  230. Node;AmplifyShaderEditor.SaturateNode;32;-96,896;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  231. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;23;485.6002,153.2;Float;False;2;0;FLOAT4;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR
  232. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;33;96,896;Float;False;2;0;FLOAT;0.0,0,0,0;False;1;COLOR;0.0;False;1;COLOR
  233. Node;AmplifyShaderEditor.SimpleAddOpNode;39;832,384;Float;False;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR
  234. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;1077.3,350.7;Float;False;True;2;Float;ASEMaterialInspector;0;CustomLighting;ASESampleShaders/CustomLightingToon;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;0;False;0;0;Opaque;0.5;True;True;0;False;Opaque;Geometry;All;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;False;0;255;255;0;0;0;0;False;0;4;10;25;False;0.5;True;0;Zero;Zero;0;Zero;Zero;Add;Add;0;True;0.02;0,0,0,0;VertexOffset;False;Cylindrical;Relative;0;;-1;-1;-1;-1;14;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0.0;False;4;FLOAT;0.0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0.0;False;9;FLOAT;0.0;False;10;OBJECT;0.0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
  235. WireConnection;38;0;36;0
  236. WireConnection;38;1;37;0
  237. WireConnection;25;0;38;0
  238. WireConnection;25;1;24;0
  239. WireConnection;3;0;1;0
  240. WireConnection;3;1;2;0
  241. WireConnection;27;0;25;0
  242. WireConnection;29;0;27;0
  243. WireConnection;4;0;3;0
  244. WireConnection;4;1;5;0
  245. WireConnection;4;2;5;0
  246. WireConnection;30;0;29;0
  247. WireConnection;30;1;28;0
  248. WireConnection;15;0;4;0
  249. WireConnection;35;0;7;0
  250. WireConnection;35;1;3;0
  251. WireConnection;12;0;11;0
  252. WireConnection;12;1;7;0
  253. WireConnection;6;1;15;0
  254. WireConnection;31;0;35;0
  255. WireConnection;31;1;30;0
  256. WireConnection;10;0;8;0
  257. WireConnection;10;1;12;0
  258. WireConnection;42;0;43;0
  259. WireConnection;42;1;6;0
  260. WireConnection;46;0;34;0
  261. WireConnection;46;1;47;0
  262. WireConnection;32;0;31;0
  263. WireConnection;23;0;42;0
  264. WireConnection;23;1;10;0
  265. WireConnection;33;0;32;0
  266. WireConnection;33;1;46;0
  267. WireConnection;39;0;23;0
  268. WireConnection;39;1;33;0
  269. WireConnection;0;2;39;0
  270. ASEEND*/
  271. //CHKSM=4929E7767ABD1D05878E240E0FF8092D594542B8