InTerra_DiffuseBase.shader 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Shader "Hidden/InTerra/InTerra-Diffuse-Base" {
  2. Properties{
  3. _MainTex("Base (RGB) Smoothness (A)", 2D) = "white" {}
  4. _TriplanarTex("splat0", 2D) = "white" {}
  5. // used in fallback on old cards
  6. _Color("Main Color", Color) = (1,1,1,1)
  7. [HideInInspector] _TerrainHolesTexture("Holes Map (RGB)", 2D) = "white" {}
  8. [HideInInspector] _TerrainSizeXZPosY("", Vector) = (0,0,0)
  9. [HideInInspector] _TriplanarOneToAllSteep("", Float) = 0
  10. [HideInInspector] _TriplanarSharpness("Triplanar Sharpness", Range(3,10)) = 8
  11. _HT_distance_scale("Scale", Range(0,0.5)) = 0.25
  12. }
  13. SubShader{
  14. Tags {
  15. "RenderType" = "Opaque"
  16. "Queue" = "Geometry-100"
  17. }
  18. LOD 200
  19. CGPROGRAM
  20. #pragma surface surf Lambert vertex:SplatmapVert addshadow fullforwardshadows
  21. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd
  22. #pragma target 3.0
  23. #define _ALPHATEST_ON
  24. #pragma shader_feature_local _TERRAIN_TRIPLANAR_ONE
  25. #pragma shader_feature_local _TERRAIN_DISTANCEBLEND
  26. #define DIFFUSE
  27. #define INTERRA_TERRAIN
  28. #define TERRAIN_BASE_PASS
  29. #define TERRAIN_INSTANCED_PERPIXEL_NORMAL
  30. #include "InTerra_DefinedGlobalKeywords.cginc"
  31. #include "InTerra_InputsAndFunctions.cginc"
  32. #include "InTerra_Mixing.cginc"
  33. #include "UnityPBSLighting.cginc"
  34. sampler2D _MainTex;
  35. sampler2D _TriplanarTex;
  36. void surf(Input IN, inout SurfaceOutput o) {
  37. #ifdef _ALPHATEST_ON
  38. ClipHoles(IN.tc.xy);
  39. #endif
  40. half4 albedo = tex2D(_MainTex, IN.tc.xy);
  41. #ifdef _TERRAIN_TRIPLANAR_ONE
  42. float3 weights;
  43. float3 flipUV = float3(1, 1, -1);
  44. #if defined(UNITY_INSTANCING_ENABLED) && !defined(SHADER_API_D3D11_9X)
  45. weights = abs(IN.terrainNormals);
  46. #else
  47. weights = abs(IN.worldNormal);
  48. #endif
  49. weights = pow(weights, _TriplanarSharpness);
  50. weights = weights / (weights.x + weights.y + weights.z);
  51. float2 frontUV = TerrainFrontUV(IN.worldPos, _MainTex_ST, IN.tc.xy, flipUV);
  52. float2 sideUV = TerrainSideUV(IN.worldPos, _MainTex_ST, IN.tc.xy, flipUV);
  53. half4 cFront = tex2D(_TriplanarTex, frontUV);
  54. half4 cSide = tex2D(_TriplanarTex, sideUV);
  55. TriplanarBase(albedo, cFront, cSide, weights, albedo.a, _TriplanarOneToAllSteep);
  56. #ifdef _TERRAIN_TINT_TEXTURE
  57. half4 tint = tex2D(_TerrainColorTintTexture, IN.tc.xy * _TerrainColorTintTexture_ST.xy + _TerrainColorTintTexture_ST.zw);
  58. albedo.rgb = lerp(albedo.rgb, ((albedo.rgb) * (tint)), _TerrainColorTintStrenght).rgb;
  59. #endif
  60. #endif
  61. o.Albedo = albedo.rgb;
  62. o.Alpha = 1;
  63. #if defined(INSTANCING_ON) && defined(SHADER_TARGET_SURFACE_ANALYSIS) && defined(TERRAIN_INSTANCED_PERPIXEL_NORMAL)
  64. o.Normal = float3(0, 0, 1); // make sure that surface shader compiler realizes we write to normal, as UNITY_INSTANCING_ENABLED is not defined for SHADER_TARGET_SURFACE_ANALYSIS.
  65. #endif
  66. #if defined(UNITY_INSTANCING_ENABLED) && !defined(SHADER_API_D3D11_9X) && defined(TERRAIN_INSTANCED_PERPIXEL_NORMAL)
  67. o.Normal = normalize(tex2D(_TerrainNormalmapTexture, IN.tc.zw).xyz * 2 - 1).xzy;
  68. #endif
  69. }
  70. ENDCG
  71. UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
  72. UsePass "Hidden/Nature/Terrain/Utilities/SELECTION"
  73. }
  74. FallBack "Diffuse"
  75. }