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.

308 lines
14 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/Parallax/SandPom"
  4. {
  5. Properties
  6. {
  7. [HideInInspector] __dirty( "", Int ) = 1
  8. _Albedo("Albedo", 2D) = "white" {}
  9. _Normal("Normal", 2D) = "bump" {}
  10. _NormalScale("Normal Scale", Float) = 0.5
  11. _Metallic("Metallic", 2D) = "white" {}
  12. _Roughness("Roughness", 2D) = "white" {}
  13. _RoughScale("Rough Scale", Float) = 0.5
  14. _Occlusion("Occlusion", 2D) = "white" {}
  15. _HeightMap("HeightMap", 2D) = "white" {}
  16. _Scale("Scale", Range( 0 , 1)) = 0.4247461
  17. _CurvatureU("Curvature U", Range( 0 , 100)) = 0
  18. _CurvatureV("Curvature V", Range( 0 , 30)) = 0
  19. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  20. [Header(Parallax Occlusion Mapping)]
  21. _CurvFix("Curvature Bias", Range( 0 , 1)) = 1
  22. }
  23. SubShader
  24. {
  25. Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
  26. Cull Back
  27. ZTest LEqual
  28. CGINCLUDE
  29. #include "UnityStandardUtils.cginc"
  30. #include "UnityPBSLighting.cginc"
  31. #include "Lighting.cginc"
  32. #pragma target 4.0
  33. #ifdef UNITY_PASS_SHADOWCASTER
  34. #undef INTERNAL_DATA
  35. #undef WorldReflectionVector
  36. #undef WorldNormalVector
  37. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  38. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  39. #define WorldNormalVector(data,normal) fixed3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  40. #endif
  41. struct Input
  42. {
  43. float2 uv_texcoord;
  44. float3 viewDir;
  45. INTERNAL_DATA
  46. float3 worldNormal;
  47. float3 worldPos;
  48. };
  49. uniform float _NormalScale;
  50. uniform sampler2D _Normal;
  51. uniform float4 _Albedo_ST;
  52. uniform sampler2D _HeightMap;
  53. uniform float _Scale;
  54. uniform float _CurvFix;
  55. uniform float _CurvatureU;
  56. uniform float _CurvatureV;
  57. uniform float4 _HeightMap_ST;
  58. uniform sampler2D _Albedo;
  59. uniform sampler2D _Metallic;
  60. uniform float _RoughScale;
  61. uniform sampler2D _Roughness;
  62. uniform sampler2D _Occlusion;
  63. inline float2 POM( sampler2D heightMap, float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv )
  64. {
  65. float3 result = 0;
  66. int stepIndex = 0;
  67. int numSteps = ( int )lerp( maxSamples, minSamples, dot( normalWorld, viewWorld ) );
  68. float layerHeight = 1.0 / numSteps;
  69. float2 plane = parallax * ( viewDirTan.xy / viewDirTan.z );
  70. uvs += refPlane * plane;
  71. float2 deltaTex = -plane * layerHeight;
  72. float2 prevTexOffset = 0;
  73. float prevRayZ = 1.0f;
  74. float prevHeight = 0.0f;
  75. float2 currTexOffset = deltaTex;
  76. float currRayZ = 1.0f - layerHeight;
  77. float currHeight = 0.0f;
  78. float intersection = 0;
  79. float2 finalTexOffset = 0;
  80. while ( stepIndex < numSteps + 1 )
  81. {
  82. result.z = dot( curv, currTexOffset * currTexOffset );
  83. currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy ).r * ( 1 - result.z );
  84. if ( currHeight > currRayZ )
  85. {
  86. stepIndex = numSteps + 1;
  87. }
  88. else
  89. {
  90. stepIndex++;
  91. prevTexOffset = currTexOffset;
  92. prevRayZ = currRayZ;
  93. prevHeight = currHeight;
  94. currTexOffset += deltaTex;
  95. currRayZ -= layerHeight * ( 1 - result.z ) * (1+_CurvFix);
  96. }
  97. }
  98. int sectionSteps = 10;
  99. int sectionIndex = 0;
  100. float newZ = 0;
  101. float newHeight = 0;
  102. while ( sectionIndex < sectionSteps )
  103. {
  104. intersection = ( prevHeight - prevRayZ ) / ( prevHeight - currHeight + currRayZ - prevRayZ );
  105. finalTexOffset = prevTexOffset + intersection * deltaTex;
  106. newZ = prevRayZ - intersection * layerHeight;
  107. newHeight = tex2Dgrad( heightMap, uvs + finalTexOffset, dx, dy ).r;
  108. if ( newHeight > newZ )
  109. {
  110. currTexOffset = finalTexOffset;
  111. currHeight = newHeight;
  112. currRayZ = newZ;
  113. deltaTex = intersection * deltaTex;
  114. layerHeight = intersection * layerHeight;
  115. }
  116. else
  117. {
  118. prevTexOffset = finalTexOffset;
  119. prevHeight = newHeight;
  120. prevRayZ = newZ;
  121. deltaTex = ( 1 - intersection ) * deltaTex;
  122. layerHeight = ( 1 - intersection ) * layerHeight;
  123. }
  124. sectionIndex++;
  125. }
  126. #ifdef UNITY_PASS_SHADOWCASTER
  127. if ( unity_LightShadowBias.z == 0.0 )
  128. {
  129. #endif
  130. if ( result.z > 1 )
  131. clip( -1 );
  132. #ifdef UNITY_PASS_SHADOWCASTER
  133. }
  134. #endif
  135. return uvs + finalTexOffset;
  136. }
  137. void surf( Input i , inout SurfaceOutputStandard o )
  138. {
  139. float2 uv_Albedo = i.uv_texcoord * _Albedo_ST.xy + _Albedo_ST.zw;
  140. float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
  141. float3 worldViewDir = normalize( UnityWorldSpaceViewDir( i.worldPos ) );
  142. float2 appendResult47 = (float2(_CurvatureU , _CurvatureV));
  143. float2 OffsetPOM8 = POM( _HeightMap, uv_Albedo, ddx(uv_Albedo), ddx(uv_Albedo), ase_worldNormal, worldViewDir, i.viewDir, 128, 128, _Scale, 0, _HeightMap_ST.xy, appendResult47 );
  144. float2 customUVs39 = OffsetPOM8;
  145. float2 temp_output_40_0 = ddx( uv_Albedo );
  146. float2 temp_output_41_0 = ddy( uv_Albedo );
  147. o.Normal = UnpackScaleNormal( tex2D( _Normal, customUVs39, temp_output_40_0, temp_output_41_0 ) ,_NormalScale );
  148. o.Albedo = tex2D( _Albedo, customUVs39, temp_output_40_0, temp_output_41_0 ).xyz;
  149. o.Metallic = tex2D( _Metallic, customUVs39, temp_output_40_0, temp_output_41_0 ).r;
  150. o.Smoothness = ( 1.0 - ( _RoughScale * tex2D( _Roughness, customUVs39, temp_output_40_0, temp_output_41_0 ).r ) );
  151. o.Occlusion = tex2D( _Occlusion, customUVs39, temp_output_40_0, temp_output_41_0 ).r;
  152. o.Alpha = 1;
  153. }
  154. ENDCG
  155. CGPROGRAM
  156. #pragma surface surf Standard keepalpha fullforwardshadows exclude_path:deferred
  157. ENDCG
  158. Pass
  159. {
  160. Name "ShadowCaster"
  161. Tags{ "LightMode" = "ShadowCaster" }
  162. ZWrite On
  163. CGPROGRAM
  164. #pragma vertex vert
  165. #pragma fragment frag
  166. #pragma target 3.0
  167. #pragma multi_compile_shadowcaster
  168. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  169. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  170. # include "HLSLSupport.cginc"
  171. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  172. #define CAN_SKIP_VPOS
  173. #endif
  174. #include "UnityCG.cginc"
  175. #include "Lighting.cginc"
  176. #include "UnityPBSLighting.cginc"
  177. sampler3D _DitherMaskLOD;
  178. struct v2f
  179. {
  180. V2F_SHADOW_CASTER;
  181. float3 worldPos : TEXCOORD6;
  182. float4 tSpace0 : TEXCOORD1;
  183. float4 tSpace1 : TEXCOORD2;
  184. float4 tSpace2 : TEXCOORD3;
  185. float4 texcoords01 : TEXCOORD4;
  186. UNITY_VERTEX_INPUT_INSTANCE_ID
  187. };
  188. v2f vert( appdata_full v )
  189. {
  190. v2f o;
  191. UNITY_SETUP_INSTANCE_ID( v );
  192. UNITY_INITIALIZE_OUTPUT( v2f, o );
  193. UNITY_TRANSFER_INSTANCE_ID( v, o );
  194. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  195. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  196. fixed3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  197. fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  198. fixed3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  199. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  200. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  201. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  202. o.texcoords01 = float4( v.texcoord.xy, v.texcoord1.xy );
  203. o.worldPos = worldPos;
  204. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  205. return o;
  206. }
  207. fixed4 frag( v2f IN
  208. #if !defined( CAN_SKIP_VPOS )
  209. , UNITY_VPOS_TYPE vpos : VPOS
  210. #endif
  211. ) : SV_Target
  212. {
  213. UNITY_SETUP_INSTANCE_ID( IN );
  214. Input surfIN;
  215. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  216. surfIN.uv_texcoord.xy = IN.texcoords01.xy;
  217. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  218. fixed3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  219. surfIN.viewDir = IN.tSpace0.xyz * worldViewDir.x + IN.tSpace1.xyz * worldViewDir.y + IN.tSpace2.xyz * worldViewDir.z;
  220. surfIN.worldPos = worldPos;
  221. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  222. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  223. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  224. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  225. SurfaceOutputStandard o;
  226. UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandard, o )
  227. surf( surfIN, o );
  228. #if defined( CAN_SKIP_VPOS )
  229. float2 vpos = IN.pos;
  230. #endif
  231. SHADOW_CASTER_FRAGMENT( IN )
  232. }
  233. ENDCG
  234. }
  235. }
  236. Fallback "Diffuse"
  237. CustomEditor "ASEMaterialInspector"
  238. }
  239. /*ASEBEGIN
  240. Version=12003
  241. 0;92;1541;926;2631.925;1174.842;3.044802;False;False
  242. Node;AmplifyShaderEditor.RangedFloatNode;43;-1504,384;Float;False;Property;_CurvatureU;Curvature U;9;0;0;0;100;0;1;FLOAT
  243. Node;AmplifyShaderEditor.RangedFloatNode;45;-1504,464;Float;False;Property;_CurvatureV;Curvature V;9;0;0;0;30;0;1;FLOAT
  244. Node;AmplifyShaderEditor.ViewDirInputsCoordNode;15;-1296,192;Float;False;Tangent;0;4;FLOAT3;FLOAT;FLOAT;FLOAT
  245. Node;AmplifyShaderEditor.DynamicAppendNode;47;-1168,368;Float;False;FLOAT2;4;0;FLOAT;0.0;False;1;FLOAT;0.0;False;2;FLOAT;0.0;False;3;FLOAT;0.0;False;1;FLOAT2
  246. Node;AmplifyShaderEditor.TexturePropertyNode;9;-1729,0.5;Float;True;Property;_HeightMap;HeightMap;7;0;None;False;white;Auto;0;1;SAMPLER2D
  247. Node;AmplifyShaderEditor.RangedFloatNode;13;-1448,78.5;Float;False;Property;_Scale;Scale;8;0;0.4247461;0;1;0;1;FLOAT
  248. Node;AmplifyShaderEditor.TextureCoordinatesNode;10;-1384,-81.5;Float;False;0;11;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;FLOAT;FLOAT;FLOAT;FLOAT
  249. Node;AmplifyShaderEditor.ParallaxOcclusionMappingNode;8;-1032.9,-21.1;Float;False;0;128;128;10;0.02;0;False;1,1;True;10,0;6;0;FLOAT2;0,0;False;1;SAMPLER2D;;False;2;FLOAT;0.0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0.0;False;5;FLOAT2;0,0;False;1;FLOAT2
  250. Node;AmplifyShaderEditor.DdxOpNode;40;-656,-160;Float;False;1;0;FLOAT2;0.0,0;False;1;FLOAT2
  251. Node;AmplifyShaderEditor.DdyOpNode;41;-656,-96;Float;False;1;0;FLOAT2;0.0,0;False;1;FLOAT2
  252. Node;AmplifyShaderEditor.RegisterLocalVarNode;39;-752,-240;Float;False;customUVs;1;False;1;0;FLOAT2;0.0,0;False;1;FLOAT2
  253. Node;AmplifyShaderEditor.RangedFloatNode;25;192,256;Float;False;Property;_RoughScale;Rough Scale;5;0;0.5;0;0;0;1;FLOAT
  254. Node;AmplifyShaderEditor.SamplerNode;20;64,336;Float;True;Property;_Roughness;Roughness;4;0;None;True;0;False;white;Auto;False;Object;-1;Derivative;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
  255. Node;AmplifyShaderEditor.SamplerNode;21;64,528;Float;True;Property;_Occlusion;Occlusion;6;0;None;True;0;False;white;Auto;False;Object;-1;Derivative;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
  256. Node;AmplifyShaderEditor.RangedFloatNode;24;-292.5285,-343.4738;Float;False;Property;_NormalScale;Normal Scale;2;0;0.5;0;0;0;1;FLOAT
  257. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;26;384,256;Float;False;2;2;0;FLOAT;0.0;False;1;FLOAT;0.0;False;1;FLOAT
  258. Node;AmplifyShaderEditor.OneMinusNode;42;496,80;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  259. Node;AmplifyShaderEditor.SamplerNode;11;64,-320;Float;True;Property;_Albedo;Albedo;0;0;None;True;0;False;white;Auto;False;Object;-1;Derivative;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
  260. Node;AmplifyShaderEditor.WireNode;29;620.7496,395.8717;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  261. Node;AmplifyShaderEditor.SamplerNode;23;64,64;Float;True;Property;_Metallic;Metallic;3;0;None;True;0;False;white;Auto;False;Object;-1;Derivative;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
  262. Node;AmplifyShaderEditor.SamplerNode;14;64,-128;Float;True;Property;_Normal;Normal;1;0;None;True;0;True;bump;Auto;True;Object;-1;Derivative;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;FLOAT3;FLOAT;FLOAT;FLOAT;FLOAT
  263. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;780.7046,-269.0693;Float;False;True;4;Float;ASEMaterialInspector;0;Standard;ASESampleShaders/Parallax/SandPom;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;3;False;0;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;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;False;0;0,0,0,0;VertexOffset;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;0;15;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;5;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,0;False;12;FLOAT3;0.0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
  264. WireConnection;47;0;43;0
  265. WireConnection;47;1;45;0
  266. WireConnection;8;0;10;0
  267. WireConnection;8;1;9;0
  268. WireConnection;8;2;13;0
  269. WireConnection;8;3;15;0
  270. WireConnection;8;5;47;0
  271. WireConnection;40;0;10;0
  272. WireConnection;41;0;10;0
  273. WireConnection;39;0;8;0
  274. WireConnection;20;1;39;0
  275. WireConnection;20;3;40;0
  276. WireConnection;20;4;41;0
  277. WireConnection;21;1;39;0
  278. WireConnection;21;3;40;0
  279. WireConnection;21;4;41;0
  280. WireConnection;26;0;25;0
  281. WireConnection;26;1;20;1
  282. WireConnection;42;0;26;0
  283. WireConnection;11;1;39;0
  284. WireConnection;11;3;40;0
  285. WireConnection;11;4;41;0
  286. WireConnection;29;0;21;1
  287. WireConnection;23;1;39;0
  288. WireConnection;23;3;40;0
  289. WireConnection;23;4;41;0
  290. WireConnection;14;1;39;0
  291. WireConnection;14;3;40;0
  292. WireConnection;14;4;41;0
  293. WireConnection;14;5;24;0
  294. WireConnection;0;0;11;0
  295. WireConnection;0;1;14;0
  296. WireConnection;0;3;23;1
  297. WireConnection;0;4;42;0
  298. WireConnection;0;5;29;0
  299. ASEEND*/
  300. //CHKSM=05D9E04B90638290E79154C9F649C97B39B0B599