SyntyStudios_Triplanar_ObjectSpace.shader 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "SyntyStudios/Triplanar_ObjectSpace"
  4. {
  5. Properties
  6. {
  7. _Texture("Texture", 2D) = "white" {}
  8. _Decal("Decal", 2D) = "white" {}
  9. _Emiss("Emiss", 2D) = "white" {}
  10. _Spec("Spec", 2D) = "white" {}
  11. _Overlay("Overlay", 2D) = "white" {}
  12. _Tiling("Tiling", Float) = 0
  13. _Falloff("Falloff", Float) = 0
  14. _OverlayAmount("OverlayAmount", Float) = 0
  15. _Smoothness("Smoothness", Color) = (0,0,0,0)
  16. [HideInInspector] _texcoord2( "", 2D ) = "white" {}
  17. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  18. [HideInInspector] __dirty( "", Int ) = 1
  19. }
  20. SubShader
  21. {
  22. Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" "IsEmissive" = "true" }
  23. Cull Back
  24. CGINCLUDE
  25. #include "UnityPBSLighting.cginc"
  26. #include "Lighting.cginc"
  27. #pragma target 3.0
  28. #ifdef UNITY_PASS_SHADOWCASTER
  29. #undef INTERNAL_DATA
  30. #undef WorldReflectionVector
  31. #undef WorldNormalVector
  32. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  33. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  34. #define WorldNormalVector(data,normal) half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  35. #endif
  36. struct Input
  37. {
  38. float2 uv2_texcoord2;
  39. float2 uv_texcoord;
  40. float3 worldPos;
  41. float3 worldNormal;
  42. INTERNAL_DATA
  43. };
  44. uniform sampler2D _Decal;
  45. uniform float4 _Decal_ST;
  46. uniform sampler2D _Texture;
  47. uniform float4 _Texture_ST;
  48. uniform sampler2D _Overlay;
  49. uniform float _Tiling;
  50. uniform float _Falloff;
  51. uniform float _OverlayAmount;
  52. uniform sampler2D _Emiss;
  53. uniform float4 _Emiss_ST;
  54. uniform sampler2D _Spec;
  55. uniform float4 _Spec_ST;
  56. uniform float4 _Smoothness;
  57. inline float4 TriplanarSamplingCF( sampler2D topTexMap, sampler2D midTexMap, sampler2D botTexMap, float3 worldPos, float3 worldNormal, float falloff, float tilling, float3 normalScale, float3 index )
  58. {
  59. float3 projNormal = ( pow( abs( worldNormal ), falloff ) );
  60. projNormal /= ( projNormal.x + projNormal.y + projNormal.z ) + 0.00001;
  61. float3 nsign = sign( worldNormal );
  62. float negProjNormalY = max( 0, projNormal.y * -nsign.y );
  63. projNormal.y = max( 0, projNormal.y * nsign.y );
  64. half4 xNorm; half4 yNorm; half4 yNormN; half4 zNorm;
  65. xNorm = ( tex2D( midTexMap, tilling * worldPos.zy * float2( nsign.x, 1.0 ) ) );
  66. yNorm = ( tex2D( topTexMap, tilling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  67. yNormN = ( tex2D( botTexMap, tilling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  68. zNorm = ( tex2D( midTexMap, tilling * worldPos.xy * float2( -nsign.z, 1.0 ) ) );
  69. return xNorm * projNormal.x + yNorm * projNormal.y + yNormN * negProjNormalY + zNorm * projNormal.z;
  70. }
  71. void surf( Input i , inout SurfaceOutputStandard o )
  72. {
  73. o.Normal = float3(0,0,1);
  74. float2 uv2_Decal = i.uv2_texcoord2 * _Decal_ST.xy + _Decal_ST.zw;
  75. float2 uv_Texture = i.uv_texcoord * _Texture_ST.xy + _Texture_ST.zw;
  76. float4 blendOpSrc28 = tex2D( _Decal, uv2_Decal );
  77. float4 blendOpDest28 = tex2D( _Texture, uv_Texture );
  78. float3 ase_worldPos = i.worldPos;
  79. float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
  80. float3 localPos = mul( unity_WorldToObject, float4( ase_worldPos, 1 ) );
  81. float3 localNormal = mul( unity_WorldToObject, float4( ase_worldNormal, 0 ) );
  82. float4 triplanar5 = TriplanarSamplingCF( _Overlay, _Overlay, _Overlay, localPos, localNormal, _Falloff, _Tiling, float3( 1,1,1 ), float3(0,0,0) );
  83. o.Albedo = ( ( saturate( ( blendOpSrc28 * blendOpDest28 ) )) * ( triplanar5 * _OverlayAmount ) ).rgb;
  84. float2 uv_Emiss = i.uv_texcoord * _Emiss_ST.xy + _Emiss_ST.zw;
  85. float4 tex2DNode25 = tex2D( _Emiss, uv_Emiss );
  86. o.Emission = tex2DNode25.rgb;
  87. float2 uv_Spec = i.uv_texcoord * _Spec_ST.xy + _Spec_ST.zw;
  88. float4 tex2DNode39 = tex2D( _Spec, uv_Spec );
  89. o.Metallic = tex2DNode39.r;
  90. o.Smoothness = _Smoothness.r;
  91. o.Alpha = 1;
  92. }
  93. ENDCG
  94. CGPROGRAM
  95. #pragma surface surf Standard keepalpha fullforwardshadows
  96. ENDCG
  97. Pass
  98. {
  99. Name "ShadowCaster"
  100. Tags{ "LightMode" = "ShadowCaster" }
  101. ZWrite On
  102. CGPROGRAM
  103. #pragma vertex vert
  104. #pragma fragment frag
  105. #pragma target 3.0
  106. #pragma multi_compile_shadowcaster
  107. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  108. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  109. #include "HLSLSupport.cginc"
  110. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  111. #define CAN_SKIP_VPOS
  112. #endif
  113. #include "UnityCG.cginc"
  114. #include "Lighting.cginc"
  115. #include "UnityPBSLighting.cginc"
  116. struct v2f
  117. {
  118. V2F_SHADOW_CASTER;
  119. float4 customPack1 : TEXCOORD1;
  120. float4 tSpace0 : TEXCOORD2;
  121. float4 tSpace1 : TEXCOORD3;
  122. float4 tSpace2 : TEXCOORD4;
  123. UNITY_VERTEX_INPUT_INSTANCE_ID
  124. };
  125. v2f vert( appdata_full v )
  126. {
  127. v2f o;
  128. UNITY_SETUP_INSTANCE_ID( v );
  129. UNITY_INITIALIZE_OUTPUT( v2f, o );
  130. UNITY_TRANSFER_INSTANCE_ID( v, o );
  131. Input customInputData;
  132. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  133. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  134. half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  135. half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  136. half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  137. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  138. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  139. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  140. o.customPack1.xy = customInputData.uv2_texcoord2;
  141. o.customPack1.xy = v.texcoord1;
  142. o.customPack1.zw = customInputData.uv_texcoord;
  143. o.customPack1.zw = v.texcoord;
  144. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  145. return o;
  146. }
  147. half4 frag( v2f IN
  148. #if !defined( CAN_SKIP_VPOS )
  149. , UNITY_VPOS_TYPE vpos : VPOS
  150. #endif
  151. ) : SV_Target
  152. {
  153. UNITY_SETUP_INSTANCE_ID( IN );
  154. Input surfIN;
  155. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  156. surfIN.uv2_texcoord2 = IN.customPack1.xy;
  157. surfIN.uv_texcoord = IN.customPack1.zw;
  158. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  159. half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  160. surfIN.worldPos = worldPos;
  161. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  162. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  163. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  164. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  165. SurfaceOutputStandard o;
  166. UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandard, o )
  167. surf( surfIN, o );
  168. #if defined( CAN_SKIP_VPOS )
  169. float2 vpos = IN.pos;
  170. #endif
  171. SHADOW_CASTER_FRAGMENT( IN )
  172. }
  173. ENDCG
  174. }
  175. }
  176. Fallback "Diffuse"
  177. CustomEditor "ASEMaterialInspector"
  178. }
  179. /*ASEBEGIN
  180. Version=16200
  181. 2567;32;2546;1397;2593.814;439.5397;1.255;True;False
  182. Node;AmplifyShaderEditor.TexturePropertyNode;6;-1466.299,58.7578;Float;True;Property;_Overlay;Overlay;6;0;Create;True;0;0;False;0;None;93e718fcc411432439749387d41fa07a;False;white;Auto;Texture2D;0;1;SAMPLER2D;0
  183. Node;AmplifyShaderEditor.RangedFloatNode;7;-1453.889,253.0376;Float;False;Property;_Tiling;Tiling;7;0;Create;True;0;0;False;0;0;2.74;0;0;0;1;FLOAT;0
  184. Node;AmplifyShaderEditor.RangedFloatNode;13;-1445.5,344.5002;Float;False;Property;_Falloff;Falloff;9;0;Create;True;0;0;False;0;0;10;0;0;0;1;FLOAT;0
  185. Node;AmplifyShaderEditor.SamplerNode;4;-1645.439,-227.072;Float;True;Property;_Texture;Texture;0;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;84508b93f15f2b64386ec07486afc7a3;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  186. Node;AmplifyShaderEditor.SamplerNode;29;-1661.991,-456.7638;Float;True;Property;_Decal;Decal;1;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;84508b93f15f2b64386ec07486afc7a3;True;1;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  187. Node;AmplifyShaderEditor.RangedFloatNode;27;-948.991,334.2362;Float;False;Property;_OverlayAmount;OverlayAmount;11;0;Create;True;0;0;False;0;0;2.76;0;0;0;1;FLOAT;0
  188. Node;AmplifyShaderEditor.TriplanarNode;5;-1198.82,95.44791;Float;True;Cylindrical;Object;False;Top Texture 0;_TopTexture0;white;2;None;Mid Texture 0;_MidTexture0;white;1;None;Bot Texture 0;_BotTexture0;white;2;None;Triplanar Sampler;False;9;0;SAMPLER2D;;False;5;FLOAT;1;False;1;SAMPLER2D;;False;6;FLOAT;0;False;2;SAMPLER2D;;False;7;FLOAT;0;False;8;FLOAT3;1,1,1;False;3;FLOAT;1;False;4;FLOAT;100;False;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  189. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;26;-713.991,94.93617;Float;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT;0;False;1;FLOAT4;0
  190. Node;AmplifyShaderEditor.BlendOpsNode;28;-803.991,-384.7638;Float;True;Multiply;True;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  191. Node;AmplifyShaderEditor.SamplerNode;15;-1829.302,783.0169;Float;True;Global;Normals;Normals;10;0;Create;True;0;0;False;0;None;None;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;0,0;False;1;FLOAT2;1,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  192. Node;AmplifyShaderEditor.NormalizeNode;16;-1606.605,1051.917;Float;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3;0
  193. Node;AmplifyShaderEditor.PowerNode;22;-877.9045,1014.717;Float;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  194. Node;AmplifyShaderEditor.SamplerNode;42;-1215.82,494.1794;Float;True;Property;_Emis2;Emis2;3;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;84508b93f15f2b64386ec07486afc7a3;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  195. Node;AmplifyShaderEditor.RangedFloatNode;20;-1167.304,1106.717;Float;False;Property;_RimPower;RimPower;8;0;Create;True;0;0;False;0;0;6.11;0;10;0;1;FLOAT;0
  196. Node;AmplifyShaderEditor.ColorNode;21;-884.1041,1194.516;Float;False;Property;_RimColor;RimColor;5;0;Create;True;0;0;False;0;0,0,0,0;0.5810912,0.3900843,0.8161765,0;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  197. Node;AmplifyShaderEditor.ViewDirInputsCoordNode;14;-1829.302,1055.017;Float;False;Tangent;False;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
  198. Node;AmplifyShaderEditor.SimpleAddOpNode;41;-787.8645,613.4051;Float;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  199. Node;AmplifyShaderEditor.OneMinusNode;19;-1070.702,991.3159;Float;False;1;0;FLOAT;0;False;1;FLOAT;0
  200. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;23;-703.5043,1025.916;Float;False;2;2;0;FLOAT;0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  201. Node;AmplifyShaderEditor.SaturateNode;18;-1239.705,949.0169;Float;False;1;0;FLOAT;1.23;False;1;FLOAT;0
  202. Node;AmplifyShaderEditor.DotProductOpNode;17;-1414.905,973.5169;Float;False;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT;0
  203. Node;AmplifyShaderEditor.SimpleAddOpNode;24;-539.549,532.8794;Float;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  204. Node;AmplifyShaderEditor.ColorNode;31;-244.2706,459.1009;Float;False;Property;_Smoothness;Smoothness;12;0;Create;True;0;0;False;0;0,0,0,0;0.5955882,0.5955882,0.5955882,0;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  205. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;40;7.771705,50.4398;Float;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  206. Node;AmplifyShaderEditor.SamplerNode;25;-1212.115,695.0443;Float;True;Property;_Emiss;Emiss;2;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;84508b93f15f2b64386ec07486afc7a3;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  207. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;11;-465.2369,-22.28335;Float;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;COLOR;0
  208. Node;AmplifyShaderEditor.SamplerNode;39;-276.618,654.6751;Float;True;Property;_Spec;Spec;4;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;84508b93f15f2b64386ec07486afc7a3;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  209. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;300.8402,-52.49501;Float;False;True;2;Float;ASEMaterialInspector;0;0;Standard;SyntyStudios/Triplanar_ObjectSpace;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;False;-1;0;False;-1;False;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;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;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;0;False;-1;0;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;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;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
  210. WireConnection;5;0;6;0
  211. WireConnection;5;1;6;0
  212. WireConnection;5;2;6;0
  213. WireConnection;5;3;7;0
  214. WireConnection;5;4;13;0
  215. WireConnection;26;0;5;0
  216. WireConnection;26;1;27;0
  217. WireConnection;28;0;29;0
  218. WireConnection;28;1;4;0
  219. WireConnection;16;0;14;0
  220. WireConnection;22;0;19;0
  221. WireConnection;22;1;20;0
  222. WireConnection;41;0;42;0
  223. WireConnection;41;1;25;0
  224. WireConnection;19;0;18;0
  225. WireConnection;23;0;22;0
  226. WireConnection;23;1;21;0
  227. WireConnection;18;0;17;0
  228. WireConnection;17;0;15;0
  229. WireConnection;17;1;16;0
  230. WireConnection;24;0;23;0
  231. WireConnection;24;1;41;0
  232. WireConnection;40;0;24;0
  233. WireConnection;40;1;39;0
  234. WireConnection;11;0;28;0
  235. WireConnection;11;1;26;0
  236. WireConnection;0;0;11;0
  237. WireConnection;0;2;25;0
  238. WireConnection;0;3;39;0
  239. WireConnection;0;4;31;0
  240. ASEEND*/
  241. //CHKSM=F6B89CEF18FD53AD9EFB8ED45A9168608E9E393C