POLYGON_Triplanar.shader 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "SyntyStudios/Triplanar"
  4. {
  5. Properties
  6. {
  7. _Overlay("Overlay", 2D) = "white" {}
  8. _FallOff("FallOff", Float) = 0
  9. _Tiling("Tiling", Float) = 0
  10. _Emission("Emission", 2D) = "white" {}
  11. _Texture("Texture", 2D) = "white" {}
  12. _EmissionColor("EmissionColor", Color) = (0,0,0,0)
  13. _DirtAmount("DirtAmount", Range( 0.5 , 1.2)) = 1
  14. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  15. [HideInInspector] __dirty( "", Int ) = 1
  16. }
  17. SubShader
  18. {
  19. Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" "IsEmissive" = "true" }
  20. Cull Back
  21. CGINCLUDE
  22. #include "UnityPBSLighting.cginc"
  23. #include "Lighting.cginc"
  24. #pragma target 3.0
  25. #ifdef UNITY_PASS_SHADOWCASTER
  26. #undef INTERNAL_DATA
  27. #undef WorldReflectionVector
  28. #undef WorldNormalVector
  29. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  30. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  31. #define WorldNormalVector(data,normal) half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  32. #endif
  33. struct Input
  34. {
  35. float2 uv_texcoord;
  36. float3 worldPos;
  37. float3 worldNormal;
  38. INTERNAL_DATA
  39. };
  40. uniform sampler2D _Texture;
  41. uniform float4 _Texture_ST;
  42. uniform sampler2D _Overlay;
  43. uniform float _Tiling;
  44. uniform float _FallOff;
  45. uniform float _DirtAmount;
  46. uniform sampler2D _Emission;
  47. uniform float4 _Emission_ST;
  48. uniform float4 _EmissionColor;
  49. inline float4 TriplanarSamplingCF( sampler2D topTexMap, sampler2D midTexMap, sampler2D botTexMap, float3 worldPos, float3 worldNormal, float falloff, float tilling, float3 normalScale, float3 index )
  50. {
  51. float3 projNormal = ( pow( abs( worldNormal ), falloff ) );
  52. projNormal /= ( projNormal.x + projNormal.y + projNormal.z ) + 0.00001;
  53. float3 nsign = sign( worldNormal );
  54. float negProjNormalY = max( 0, projNormal.y * -nsign.y );
  55. projNormal.y = max( 0, projNormal.y * nsign.y );
  56. half4 xNorm; half4 yNorm; half4 yNormN; half4 zNorm;
  57. xNorm = ( tex2D( midTexMap, tilling * worldPos.zy * float2( nsign.x, 1.0 ) ) );
  58. yNorm = ( tex2D( topTexMap, tilling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  59. yNormN = ( tex2D( botTexMap, tilling * worldPos.xz * float2( nsign.y, 1.0 ) ) );
  60. zNorm = ( tex2D( midTexMap, tilling * worldPos.xy * float2( -nsign.z, 1.0 ) ) );
  61. return xNorm * projNormal.x + yNorm * projNormal.y + yNormN * negProjNormalY + zNorm * projNormal.z;
  62. }
  63. void surf( Input i , inout SurfaceOutputStandard o )
  64. {
  65. o.Normal = float3(0,0,1);
  66. float2 uv_Texture = i.uv_texcoord * _Texture_ST.xy + _Texture_ST.zw;
  67. float3 ase_worldPos = i.worldPos;
  68. float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
  69. float4 triplanar1 = TriplanarSamplingCF( _Overlay, _Overlay, _Overlay, ase_worldPos, ase_worldNormal, _FallOff, _Tiling, float3( 1,1,1 ), float3(0,0,0) );
  70. float4 temp_cast_0 = (_DirtAmount).xxxx;
  71. float4 clampResult17 = clamp( triplanar1 , temp_cast_0 , float4( 1,1,1,0 ) );
  72. o.Albedo = ( tex2D( _Texture, uv_Texture ) * clampResult17 ).rgb;
  73. float2 uv_Emission = i.uv_texcoord * _Emission_ST.xy + _Emission_ST.zw;
  74. o.Emission = ( tex2D( _Emission, uv_Emission ) * _EmissionColor ).rgb;
  75. o.Alpha = 1;
  76. }
  77. ENDCG
  78. CGPROGRAM
  79. #pragma surface surf Standard keepalpha fullforwardshadows
  80. ENDCG
  81. Pass
  82. {
  83. Name "ShadowCaster"
  84. Tags{ "LightMode" = "ShadowCaster" }
  85. ZWrite On
  86. CGPROGRAM
  87. #pragma vertex vert
  88. #pragma fragment frag
  89. #pragma target 3.0
  90. #pragma multi_compile_shadowcaster
  91. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  92. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  93. #include "HLSLSupport.cginc"
  94. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  95. #define CAN_SKIP_VPOS
  96. #endif
  97. #include "UnityCG.cginc"
  98. #include "Lighting.cginc"
  99. #include "UnityPBSLighting.cginc"
  100. struct v2f
  101. {
  102. V2F_SHADOW_CASTER;
  103. float2 customPack1 : TEXCOORD1;
  104. float4 tSpace0 : TEXCOORD2;
  105. float4 tSpace1 : TEXCOORD3;
  106. float4 tSpace2 : TEXCOORD4;
  107. UNITY_VERTEX_INPUT_INSTANCE_ID
  108. };
  109. v2f vert( appdata_full v )
  110. {
  111. v2f o;
  112. UNITY_SETUP_INSTANCE_ID( v );
  113. UNITY_INITIALIZE_OUTPUT( v2f, o );
  114. UNITY_TRANSFER_INSTANCE_ID( v, o );
  115. Input customInputData;
  116. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  117. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  118. half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  119. half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  120. half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  121. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  122. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  123. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  124. o.customPack1.xy = customInputData.uv_texcoord;
  125. o.customPack1.xy = v.texcoord;
  126. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  127. return o;
  128. }
  129. half4 frag( v2f IN
  130. #if !defined( CAN_SKIP_VPOS )
  131. , UNITY_VPOS_TYPE vpos : VPOS
  132. #endif
  133. ) : SV_Target
  134. {
  135. UNITY_SETUP_INSTANCE_ID( IN );
  136. Input surfIN;
  137. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  138. surfIN.uv_texcoord = IN.customPack1.xy;
  139. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  140. half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  141. surfIN.worldPos = worldPos;
  142. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  143. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  144. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  145. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  146. SurfaceOutputStandard o;
  147. UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandard, o )
  148. surf( surfIN, o );
  149. #if defined( CAN_SKIP_VPOS )
  150. float2 vpos = IN.pos;
  151. #endif
  152. SHADOW_CASTER_FRAGMENT( IN )
  153. }
  154. ENDCG
  155. }
  156. }
  157. Fallback "Diffuse"
  158. CustomEditor "ASEMaterialInspector"
  159. }
  160. /*ASEBEGIN
  161. Version=16200
  162. 2567;32;2546;1397;1501.224;816.0149;1.07;True;False
  163. Node;AmplifyShaderEditor.RangedFloatNode;3;-489.21,-60.51;Float;False;Property;_Tiling;Tiling;2;0;Create;True;0;0;False;0;0;6.24;0;0;0;1;FLOAT;0
  164. Node;AmplifyShaderEditor.TexturePropertyNode;2;-514,-296;Float;True;Property;_Overlay;Overlay;0;0;Create;True;0;0;False;0;None;9e88b336bd16b1e4b99de75f486126c1;False;white;Auto;Texture2D;0;1;SAMPLER2D;0
  165. Node;AmplifyShaderEditor.RangedFloatNode;4;-485,63;Float;False;Property;_FallOff;FallOff;1;0;Create;True;0;0;False;0;0;5.01;0;0;0;1;FLOAT;0
  166. Node;AmplifyShaderEditor.RangedFloatNode;15;-156.2343,6.280043;Float;False;Property;_DirtAmount;DirtAmount;6;0;Create;True;0;0;False;0;1;0;0.5;1.2;0;1;FLOAT;0
  167. Node;AmplifyShaderEditor.TriplanarNode;1;-163.14,-299.8202;Float;True;Cylindrical;World;False;Top Texture 0;_TopTexture0;white;1;None;Mid Texture 0;_MidTexture0;white;-1;None;Bot Texture 0;_BotTexture0;white;0;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;1;False;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  168. Node;AmplifyShaderEditor.ColorNode;11;68.00011,303;Float;False;Property;_EmissionColor;EmissionColor;5;0;Create;True;0;0;False;0;0,0,0,0;0.1878804,0.6724138,0.6296608,1;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  169. Node;AmplifyShaderEditor.SamplerNode;7;-535.8401,-519.7598;Float;True;Property;_Texture;Texture;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
  170. Node;AmplifyShaderEditor.SamplerNode;9;-282.9999,207;Float;True;Property;_Emission;Emission;3;0;Create;True;0;0;False;0;84508b93f15f2b64386ec07486afc7a3;80ee511a5808d8d499a8ca850b8a2129;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
  171. Node;AmplifyShaderEditor.ClampOpNode;17;322.0553,-304.0211;Float;False;3;0;FLOAT4;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;2;FLOAT4;1,1,1,0;False;1;FLOAT4;0
  172. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;8;636.5526,-465.2808;Float;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;COLOR;0
  173. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;10;237.0001,114;Float;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  174. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;716.0014,-25.1995;Float;False;True;2;Float;ASEMaterialInspector;0;0;Standard;SyntyStudios/Triplanar;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
  175. WireConnection;1;0;2;0
  176. WireConnection;1;1;2;0
  177. WireConnection;1;2;2;0
  178. WireConnection;1;3;3;0
  179. WireConnection;1;4;4;0
  180. WireConnection;17;0;1;0
  181. WireConnection;17;1;15;0
  182. WireConnection;8;0;7;0
  183. WireConnection;8;1;17;0
  184. WireConnection;10;0;9;0
  185. WireConnection;10;1;11;0
  186. WireConnection;0;0;8;0
  187. WireConnection;0;2;10;0
  188. ASEEND*/
  189. //CHKSM=EB6B4A204CCF3BCDCFAB8D6684B8C64D4663B314