InTerra_SplatmapMix.hlsl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #ifdef INTERRA_OBJECT
  2. void ObjectIntegration_float(float heightOffset, float3 tangentViewDirTerrain, float3 worldViewDir, float3 worldNormal, float3 worldTangent, float3 worldBitangent, float2 detailUV, float3 worldPos, float4 terrainNormals, float4 objectAlbedo, float3 objectNormal, float4 objectMask, float3 objectEmission, out float3 albedo, out float3 mixedNormal, out float smoothness, out float metallic, out float occlusion, out float3 emission)
  3. #else
  4. #ifdef INTERRA_MESH_TERRAIN
  5. #ifndef TESSELLATION_ON
  6. void SplatmapMix_float(float3 tangentViewDirTerrain, float3 worldNormal, float3 worldPos,float3 worldTangent, float3 worldBitangent, out half3 mixedAlbedo, out half3 mixedNormal, out half smoothness, out half metallic, out half occlusion)
  7. #else
  8. void SplatmapMix_float(float3 worldNormal, float3 worldPos, float3 worldTangent, float3 worldBitangent, out half3 mixedAlbedo, out half3 mixedNormal, out half smoothness, out half metallic, out half occlusion)
  9. #endif
  10. #else
  11. #ifndef TESSELLATION_ON
  12. #include "InTerra_Functions.hlsl"
  13. #endif
  14. void SplatmapMix(float2 splatBaseUV, float3 worldNormal, float3 tangentViewDirTerrain, float3 worldPos, out float3 mixedAlbedo, out float smoothness, out float metallic, out float occlusion, inout float3 mixedNormal)
  15. #endif
  16. #endif
  17. {
  18. float4 mixedDiffuse;
  19. mixedNormal = float3(0, 0, 1);
  20. #include "InTerra_SplatMapControl.hlsl"
  21. //======================================================================
  22. //------------------------- OBJECT INTERSECTION ----------------------
  23. //======================================================================
  24. #ifdef INTERRA_OBJECT
  25. float steeptriplanarWeights = _SteepIntersection == 1 ? saturate(worldNormal.y + _Steepness) : 1;
  26. float intersect1 = smoothstep(_Intersection.y, _Intersection.x, heightOffset) * steeptriplanarWeights;
  27. float intersect2 = smoothstep(_Intersection2.y, _Intersection2.x, heightOffset) * (1 - steeptriplanarWeights);
  28. float intersection = intersect1 + intersect2;
  29. float intersectNormal = smoothstep(_NormIntersect.y, _NormIntersect.x, heightOffset);
  30. if (intersection < 1e-5f)
  31. {
  32. blendMask[0] = 0.0f;
  33. blendMask[1] = 0.0f;
  34. blendMask[2] = 0.0f;
  35. blendMask[3] = 0.0f;
  36. #if defined(_TERRAIN_DISTANCEBLEND)
  37. dBlendMask[0] = 0.0f;
  38. dBlendMask[1] = 0.0f;
  39. dBlendMask[2] = 0.0f;
  40. dBlendMask[3] = 0.0f;
  41. #endif
  42. }
  43. #endif
  44. //====================================================================================
  45. //----------------------------------- MASK MAPS ------------------------------------
  46. //====================================================================================
  47. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  48. #ifdef _TERRAIN_TRIPLANAR_ONE
  49. SampleMask(mask, uvSplat, blendMask, triplanarWeights.y + (1 - blendMask[0].r));
  50. SampleMaskTOL(mask_front, mask, uvSplat_front, triplanarWeights.z);
  51. SampleMaskTOL(mask_side, mask, uvSplat_side, triplanarWeights.x);
  52. #else
  53. SampleMask(mask, uvSplat, blendMask, triplanarWeights.y);
  54. SampleMask(mask_front, uvSplat_front, blendMask, triplanarWeights.z);
  55. SampleMask(mask_side, uvSplat_side, blendMask, triplanarWeights.x);
  56. #endif
  57. MaskWeight(mask, mask_front, mask_side, blendMask, triplanarWeights, _HeightTransition);
  58. #else
  59. SampleMask(mask, uvSplat, blendMask, 1.0f);
  60. #endif
  61. #ifdef _TERRAIN_DISTANCEBLEND
  62. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  63. #ifdef _TERRAIN_TRIPLANAR_ONE
  64. SampleMask(dMask, distantUV, dBlendMask, saturate(triplanarWeights.y + (1 - dBlendMask[0].r)));
  65. SampleMaskTOL(dMask_front, dMask, distantUV_front, blendMask[0].r * triplanarWeights.z );
  66. SampleMaskTOL(dMask_side, dMask, distantUV_side, blendMask[0].r * triplanarWeights.x );
  67. #else
  68. SampleMask(dMask, distantUV, dBlendMask, triplanarWeights.y);
  69. SampleMask(dMask_front, distantUV_front, dBlendMask, triplanarWeights.z);
  70. SampleMask(dMask_side, distantUV_side, dBlendMask, triplanarWeights.x);
  71. #endif
  72. MaskWeight(dMask, dMask_front, dMask_side, dBlendMask, triplanarWeights, _Distance_HeightTransition);
  73. #else
  74. SampleMask(dMask, distantUV, dBlendMask, 1.0f);
  75. #endif
  76. dBlendMask = dOrigBlendMask;
  77. #endif
  78. blendMask = origBlendMask;
  79. //========================================================================================
  80. //------------------------------ HEIGHT MAP SPLAT BLENDINGS ------------------------------
  81. //========================================================================================
  82. #if defined(_TERRAIN_BLEND_HEIGHT) && !defined(_LAYERS_ONE) && !defined(TERRAIN_SPLAT_ADDPASS)
  83. if (_HeightmapBlending == 1)
  84. {
  85. HeightBlend(mask, blendMask, _HeightTransition);
  86. #ifdef _TERRAIN_DISTANCEBLEND
  87. HeightBlend(dMask, dBlendMask, _Distance_HeightTransition);
  88. #endif
  89. }
  90. #endif
  91. //-------------------- HEIGHTMAP OBJECT INTERSECTION ----------------
  92. MaskSplatWeight(mask, blendMask, mixedMask);
  93. #ifdef _TERRAIN_DISTANCEBLEND
  94. MaskSplatWeight(dMask, dBlendMask, dMixedMask);
  95. dMixedMask = lerp(mixedMask, dMixedMask, _HT_cover);
  96. mixedMask = lerp(mixedMask, dMixedMask, dist);
  97. #endif
  98. occlusion = mixedMask.g;
  99. metallic = mixedMask.r;
  100. heightSum = mixedMask.b;
  101. #if defined(_TERRAIN_BLEND_HEIGHT) && !defined(_LAYERS_ONE) && !defined(TERRAIN_SPLAT_ADDPASS)
  102. if (_HeightmapBlending == 1)
  103. {
  104. #ifdef _TERRAIN_DISTANCEBLEND
  105. if(sampleDistMask)
  106. {
  107. dBlendMask[0] *= sampleDistMask;
  108. #if defined(_LAYERS_EIGHT) || defined(_LAYERS_SIXTEEN)
  109. dBlendMask[1] *= sampleDistMask;
  110. #ifdef _LAYERS_SIXTEEN
  111. dBlendMask[2] *= sampleDistMask;
  112. dBlendMask[3] *= sampleDistMask;
  113. #endif
  114. #endif
  115. }
  116. #endif
  117. }
  118. #endif
  119. #ifdef INTERRA_OBJECT
  120. objectMask.rgba = objectMask.rgba * _MaskMapRemapScale.rgba + _MaskMapRemapOffset.rgba;
  121. half height = objectMask.b;
  122. half terrainHeith = 0.5f;
  123. if (_HeightmapBlending == 1)
  124. {
  125. terrainHeith = lerp(heightSum, 1, intersection);
  126. }
  127. float2 heightIntersect = (1 / (1 * pow(2, float2(((1 - intersection) * height), (intersection * terrainHeith)) * (-(_Sharpness)))) + 1) * 0.5;
  128. heightIntersect /= (heightIntersect.r + heightIntersect.g);
  129. heightSum = (heightSum * heightIntersect.g) + (height * heightIntersect.r);
  130. if (heightIntersect.g < 1e-3f)
  131. {
  132. blendMask[0] = 0.0f;
  133. blendMask[1] = 0.0f;
  134. blendMask[2] = 0.0f;
  135. blendMask[3] = 0.0f;
  136. #if defined(_TERRAIN_DISTANCEBLEND)
  137. dBlendMask[0] = 0.0f;
  138. dBlendMask[1] = 0.0f;
  139. dBlendMask[2] = 0.0f;
  140. dBlendMask[3] = 0.0f;
  141. #endif
  142. }
  143. #endif
  144. //=======================================================================
  145. //-------------------- PUDDLES & RAINDROPS NORMALS --------------------
  146. //=======================================================================
  147. #ifndef _TERRAIN_BASEMAP_GEN
  148. float3 ripNormal = float3(0, 0, 1);
  149. float raindropSize = 1.0f / _InTerra_GlobalRaindropRipples.z * 0.1f;
  150. float2 puddlesHeight = float2(0.0f, 1.0f);
  151. float3 puddleWeight = pow(abs(worldNormal.rgb), 10.0f);
  152. puddleWeight = puddleWeight / (puddleWeight.x + puddleWeight.y + puddleWeight.z);
  153. puddlesHeight = (1 / (1 * pow(2, float2(_InTerra_GlobalPuddles.x, heightSum) * (-(100)))) + 1) * 0.5;
  154. puddlesHeight /= (puddlesHeight.r + puddlesHeight.g);
  155. float horizontalWeight = smoothstep(0.9999f, 1.0f, saturate(puddleWeight.y - ((puddleWeight.x + puddleWeight.z) * 100000000)));
  156. puddlesHeight.r *= horizontalWeight;
  157. if (_InTerra_GlobalRaindropRipples.x > 0.0f)
  158. {
  159. if (puddlesHeight.x > 0.8f && _InTerra_GlobalRaindropsDistance.y > 0.0f)
  160. {
  161. float raindropsDistance = smoothstep(_InTerra_GlobalRaindropsDistance.x, _InTerra_GlobalRaindropsDistance.y, distance(worldPos, _WorldSpaceCameraPos));
  162. float rainIndex = 1 / (min(5.0f, _InTerra_GlobalRaindropRipples.x) * 4.0f);
  163. for (float i = 5.0; i > 4.0; i -= rainIndex)
  164. {
  165. ripNormal = BlendNormal(ripNormal, RainRipples(worldPos.zx * raindropSize * i + i * 0.25f , i, i * 0.25f));
  166. }
  167. ripNormal = lerp(ripNormal, float3(0, 0, 1), raindropsDistance);
  168. }
  169. float2 uvRefractOffset = ripNormal.xy * 0.01;
  170. for (int i = 0; i < _LAYER_COUNT; ++i)
  171. {
  172. uvSplat[i] += uvRefractOffset;
  173. }
  174. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  175. ripNormal = WorldTangent(worldTangent, worldBitangent, ripNormal);
  176. #endif
  177. }
  178. #endif
  179. //========================================================================================
  180. //------------------------------- ALBEDO, SMOOTHNESS & NORMAL ---------------------------
  181. //========================================================================================
  182. #if !(defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN))
  183. float3 worldTangent;
  184. float3 worldBitangent;
  185. #endif
  186. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  187. float4 frontDiffuse;
  188. float3 frontNormal;
  189. float4 sideDiffuse;
  190. float3 sideNormal;
  191. #ifdef _TERRAIN_TRIPLANAR_ONE
  192. SampleSplat(uvSplat, blendMask, saturate(triplanarWeights.y + (1 - blendMask[0].r)), mask, mixedDiffuse, mixedNormal);
  193. SampleSplatTOL(frontDiffuse, frontNormal, uvSplat_front, blendMask, triplanarWeights.z, mask);
  194. SampleSplatTOL(sideDiffuse, sideNormal, uvSplat_side, blendMask, triplanarWeights.x, mask);
  195. #else
  196. SampleSplat(uvSplat, blendMask, triplanarWeights.y, mask, mixedDiffuse, mixedNormal);
  197. SampleSplat(uvSplat_front, blendMask, triplanarWeights.z, mask, frontDiffuse, frontNormal);
  198. SampleSplat(uvSplat_side, blendMask, triplanarWeights.x, mask, sideDiffuse, sideNormal);
  199. #endif
  200. #else
  201. SampleSplat(uvSplat, blendMask, 1.0f, mask, mixedDiffuse, mixedNormal);
  202. #endif
  203. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  204. mixedNormal = WorldTangent(worldTangent, worldBitangent, mixedNormal);
  205. #endif
  206. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  207. mixedDiffuse = mixedDiffuse + frontDiffuse + sideDiffuse;
  208. mixedNormal = TriplanarNormal(mixedNormal, worldTangent, worldBitangent, frontNormal, sideNormal, triplanarWeights, flipUV);
  209. #endif
  210. #ifdef _TERRAIN_DISTANCEBLEND
  211. float4 distantDiffuse;
  212. float3 distantNormal;
  213. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  214. float4 dFrontDiffuse;
  215. float3 dFontNormal;
  216. float4 dSideDiffuse;
  217. float3 dSideNormal;
  218. #ifdef _TERRAIN_TRIPLANAR_ONE
  219. SampleSplat(distantUV, dBlendMask, saturate(triplanarWeights.y + (1 - dBlendMask[0].r)), dMask, distantDiffuse, distantNormal);
  220. SampleSplatTOL(dFrontDiffuse, dFontNormal, distantUV_front, dBlendMask, triplanarWeights.z, dMask);
  221. SampleSplatTOL(dSideDiffuse, dSideNormal, distantUV_side, dBlendMask, triplanarWeights.x, dMask);
  222. #else
  223. SampleSplat(distantUV, dBlendMask, triplanarWeights.y, dMask, distantDiffuse, distantNormal);
  224. SampleSplat(distantUV_front, dBlendMask, triplanarWeights.z, dMask, dFrontDiffuse, dFontNormal);
  225. SampleSplat(distantUV_side, dBlendMask, triplanarWeights.x, dMask, dSideDiffuse, dSideNormal);
  226. #endif
  227. #else
  228. SampleSplat(distantUV, dBlendMask, 1.0f, dMask, distantDiffuse, distantNormal);
  229. #endif
  230. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  231. distantNormal = WorldTangent(worldTangent, worldBitangent, distantNormal);
  232. #endif
  233. #if defined(TRIPLANAR) && !defined(_TERRAIN_BASEMAP_GEN)
  234. distantDiffuse = distantDiffuse + dFrontDiffuse + dSideDiffuse;
  235. distantNormal = TriplanarNormal(distantNormal, worldTangent, worldBitangent, dFontNormal, dSideNormal, triplanarWeights, flipUV);
  236. #endif
  237. distantDiffuse = lerp(mixedDiffuse, distantDiffuse, _HT_cover);
  238. distantNormal = lerp(mixedNormal, distantNormal, _HT_cover);
  239. #ifdef _TERRAIN_BASEMAP_GEN
  240. mixedDiffuse = distantDiffuse;
  241. #else
  242. mixedDiffuse = lerp(mixedDiffuse, distantDiffuse, dist);
  243. mixedNormal = lerp(mixedNormal, distantNormal, dist);
  244. #endif
  245. #endif
  246. float3 tint = SAMPLE_TEXTURE2D(_TerrainColorTintTexture, SamplerState_Linear_Repeat, tintUV).rgb;
  247. #if !defined(TRIPLANAR_TINT)
  248. mixedDiffuse.rgb = lerp(mixedDiffuse.rgb, (mixedDiffuse.rgb * tint), _TerrainColorTintStrenght).rgb;
  249. #endif
  250. float normalDist = smoothstep(_TerrainNormalTintDistance.x, _TerrainNormalTintDistance.y, (distance(worldPos, _WorldSpaceCameraPos)));
  251. float3 normalTint = UnpackNormals(SAMPLE_TEXTURE2D(_TerrainNormalTintTexture, sampler_Splat0, normalTintUV), 1);
  252. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  253. normalTint = WorldTangent(worldTangent, worldBitangent, normalTint);
  254. #endif
  255. mixedNormal = lerp(mixedNormal, BlendNormals(mixedNormal, normalTint), _TerrainNormalTintStrenght * normalDist).rgb;
  256. //========================================================================================
  257. //--------------------------------------- TRACKS --------------------------------------
  258. //========================================================================================
  259. #if defined(_TRACKS) && !defined(_TERRAIN_BASEMAP_GEN)
  260. if (_Tracks == 1)
  261. {
  262. UnpackTrackSplatValues(trackSplats);
  263. UnpackTrackSplatColor(trackSplatsColor);
  264. float4 trackColor = TrackSplatValues(tBlendMask, trackSplatsColor);
  265. float4 trackValues = TrackSplatValues(tBlendMask, trackSplats);
  266. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  267. float2 terrainSize = _TerrainSize.xz;
  268. #else
  269. float2 terrainSize = _TerrainSizeXZPosY.xy;
  270. #endif
  271. float2 trackDetailUV = (float2(splatBaseUV.x, -splatBaseUV.y) * _TrackDetailTexture_ST.xy * terrainSize + _TrackDetailTexture_ST.zw);
  272. #if defined(PARALLAX) && defined(_TERRAIN_PARALLAX)
  273. if (_Terrain_Parallax == 1)
  274. {
  275. float2 trackParallaxOffset = ParallaxOffset(_InTerra_TrackTexture, SamplerState_Linear_Repeat, _ParallaxTrackSteps, -trackValues.y, trackUV, float3( -tangentViewDirTerrain.x, tangentViewDirTerrain.y, -tangentViewDirTerrain.z), _ParallaxTrackAffineSteps, _MipMapLevel + (lod * (log2(max(_InTerra_TrackTexture_TexelSize.z, _InTerra_TrackTexture_TexelSize.w)) + 1)), 1 );
  276. trackUV += trackParallaxOffset;
  277. trackDetailUV += (trackParallaxOffset ) * (_TrackDetailTexture_ST.xy * _InTerra_TrackArea);
  278. }
  279. #endif
  280. float4 trackDetail = SAMPLE_TEXTURE2D(_TrackDetailTexture, SamplerState_Linear_Repeat, trackDetailUV);
  281. trackDepth = SAMPLE_TEXTURE2D_LOD(_InTerra_TrackTexture, SamplerState_Linear_Repeat, trackUV, 0);
  282. float normalsOffset = _InTerra_TrackTexture_TexelSize.x;
  283. float texelArea = _InTerra_TrackTexture_TexelSize.x * 100 * _InTerra_TrackArea;
  284. float normalStrenghts = _TrackNormalStrenght / texelArea;
  285. float normalEdgeStrenghts = _TrackEdgeNormals / texelArea;
  286. float4 heights[4];
  287. heights[0] = (SAMPLE_TEXTURE2D_LOD(_InTerra_TrackTexture, SamplerState_Linear_Repeat, trackUV + float2(0.0f, normalsOffset), 0.0f));
  288. heights[1] = (SAMPLE_TEXTURE2D_LOD(_InTerra_TrackTexture, SamplerState_Linear_Repeat, trackUV + float2(normalsOffset, 0.0f), 0.0f));
  289. heights[2] = (SAMPLE_TEXTURE2D_LOD(_InTerra_TrackTexture, SamplerState_Linear_Repeat, trackUV + float2(-normalsOffset, 0.0f), 0.0f));
  290. heights[3] = (SAMPLE_TEXTURE2D_LOD(_InTerra_TrackTexture, SamplerState_Linear_Repeat, trackUV + float2(0.0f, -normalsOffset), 0.0f));
  291. for (int i = 0; i < 4; ++i)
  292. {
  293. heights[i] *= float4(1.0f, 1.0f, normalStrenghts * 2, normalEdgeStrenghts * 2);
  294. }
  295. float3 edgeNormals = (float3(float2(heights[2].a - heights[1].a, heights[0].a - heights[3].a), 1.0f));
  296. float3 trackNormal = float3(float2(heights[2].b - heights[1].b, heights[0].b - heights[3].b), 1.0f);
  297. float4 trackDetailNormal = SAMPLE_TEXTURE2D(_TrackDetailNormalTexture, SamplerState_Linear_Repeat, trackDetailUV);
  298. trackDetailNormal.xyz = UnpackNormalScale(float4(trackDetailNormal.x, trackDetailNormal.y, 0, 1-trackDetailNormal.w), _TrackDetailNormalStrenght);
  299. trackDetailNormal.z += 1e-5f;
  300. float heightSum = HeightSum(mask, blendMask);
  301. float trackHeightMap = saturate(trackDepth.b + _TrackHeightOffset);
  302. float2 trackIntersect = float2(trackDepth.b, 1 - trackDepth.b);
  303. trackIntersect *= (1 / (pow(2, float2(trackHeightMap, heightSum) * (-(_TrackHeightTransition)))) + 1) * 0.5;
  304. trackIntersect /= (trackIntersect.r + trackIntersect.g);
  305. trackNormal = (lerp(trackNormal, normalize(lerp(trackDetailNormal.xyz, trackNormal, 0.5f)), trackValues.a)) * trackIntersect.r;
  306. float trackEdge = saturate(pow(abs(trackDepth.a), _TrackEdgeSharpness));
  307. float track = trackIntersect.r * trackDist;
  308. float colorOpacity = saturate(track * trackColor.a);
  309. float normalOpacity = saturate(trackValues.z * (trackEdge + track)) * trackDist;
  310. #if defined(_NORMALMAPS)
  311. trackNormal = normalize(lerp(edgeNormals, trackNormal, trackDepth.b));
  312. trackNormal.z += 1e-5f;
  313. trackColor = lerp(trackColor, (trackColor * trackDetail), trackValues.a);
  314. #if defined(INTERRA_OBJECT) || defined(INTERRA_MESH_TERRAIN)
  315. trackNormal.xy *= -1;
  316. edgeNormals.xy *= -1;
  317. trackNormal = WorldTangent(worldTangent, worldBitangent, trackNormal);
  318. #endif
  319. mixedNormal = lerp(mixedNormal, trackNormal, normalOpacity);
  320. mixedNormal.z += +1e-5f;
  321. #endif
  322. mixedDiffuse.rgb = lerp(mixedDiffuse.rgb, trackColor.rgb, colorOpacity);
  323. mixedDiffuse.a = lerp(mixedDiffuse.a, trackValues.x, track);
  324. occlusion = lerp(occlusion, _TrackAO, track);
  325. }
  326. #endif
  327. mixedDiffuse.a = lerp(mixedDiffuse.a, 1.0f, _InTerra_GlobalWetness);
  328. mixedNormal.xy = _InTerra_GlobalWetness > 0.4 ? mixedNormal.xy * (1 - min(0.7f, (_InTerra_GlobalWetness * 2.25f - 1))) : mixedNormal.xy;
  329. mixedNormal.z += +1e-5f;
  330. mixedDiffuse = mixedDiffuse + SAMPLE_TEXTURE2D_LOD(_Splat0, sampler_Splat0, float2(0,0), 10) * 0.000001f;
  331. #ifdef INTERRA_MESH_TERRAIN
  332. if (_CheckHeight)
  333. {
  334. mixedDiffuse.rgb *= float3(1.0f, 0.80f, 0.60f);
  335. }
  336. #endif
  337. //=======================================================================================
  338. //==============================| OBJECT INTEGRATION |===============================
  339. //=======================================================================================
  340. #ifdef INTERRA_OBJECT
  341. objectAlbedo.a = _HasMask == 1 ? objectMask.a : _Smoothness;
  342. objectAlbedo.a = _GlobalWetnessDisabled ? objectAlbedo.a : lerp(objectAlbedo.a, 1.0f, _InTerra_GlobalWetness);
  343. float objectMetallic = _HasMask == 1 ? objectMask.r : _Metallic;
  344. float objectAo = _HasMask == 1 ? objectMask.g : _Ao;
  345. float3 dt = float3(0, 0, 0);
  346. UNITY_BRANCH if (_Detail > 0)
  347. {
  348. UNITY_BRANCH if (_HasDetailAlbedo > 0)
  349. {
  350. float3 dt = SAMPLE_TEXTURE2D(_DetailMap, sampler_DetailMap, detailUV).rgb;
  351. objectAlbedo.rgb = lerp(objectAlbedo.rgb, half(2.0) * dt, _DetailStrenght).rgb;
  352. }
  353. float3 objectNormalD = UnpackNormalScale(SAMPLE_TEXTURE2D(_DetailNormalMap, sampler_DetailNormalMap, detailUV), _DetailNormalMapScale);
  354. objectNormal = (lerp(objectNormal, BlendNormalRNM(objectNormal, objectNormalD), _DetailStrenght));
  355. }
  356. mixedDiffuse = lerp(mixedDiffuse, objectAlbedo, heightIntersect.r);
  357. float3 terrainNormal = (mixedNormal.z * terrainNormals.xyz) + 1e-5f;
  358. terrainNormal.xy = mixedNormal.xy + terrainNormal.xy;
  359. mixedNormal = lerp(mixedNormal, terrainNormal, intersectNormal);
  360. mixedNormal = lerp(mixedNormal, objectNormal, heightIntersect.r);
  361. metallic = lerp(metallic, objectMetallic, heightIntersect.r);
  362. occlusion = lerp(occlusion, objectAo, heightIntersect.r);
  363. albedo = mixedDiffuse.rgb;
  364. emission = 0;
  365. UNITY_BRANCH if (_EmissionEnabled > 0)
  366. {
  367. emission = lerp(0, objectEmission, heightIntersect.r);
  368. }
  369. #else
  370. mixedAlbedo = mixedDiffuse.rgb;
  371. #endif
  372. //===============| PUDDLES & RAINDROPS FINAL MIX |======================
  373. #ifndef _TERRAIN_BASEMAP_GEN
  374. if (_InTerra_GlobalPuddles.y > 0.0f)
  375. {
  376. float wettnessAround = smoothstep(_InTerra_GlobalPuddles.y, _InTerra_GlobalPuddles.x, heightSum) * horizontalWeight;
  377. mixedNormal.xy = wettnessAround > 0.4 ? mixedNormal.xy * (1 - min(0.9f, (wettnessAround * 2.25f - 1))) : mixedNormal.xy;
  378. mixedDiffuse.a = lerp(mixedDiffuse.a, 1.0f, wettnessAround);
  379. mixedDiffuse.a = lerp(mixedDiffuse.a, 1.0f, puddlesHeight.r * horizontalWeight);
  380. mixedNormal = lerp(mixedNormal, ripNormal, puddlesHeight.r * horizontalWeight);
  381. occlusion = lerp(occlusion, lerp(occlusion, 0.9f, 0.75f) , puddlesHeight.r * horizontalWeight);
  382. }
  383. #endif
  384. smoothness = mixedDiffuse.a;
  385. mixedNormal.z += +1e-5f;
  386. //=========================================================================================
  387. }