TerrainLitPasses.hlsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. #ifndef UNIVERSAL_TERRAIN_LIT_PASSES_INCLUDED
  2. #define UNIVERSAL_TERRAIN_LIT_PASSES_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #if defined(UNITY_INSTANCING_ENABLED) && defined(_TERRAIN_INSTANCED_PERPIXEL_NORMAL)
  5. #define ENABLE_TERRAIN_PERPIXEL_NORMAL
  6. #endif
  7. #ifdef UNITY_INSTANCING_ENABLED
  8. TEXTURE2D(_TerrainHeightmapTexture);
  9. TEXTURE2D(_TerrainNormalmapTexture);
  10. SAMPLER(sampler_TerrainNormalmapTexture);
  11. #endif
  12. UNITY_INSTANCING_BUFFER_START(Terrain)
  13. UNITY_DEFINE_INSTANCED_PROP(float4, _TerrainPatchInstanceData) // float4(xBase, yBase, skipScale, ~)
  14. UNITY_INSTANCING_BUFFER_END(Terrain)
  15. #ifdef _ALPHATEST_ON
  16. TEXTURE2D(_TerrainHolesTexture);
  17. SAMPLER(sampler_TerrainHolesTexture);
  18. void ClipHoles(float2 uv)
  19. {
  20. float hole = SAMPLE_TEXTURE2D(_TerrainHolesTexture, sampler_TerrainHolesTexture, uv).r;
  21. clip(hole == 0.0f ? -1 : 1);
  22. }
  23. #endif
  24. struct Attributes
  25. {
  26. float4 positionOS : POSITION;
  27. float3 normalOS : NORMAL;
  28. float2 texcoord : TEXCOORD0;
  29. UNITY_VERTEX_INPUT_INSTANCE_ID
  30. };
  31. struct Varyings
  32. {
  33. float4 uvMainAndLM : TEXCOORD0; // xy: control, zw: lightmap
  34. #ifndef TERRAIN_SPLAT_BASEPASS
  35. float4 uvSplat01 : TEXCOORD1; // xy: splat0, zw: splat1
  36. float4 uvSplat23 : TEXCOORD2; // xy: splat2, zw: splat3
  37. #endif
  38. #if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  39. float4 normal : TEXCOORD3; // xyz: normal, w: viewDir.x
  40. float4 tangent : TEXCOORD4; // xyz: tangent, w: viewDir.y
  41. float4 bitangent : TEXCOORD5; // xyz: bitangent, w: viewDir.z
  42. #else
  43. float3 normal : TEXCOORD3;
  44. float3 viewDir : TEXCOORD4;
  45. half3 vertexSH : TEXCOORD5; // SH
  46. #endif
  47. half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
  48. float3 positionWS : TEXCOORD7;
  49. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  50. float4 shadowCoord : TEXCOORD8;
  51. #endif
  52. float4 clipPos : SV_POSITION;
  53. UNITY_VERTEX_OUTPUT_STEREO
  54. };
  55. void InitializeInputData(Varyings IN, half3 normalTS, out InputData input)
  56. {
  57. input = (InputData)0;
  58. input.positionWS = IN.positionWS;
  59. half3 SH = half3(0, 0, 0);
  60. #if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  61. half3 viewDirWS = half3(IN.normal.w, IN.tangent.w, IN.bitangent.w);
  62. input.normalWS = TransformTangentToWorld(normalTS, half3x3(-IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz));
  63. SH = SampleSH(input.normalWS.xyz);
  64. #elif defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  65. half3 viewDirWS = IN.viewDir;
  66. float2 sampleCoords = (IN.uvMainAndLM.xy / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
  67. half3 normalWS = TransformObjectToWorldNormal(normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, sampler_TerrainNormalmapTexture, sampleCoords).rgb * 2 - 1));
  68. half3 tangentWS = cross(GetObjectToWorldMatrix()._13_23_33, normalWS);
  69. input.normalWS = TransformTangentToWorld(normalTS, half3x3(-tangentWS, cross(normalWS, tangentWS), normalWS));
  70. SH = SampleSH(input.normalWS.xyz);
  71. #else
  72. half3 viewDirWS = IN.viewDir;
  73. input.normalWS = IN.normal;
  74. SH = IN.vertexSH;
  75. #endif
  76. #if SHADER_HINT_NICE_QUALITY
  77. viewDirWS = SafeNormalize(viewDirWS);
  78. #endif
  79. input.normalWS = NormalizeNormalPerPixel(input.normalWS);
  80. input.viewDirectionWS = viewDirWS;
  81. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  82. input.shadowCoord = input.shadowCoord;
  83. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  84. input.shadowCoord = TransformWorldToShadowCoord(input.positionWS);
  85. #else
  86. input.shadowCoord = float4(0, 0, 0, 0);
  87. #endif
  88. input.fogCoord = IN.fogFactorAndVertexLight.x;
  89. input.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  90. input.bakedGI = SAMPLE_GI(IN.uvMainAndLM.zw, SH, input.normalWS);
  91. }
  92. #ifndef TERRAIN_SPLAT_BASEPASS
  93. void SplatmapMix(float4 uvMainAndLM, float4 uvSplat01, float4 uvSplat23, inout half4 splatControl, out half weight, out half4 mixedDiffuse, out half4 defaultSmoothness, inout half3 mixedNormal)
  94. {
  95. half4 diffAlbedo[4];
  96. diffAlbedo[0] = SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, uvSplat01.xy);
  97. diffAlbedo[1] = SAMPLE_TEXTURE2D(_Splat1, sampler_Splat0, uvSplat01.zw);
  98. diffAlbedo[2] = SAMPLE_TEXTURE2D(_Splat2, sampler_Splat0, uvSplat23.xy);
  99. diffAlbedo[3] = SAMPLE_TEXTURE2D(_Splat3, sampler_Splat0, uvSplat23.zw);
  100. // This might be a bit of a gamble -- the assumption here is that if the diffuseMap has no
  101. // alpha channel, then diffAlbedo[n].a = 1.0 (and _DiffuseHasAlphaN = 0.0)
  102. // Prior to coming in, _SmoothnessN is actually set to max(_DiffuseHasAlphaN, _SmoothnessN)
  103. // This means that if we have an alpha channel, _SmoothnessN is locked to 1.0 and
  104. // otherwise, the true slider value is passed down and diffAlbedo[n].a == 1.0.
  105. defaultSmoothness = half4(diffAlbedo[0].a, diffAlbedo[1].a, diffAlbedo[2].a, diffAlbedo[3].a);
  106. defaultSmoothness *= half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
  107. #ifndef _TERRAIN_BLEND_HEIGHT
  108. // 20.0 is the number of steps in inputAlphaMask (Density mask. We decided 20 empirically)
  109. half4 opacityAsDensity = saturate((half4(diffAlbedo[0].a, diffAlbedo[1].a, diffAlbedo[2].a, diffAlbedo[3].a) - (half4(1.0, 1.0, 1.0, 1.0) - splatControl)) * 20.0);
  110. opacityAsDensity += 0.001h * splatControl; // if all weights are zero, default to what the blend mask says
  111. half4 useOpacityAsDensityParam = { _DiffuseRemapScale0.w, _DiffuseRemapScale1.w, _DiffuseRemapScale2.w, _DiffuseRemapScale3.w }; // 1 is off
  112. splatControl = lerp(opacityAsDensity, splatControl, useOpacityAsDensityParam);
  113. #endif
  114. // Now that splatControl has changed, we can compute the final weight and normalize
  115. weight = dot(splatControl, 1.0h);
  116. #ifdef TERRAIN_SPLAT_ADDPASS
  117. clip(weight <= 0.005h ? -1.0h : 1.0h);
  118. #endif
  119. #ifndef _TERRAIN_BASEMAP_GEN
  120. // Normalize weights before lighting and restore weights in final modifier functions so that the overal
  121. // lighting result can be correctly weighted.
  122. splatControl /= (weight + HALF_MIN);
  123. #endif
  124. mixedDiffuse = 0.0h;
  125. mixedDiffuse += diffAlbedo[0] * half4(_DiffuseRemapScale0.rgb * splatControl.rrr, 1.0h);
  126. mixedDiffuse += diffAlbedo[1] * half4(_DiffuseRemapScale1.rgb * splatControl.ggg, 1.0h);
  127. mixedDiffuse += diffAlbedo[2] * half4(_DiffuseRemapScale2.rgb * splatControl.bbb, 1.0h);
  128. mixedDiffuse += diffAlbedo[3] * half4(_DiffuseRemapScale3.rgb * splatControl.aaa, 1.0h);
  129. #ifdef _NORMALMAP
  130. half3 nrm = 0.0f;
  131. nrm += splatControl.r * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal0, sampler_Normal0, uvSplat01.xy), _NormalScale0);
  132. nrm += splatControl.g * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal1, sampler_Normal0, uvSplat01.zw), _NormalScale1);
  133. nrm += splatControl.b * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal2, sampler_Normal0, uvSplat23.xy), _NormalScale2);
  134. nrm += splatControl.a * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal3, sampler_Normal0, uvSplat23.zw), _NormalScale3);
  135. // avoid risk of NaN when normalizing.
  136. #if HAS_HALF
  137. nrm.z += 0.01h;
  138. #else
  139. nrm.z += 1e-5f;
  140. #endif
  141. mixedNormal = normalize(nrm.xyz);
  142. #endif
  143. }
  144. #endif
  145. #ifdef _TERRAIN_BLEND_HEIGHT
  146. void HeightBasedSplatModify(inout half4 splatControl, in half4 masks[4])
  147. {
  148. // heights are in mask blue channel, we multiply by the splat Control weights to get combined height
  149. half4 splatHeight = half4(masks[0].b, masks[1].b, masks[2].b, masks[3].b) * splatControl.rgba;
  150. half maxHeight = max(splatHeight.r, max(splatHeight.g, max(splatHeight.b, splatHeight.a)));
  151. // Ensure that the transition height is not zero.
  152. half transition = max(_HeightTransition, 1e-5);
  153. // This sets the highest splat to "transition", and everything else to a lower value relative to that, clamping to zero
  154. // Then we clamp this to zero and normalize everything
  155. half4 weightedHeights = splatHeight + transition - maxHeight.xxxx;
  156. weightedHeights = max(0, weightedHeights);
  157. // We need to add an epsilon here for active layers (hence the blendMask again)
  158. // so that at least a layer shows up if everything's too low.
  159. weightedHeights = (weightedHeights + 1e-6) * splatControl;
  160. // Normalize (and clamp to epsilon to keep from dividing by zero)
  161. half sumHeight = max(dot(weightedHeights, half4(1, 1, 1, 1)), 1e-6);
  162. splatControl = weightedHeights / sumHeight.xxxx;
  163. }
  164. #endif
  165. void SplatmapFinalColor(inout half4 color, half fogCoord)
  166. {
  167. color.rgb *= color.a;
  168. #ifdef TERRAIN_SPLAT_ADDPASS
  169. color.rgb = MixFogColor(color.rgb, half3(0,0,0), fogCoord);
  170. #else
  171. color.rgb = MixFog(color.rgb, fogCoord);
  172. #endif
  173. }
  174. void TerrainInstancing(inout float4 positionOS, inout float3 normal, inout float2 uv)
  175. {
  176. #ifdef UNITY_INSTANCING_ENABLED
  177. float2 patchVertex = positionOS.xy;
  178. float4 instanceData = UNITY_ACCESS_INSTANCED_PROP(Terrain, _TerrainPatchInstanceData);
  179. float2 sampleCoords = (patchVertex.xy + instanceData.xy) * instanceData.z; // (xy + float2(xBase,yBase)) * skipScale
  180. float height = UnpackHeightmap(_TerrainHeightmapTexture.Load(int3(sampleCoords, 0)));
  181. positionOS.xz = sampleCoords * _TerrainHeightmapScale.xz;
  182. positionOS.y = height * _TerrainHeightmapScale.y;
  183. #ifdef ENABLE_TERRAIN_PERPIXEL_NORMAL
  184. normal = float3(0, 1, 0);
  185. #else
  186. normal = _TerrainNormalmapTexture.Load(int3(sampleCoords, 0)).rgb * 2 - 1;
  187. #endif
  188. uv = sampleCoords * _TerrainHeightmapRecipSize.zw;
  189. #endif
  190. }
  191. void TerrainInstancing(inout float4 positionOS, inout float3 normal)
  192. {
  193. float2 uv = { 0, 0 };
  194. TerrainInstancing(positionOS, normal, uv);
  195. }
  196. ///////////////////////////////////////////////////////////////////////////////
  197. // Vertex and Fragment functions //
  198. ///////////////////////////////////////////////////////////////////////////////
  199. // Used in Standard Terrain shader
  200. Varyings SplatmapVert(Attributes v)
  201. {
  202. Varyings o = (Varyings)0;
  203. UNITY_SETUP_INSTANCE_ID(v);
  204. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  205. TerrainInstancing(v.positionOS, v.normalOS, v.texcoord);
  206. VertexPositionInputs Attributes = GetVertexPositionInputs(v.positionOS.xyz);
  207. o.uvMainAndLM.xy = v.texcoord;
  208. o.uvMainAndLM.zw = v.texcoord * unity_LightmapST.xy + unity_LightmapST.zw;
  209. #ifndef TERRAIN_SPLAT_BASEPASS
  210. o.uvSplat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  211. o.uvSplat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  212. o.uvSplat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
  213. o.uvSplat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
  214. #endif
  215. half3 viewDirWS = GetCameraPositionWS() - Attributes.positionWS;
  216. #if !SHADER_HINT_NICE_QUALITY
  217. viewDirWS = SafeNormalize(viewDirWS);
  218. #endif
  219. #if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  220. float4 vertexTangent = float4(cross(float3(0, 0, 1), v.normalOS), 1.0);
  221. VertexNormalInputs normalInput = GetVertexNormalInputs(v.normalOS, vertexTangent);
  222. o.normal = half4(normalInput.normalWS, viewDirWS.x);
  223. o.tangent = half4(normalInput.tangentWS, viewDirWS.y);
  224. o.bitangent = half4(normalInput.bitangentWS, viewDirWS.z);
  225. #else
  226. o.normal = TransformObjectToWorldNormal(v.normalOS);
  227. o.viewDir = viewDirWS;
  228. o.vertexSH = SampleSH(o.normal);
  229. #endif
  230. o.fogFactorAndVertexLight.x = ComputeFogFactor(Attributes.positionCS.z);
  231. o.fogFactorAndVertexLight.yzw = VertexLighting(Attributes.positionWS, o.normal.xyz);
  232. o.positionWS = Attributes.positionWS;
  233. o.clipPos = Attributes.positionCS;
  234. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  235. o.shadowCoord = GetShadowCoord(Attributes);
  236. #endif
  237. return o;
  238. }
  239. void ComputeMasks(out half4 masks[4], half4 hasMask, Varyings IN)
  240. {
  241. masks[0] = 0.5h;
  242. masks[1] = 0.5h;
  243. masks[2] = 0.5h;
  244. masks[3] = 0.5h;
  245. #ifdef _MASKMAP
  246. masks[0] = lerp(masks[0], SAMPLE_TEXTURE2D(_Mask0, sampler_Mask0, IN.uvSplat01.xy), hasMask.x);
  247. masks[1] = lerp(masks[1], SAMPLE_TEXTURE2D(_Mask1, sampler_Mask0, IN.uvSplat01.zw), hasMask.y);
  248. masks[2] = lerp(masks[2], SAMPLE_TEXTURE2D(_Mask2, sampler_Mask0, IN.uvSplat23.xy), hasMask.z);
  249. masks[3] = lerp(masks[3], SAMPLE_TEXTURE2D(_Mask3, sampler_Mask0, IN.uvSplat23.zw), hasMask.w);
  250. #endif
  251. masks[0] *= _MaskMapRemapScale0.rgba;
  252. masks[0] += _MaskMapRemapOffset0.rgba;
  253. masks[1] *= _MaskMapRemapScale1.rgba;
  254. masks[1] += _MaskMapRemapOffset1.rgba;
  255. masks[2] *= _MaskMapRemapScale2.rgba;
  256. masks[2] += _MaskMapRemapOffset2.rgba;
  257. masks[3] *= _MaskMapRemapScale3.rgba;
  258. masks[3] += _MaskMapRemapOffset3.rgba;
  259. }
  260. // Used in Standard Terrain shader
  261. half4 SplatmapFragment(Varyings IN) : SV_TARGET
  262. {
  263. #ifdef _ALPHATEST_ON
  264. ClipHoles(IN.uvMainAndLM.xy);
  265. #endif
  266. half3 normalTS = half3(0.0h, 0.0h, 1.0h);
  267. #ifdef TERRAIN_SPLAT_BASEPASS
  268. half3 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).rgb;
  269. half smoothness = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).a;
  270. half metallic = SAMPLE_TEXTURE2D(_MetallicTex, sampler_MetallicTex, IN.uvMainAndLM.xy).r;
  271. half alpha = 1;
  272. half occlusion = 1;
  273. #else
  274. half4 hasMask = half4(_LayerHasMask0, _LayerHasMask1, _LayerHasMask2, _LayerHasMask3);
  275. half4 masks[4];
  276. ComputeMasks(masks, hasMask, IN);
  277. float2 splatUV = (IN.uvMainAndLM.xy * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy;
  278. half4 splatControl = SAMPLE_TEXTURE2D(_Control, sampler_Control, splatUV);
  279. #ifdef _TERRAIN_BLEND_HEIGHT
  280. // disable Height Based blend when there are more than 4 layers (multi-pass breaks the normalization)
  281. if (_NumLayersCount <= 4)
  282. HeightBasedSplatModify(splatControl, masks);
  283. #endif
  284. half weight;
  285. half4 mixedDiffuse;
  286. half4 defaultSmoothness;
  287. SplatmapMix(IN.uvMainAndLM, IN.uvSplat01, IN.uvSplat23, splatControl, weight, mixedDiffuse, defaultSmoothness, normalTS);
  288. half3 albedo = mixedDiffuse.rgb;
  289. half4 defaultMetallic = half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3);
  290. half4 defaultOcclusion = half4(_MaskMapRemapScale0.g, _MaskMapRemapScale1.g, _MaskMapRemapScale2.g, _MaskMapRemapScale3.g) +
  291. half4(_MaskMapRemapOffset0.g, _MaskMapRemapOffset1.g, _MaskMapRemapOffset2.g, _MaskMapRemapOffset3.g);
  292. half4 maskSmoothness = half4(masks[0].a, masks[1].a, masks[2].a, masks[3].a);
  293. defaultSmoothness = lerp(defaultSmoothness, maskSmoothness, hasMask);
  294. half smoothness = dot(splatControl, defaultSmoothness);
  295. half4 maskMetallic = half4(masks[0].r, masks[1].r, masks[2].r, masks[3].r);
  296. defaultMetallic = lerp(defaultMetallic, maskMetallic, hasMask);
  297. half metallic = dot(splatControl, defaultMetallic);
  298. half4 maskOcclusion = half4(masks[0].g, masks[1].g, masks[2].g, masks[3].g);
  299. defaultOcclusion = lerp(defaultOcclusion, maskOcclusion, hasMask);
  300. half occlusion = dot(splatControl, defaultOcclusion);
  301. half alpha = weight;
  302. #endif
  303. InputData inputData;
  304. InitializeInputData(IN, normalTS, inputData);
  305. half4 color = UniversalFragmentPBR(inputData, albedo, metallic, /* specular */ half3(0.0h, 0.0h, 0.0h), smoothness, occlusion, /* emission */ half3(0, 0, 0), alpha);
  306. SplatmapFinalColor(color, inputData.fogCoord);
  307. return half4(color.rgb, 1.0h);
  308. }
  309. // Shadow pass
  310. // x: global clip space bias, y: normal world space bias
  311. float3 _LightDirection;
  312. struct AttributesLean
  313. {
  314. float4 position : POSITION;
  315. float3 normalOS : NORMAL;
  316. #ifdef _ALPHATEST_ON
  317. float2 texcoord : TEXCOORD0;
  318. #endif
  319. UNITY_VERTEX_INPUT_INSTANCE_ID
  320. };
  321. struct VaryingsLean
  322. {
  323. float4 clipPos : SV_POSITION;
  324. #ifdef _ALPHATEST_ON
  325. float2 texcoord : TEXCOORD0;
  326. #endif
  327. UNITY_VERTEX_OUTPUT_STEREO
  328. };
  329. VaryingsLean ShadowPassVertex(AttributesLean v)
  330. {
  331. VaryingsLean o = (VaryingsLean)0;
  332. UNITY_SETUP_INSTANCE_ID(v);
  333. TerrainInstancing(v.position, v.normalOS);
  334. float3 positionWS = TransformObjectToWorld(v.position.xyz);
  335. float3 normalWS = TransformObjectToWorldNormal(v.normalOS);
  336. float4 clipPos = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  337. #if UNITY_REVERSED_Z
  338. clipPos.z = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
  339. #else
  340. clipPos.z = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
  341. #endif
  342. o.clipPos = clipPos;
  343. #ifdef _ALPHATEST_ON
  344. o.texcoord = v.texcoord;
  345. #endif
  346. return o;
  347. }
  348. half4 ShadowPassFragment(VaryingsLean IN) : SV_TARGET
  349. {
  350. #ifdef _ALPHATEST_ON
  351. ClipHoles(IN.texcoord);
  352. #endif
  353. return 0;
  354. }
  355. // Depth pass
  356. VaryingsLean DepthOnlyVertex(AttributesLean v)
  357. {
  358. VaryingsLean o = (VaryingsLean)0;
  359. UNITY_SETUP_INSTANCE_ID(v);
  360. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  361. TerrainInstancing(v.position, v.normalOS);
  362. o.clipPos = TransformObjectToHClip(v.position.xyz);
  363. #ifdef _ALPHATEST_ON
  364. o.texcoord = v.texcoord;
  365. #endif
  366. return o;
  367. }
  368. half4 DepthOnlyFragment(VaryingsLean IN) : SV_TARGET
  369. {
  370. #ifdef _ALPHATEST_ON
  371. ClipHoles(IN.texcoord);
  372. #endif
  373. #ifdef SCENESELECTIONPASS
  374. // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly
  375. return half4(_ObjectId, _PassValue, 1.0, 1.0);
  376. #endif
  377. return 0;
  378. }
  379. #endif