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.

130 lines
8.8 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/Triplanar Simple"
  4. {
  5. Properties
  6. {
  7. _TopAlbedo("Top Albedo", 2D) = "white" {}
  8. _TopNormal("Top Normal", 2D) = "bump" {}
  9. _TriplanarAlbedo("Triplanar Albedo", 2D) = "white" {}
  10. _TriplanarNormal("Triplanar Normal", 2D) = "bump" {}
  11. _Specular("Specular", Range( 0 , 1)) = 0.02
  12. _Smoothness("Smoothness", Range( 0 , 1)) = 0.5
  13. _CoverageFalloff("Coverage Falloff", Range( 0.01 , 5)) = 0.5
  14. [HideInInspector] __dirty( "", Int ) = 1
  15. }
  16. SubShader
  17. {
  18. Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
  19. Cull Back
  20. ZTest LEqual
  21. CGPROGRAM
  22. #pragma target 3.0
  23. #define ASE_TEXTURE_PARAMS(textureName) textureName
  24. #pragma surface surf StandardSpecular keepalpha addshadow fullforwardshadows exclude_path:deferred
  25. struct Input
  26. {
  27. float3 worldPos;
  28. float3 worldNormal;
  29. INTERNAL_DATA
  30. };
  31. uniform sampler2D _TopNormal;
  32. uniform sampler2D _TriplanarNormal;
  33. uniform float _CoverageFalloff;
  34. uniform sampler2D _TopAlbedo;
  35. uniform sampler2D _TriplanarAlbedo;
  36. uniform float _Specular;
  37. uniform float _Smoothness;
  38. inline float3 TriplanarSamplingCNF( sampler2D topTexMap, sampler2D midTexMap, sampler2D botTexMap, float3 worldPos, float3 worldNormal, float falloff, float2 tiling, float3 normalScale, float3 index )
  39. {
  40. float3 projNormal = ( pow( abs( worldNormal ), falloff ) );
  41. projNormal /= ( projNormal.x + projNormal.y + projNormal.z ) + 0.00001;
  42. float3 nsign = sign( worldNormal );
  43. float negProjNormalY = max( 0, projNormal.y * -nsign.y );
  44. projNormal.y = max( 0, projNormal.y * nsign.y );
  45. half4 xNorm; half4 yNorm; half4 yNormN; half4 zNorm;
  46. xNorm = ( tex2D( ASE_TEXTURE_PARAMS( midTexMap ), tiling * worldPos.zy * float2( nsign.x, 1.0 ) ) );
  47. yNorm = ( tex2D( ASE_TEXTURE_PARAMS( topTexMap ), tiling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  48. yNormN = ( tex2D( ASE_TEXTURE_PARAMS( botTexMap ), tiling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  49. zNorm = ( tex2D( ASE_TEXTURE_PARAMS( midTexMap ), tiling * worldPos.xy * float2( -nsign.z, 1.0 ) ) );
  50. xNorm.xyz = half3( UnpackNormal( xNorm ).xy * float2( nsign.x, 1.0 ) + worldNormal.zy, worldNormal.x ).zyx;
  51. yNorm.xyz = half3( UnpackNormal( yNorm ).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;
  52. zNorm.xyz = half3( UnpackNormal( zNorm ).xy * float2( -nsign.z, 1.0 ) + worldNormal.xy, worldNormal.z ).xyz;
  53. yNormN.xyz = half3( UnpackNormal( yNormN ).xy * float2( nsign.y, 1.0 ) + worldNormal.xz, worldNormal.y ).xzy;
  54. return normalize( xNorm.xyz * projNormal.x + yNorm.xyz * projNormal.y + yNormN.xyz * negProjNormalY + zNorm.xyz * projNormal.z );
  55. }
  56. inline float4 TriplanarSamplingCF( sampler2D topTexMap, sampler2D midTexMap, sampler2D botTexMap, float3 worldPos, float3 worldNormal, float falloff, float2 tiling, float3 normalScale, float3 index )
  57. {
  58. float3 projNormal = ( pow( abs( worldNormal ), falloff ) );
  59. projNormal /= ( projNormal.x + projNormal.y + projNormal.z ) + 0.00001;
  60. float3 nsign = sign( worldNormal );
  61. float negProjNormalY = max( 0, projNormal.y * -nsign.y );
  62. projNormal.y = max( 0, projNormal.y * nsign.y );
  63. half4 xNorm; half4 yNorm; half4 yNormN; half4 zNorm;
  64. xNorm = ( tex2D( ASE_TEXTURE_PARAMS( midTexMap ), tiling * worldPos.zy * float2( nsign.x, 1.0 ) ) );
  65. yNorm = ( tex2D( ASE_TEXTURE_PARAMS( topTexMap ), tiling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  66. yNormN = ( tex2D( ASE_TEXTURE_PARAMS( botTexMap ), tiling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  67. zNorm = ( tex2D( ASE_TEXTURE_PARAMS( midTexMap ), tiling * worldPos.xy * float2( -nsign.z, 1.0 ) ) );
  68. return xNorm * projNormal.x + yNorm * projNormal.y + yNormN * negProjNormalY + zNorm * projNormal.z;
  69. }
  70. void surf( Input i , inout SurfaceOutputStandardSpecular o )
  71. {
  72. float3 ase_worldPos = i.worldPos;
  73. float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
  74. float3 ase_worldTangent = WorldNormalVector( i, float3( 1, 0, 0 ) );
  75. float3 ase_worldBitangent = WorldNormalVector( i, float3( 0, 1, 0 ) );
  76. float3x3 ase_worldToTangent = float3x3( ase_worldTangent, ase_worldBitangent, ase_worldNormal );
  77. float3 triplanar345 = TriplanarSamplingCNF( _TopNormal, _TriplanarNormal, _TriplanarNormal, ase_worldPos, ase_worldNormal, _CoverageFalloff, float2( 1,1 ), float3( 1,1,1 ), float3(0,0,0) );
  78. float3 tanTriplanarNormal345 = mul( ase_worldToTangent, triplanar345 );
  79. o.Normal = tanTriplanarNormal345;
  80. float4 triplanar343 = TriplanarSamplingCF( _TopAlbedo, _TriplanarAlbedo, _TriplanarAlbedo, ase_worldPos, ase_worldNormal, _CoverageFalloff, float2( 1,1 ), float3( 1,1,1 ), float3(0,0,0) );
  81. o.Albedo = triplanar343.xyz;
  82. float3 temp_cast_1 = (_Specular).xxx;
  83. o.Specular = temp_cast_1;
  84. o.Smoothness = _Smoothness;
  85. o.Alpha = 1;
  86. }
  87. ENDCG
  88. }
  89. Fallback "Diffuse"
  90. CustomEditor "ASEMaterialInspector"
  91. }
  92. /*ASEBEGIN
  93. Version=16500
  94. 1934;267;1048;580;43.36483;343.2944;2.069231;True;False
  95. Node;AmplifyShaderEditor.TexturePropertyNode;347;672,656;Float;True;Property;_TriplanarNormal;Triplanar Normal;3;0;Create;True;0;0;False;0;None;0bebe40e9ebbecc48b8e9cfea982da7e;True;bump;Auto;Texture2D;0;1;SAMPLER2D;0
  96. Node;AmplifyShaderEditor.TexturePropertyNode;339;672,-48;Float;True;Property;_TriplanarAlbedo;Triplanar Albedo;2;0;Create;True;0;0;False;0;None;b297077dae62c1944ba14cad801cddf5;False;white;Auto;Texture2D;0;1;SAMPLER2D;0
  97. Node;AmplifyShaderEditor.TexturePropertyNode;346;672,448;Float;True;Property;_TopNormal;Top Normal;1;0;Create;True;0;0;False;0;None;f5453dca2ac649e4182c56a3966ad395;True;bump;Auto;Texture2D;0;1;SAMPLER2D;0
  98. Node;AmplifyShaderEditor.RangedFloatNode;352;608,304;Float;False;Property;_CoverageFalloff;Coverage Falloff;6;0;Create;True;0;0;False;0;0.5;2;0.01;5;0;1;FLOAT;0
  99. Node;AmplifyShaderEditor.WorldPosInputsNode;344;688,144;Float;False;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
  100. Node;AmplifyShaderEditor.TexturePropertyNode;338;672,-240;Float;True;Property;_TopAlbedo;Top Albedo;0;0;Create;True;0;0;False;0;None;c68296334e691ed45b62266cbc716628;False;white;Auto;Texture2D;0;1;SAMPLER2D;0
  101. Node;AmplifyShaderEditor.RangedFloatNode;213;1184,624;Float;False;Property;_Smoothness;Smoothness;5;0;Create;True;0;0;False;0;0.5;0.2;0;1;0;1;FLOAT;0
  102. Node;AmplifyShaderEditor.RangedFloatNode;212;1184,544;Float;False;Property;_Specular;Specular;4;0;Create;True;0;0;False;0;0.02;0.02;0;1;0;1;FLOAT;0
  103. Node;AmplifyShaderEditor.TriplanarNode;343;1088,64;Float;True;Cylindrical;World;False;Top Texture 0;_TopTexture0;white;-1;None;Mid Texture 0;_MidTexture0;white;-1;None;Bot Texture 0;_BotTexture0;white;-1;None;Triplanar Sampler;False;10;0;SAMPLER2D;;False;5;FLOAT;1;False;1;SAMPLER2D;;False;6;FLOAT;0;False;2;SAMPLER2D;;False;7;FLOAT;0;False;9;FLOAT3;0,0,0;False;8;FLOAT3;1,1,1;False;3;FLOAT2;1,1;False;4;FLOAT;2;False;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  104. Node;AmplifyShaderEditor.TriplanarNode;345;1088,320;Float;True;Cylindrical;World;True;Top Texture 1;_TopTexture1;white;-1;None;Mid Texture 1;_MidTexture1;white;-1;None;Bot Texture 1;_BotTexture1;white;-1;None;Triplanar Sampler;False;10;0;SAMPLER2D;;False;5;FLOAT;1;False;1;SAMPLER2D;;False;6;FLOAT;0;False;2;SAMPLER2D;;False;7;FLOAT;0;False;9;FLOAT3;0,0,0;False;8;FLOAT3;1,1,1;False;3;FLOAT2;1,1;False;4;FLOAT;2;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  105. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;1808,176;Float;False;True;2;Float;ASEMaterialInspector;0;0;StandardSpecular;ASESampleShaders/Triplanar Simple;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;Back;0;False;-1;3;False;-1;False;0;False;-1;0;False;-1;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;ForwardOnly;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;0;4;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;1;False;-1;1;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;0;False;0.1;False;-1;0;False;-1;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,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
  106. WireConnection;343;0;338;0
  107. WireConnection;343;1;339;0
  108. WireConnection;343;2;339;0
  109. WireConnection;343;9;344;0
  110. WireConnection;343;4;352;0
  111. WireConnection;345;0;346;0
  112. WireConnection;345;1;347;0
  113. WireConnection;345;2;347;0
  114. WireConnection;345;9;344;0
  115. WireConnection;345;4;352;0
  116. WireConnection;0;0;343;0
  117. WireConnection;0;1;345;0
  118. WireConnection;0;3;212;0
  119. WireConnection;0;4;213;0
  120. ASEEND*/
  121. //CHKSM=D6356C30BD158BF416AA73E4BB09D631E58AE42C