Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2.  
  3. #ifndef TERRAIN_SPLATMAP_COMMON_CGINC_INCLUDED
  4. #define TERRAIN_SPLATMAP_COMMON_CGINC_INCLUDED
  5.  
  6. struct Input
  7. {
  8.     float2 uv_Splat0 : TEXCOORD0;
  9.     float2 uv_Splat1 : TEXCOORD1;
  10.     float2 uv_Splat2 : TEXCOORD2;
  11.     float2 uv_Splat3 : TEXCOORD3;
  12.     float2 tc_Control : TEXCOORD4;  // Not prefixing '_Contorl' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
  13.     UNITY_FOG_COORDS(5)
  14. };
  15.  
  16. sampler2D _Control;
  17. float4 _Control_ST;
  18. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
  19.  
  20. #ifdef _TERRAIN_NORMAL_MAP
  21.     sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
  22. #endif
  23.  
  24. void SplatmapVert(inout appdata_full v, out Input data)
  25. {
  26.     UNITY_INITIALIZE_OUTPUT(Input, data);
  27.     data.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);  // Need to manually transform uv here, as we choose not to use 'uv' prefix for this texcoord.
  28.     float4 pos = UnityObjectToClipPos(v.vertex);
  29.     UNITY_TRANSFER_FOG(data, pos);
  30.  
  31. #ifdef _TERRAIN_NORMAL_MAP
  32.     v.tangent.xyz = cross(v.normal, float3(0,0,1));
  33.     v.tangent.w = -1;
  34. #endif
  35. }
  36.  
  37. #ifdef TERRAIN_STANDARD_SHADER
  38. void SplatmapMix(Input IN, half4 defaultAlpha, out half4 splat_control, out half weight, out fixed4 mixedDiffuse, inout float3 mixedNormal)
  39. #else
  40. void SplatmapMix(Input IN, out half4 splat_control, out half weight, out fixed4 mixedDiffuse, inout fixed3 mixedNormal)
  41. #endif
  42. {
  43.     splat_control = tex2D(_Control, IN.tc_Control);
  44.     weight = dot(splat_control, half4(1,1,1,1));
  45.  
  46.     #if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
  47.         clip(weight == 0.0f ? -1 : 1);
  48.     #endif
  49.  
  50.     // Normalize weights before lighting and restore weights in final modifier functions so that the overal
  51.     // lighting result can be correctly weighted.
  52.     splat_control /= (weight + 1e-3f);
  53.  
  54.     mixedDiffuse = 0.0f;
  55.     #ifdef TERRAIN_STANDARD_SHADER
  56.         mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.uv_Splat0) * half4(1.0, 1.0, 1.0, defaultAlpha.r);
  57.         mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.uv_Splat1) * half4(1.0, 1.0, 1.0, defaultAlpha.g);
  58.         mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.uv_Splat2) * half4(1.0, 1.0, 1.0, defaultAlpha.b);
  59.         mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.uv_Splat3) * half4(1.0, 1.0, 1.0, defaultAlpha.a);
  60.     #else
  61.         mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.uv_Splat0);
  62.         mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.uv_Splat1);
  63.         mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.uv_Splat2);
  64.         mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.uv_Splat3);
  65.     #endif
  66.  
  67.     #ifdef _TERRAIN_NORMAL_MAP
  68.         fixed4 nrm = 0.0f;
  69.         nrm += splat_control.r * tex2D(_Normal0, IN.uv_Splat0);
  70.         nrm += splat_control.g * tex2D(_Normal1, IN.uv_Splat1);
  71.         nrm += splat_control.b * tex2D(_Normal2, IN.uv_Splat2);
  72.         nrm += splat_control.a * tex2D(_Normal3, IN.uv_Splat3);
  73.         mixedNormal = UnpackNormal(nrm);
  74.     #endif
  75. }
  76.  
  77. #ifndef TERRAIN_SURFACE_OUTPUT
  78.     #define TERRAIN_SURFACE_OUTPUT SurfaceOutput
  79. #endif
  80.  
  81. void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
  82. {
  83.     color *= o.Alpha;
  84.     #ifdef TERRAIN_SPLAT_ADDPASS
  85.         UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
  86.     #else
  87.         UNITY_APPLY_FOG(IN.fogCoord, color);
  88.     #endif
  89. }
  90.  
  91. void SplatmapFinalPrepass(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 normalSpec)
  92. {
  93.     normalSpec *= o.Alpha;
  94. }
  95.  
  96. void SplatmapFinalGBuffer(Input IN, TERRAIN_SURFACE_OUTPUT o, inout half4 outGBuffer0, inout half4 outGBuffer1, inout half4 outGBuffer2, inout half4 emission)
  97. {
  98.     UnityStandardDataApplyWeightToGbuffer(outGBuffer0, outGBuffer1, outGBuffer2, o.Alpha);
  99.     emission *= o.Alpha;
  100. }
  101.  
  102. #endif // TERRAIN_SPLATMAP_COMMON_CGINC_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement