Th3NiKo

Shader terrain

Jun 17th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  4.  
  5. Shader "Terrains/Terrain"
  6. {
  7. Properties
  8. {
  9. _MainTex ("Texture", 2D) = "gray" {}
  10. _NoiseTexture ("Texture", 2D) = "white" {}
  11. }
  12. SubShader
  13. {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 100
  16.  
  17. Pass
  18. {
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. // make fog work
  23. #pragma multi_compile_fog
  24.  
  25. #include "UnityCG.cginc"
  26.  
  27. struct appdata
  28. {
  29. float4 vertex : POSITION;
  30. float2 uv : TEXCOORD0;
  31. float4 worldPosition : TEXCOORD1;
  32. };
  33.  
  34. struct v2f
  35. {
  36. float2 uv : TEXCOORD0;
  37. UNITY_FOG_COORDS(1)
  38. float4 vertex : SV_POSITION;
  39. };
  40.  
  41. sampler2D _MainTex;
  42. float4 _MainTex_ST;
  43. sampler2D _NoiseTexture;
  44.  
  45. v2f vert (appdata v)
  46. {
  47. v2f o;
  48. float3 worldPos = mul (unity_ObjectToWorld, v.vertex).xyz;
  49. float4 offset = float4(0,tex2Dlod(_NoiseTexture, float4( worldPos.x / 100 , worldPos.z / 100 ,0,0)).r * 15,0,0);
  50.  
  51. o.vertex = UnityObjectToClipPos(v.vertex + offset);
  52.  
  53. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  54. UNITY_TRANSFER_FOG(o,o.vertex);
  55.  
  56. return o;
  57. }
  58.  
  59. fixed4 frag (v2f i) : SV_Target
  60. {
  61. // sample the texture
  62. fixed4 col = tex2D(_MainTex, i.uv);
  63. col.b = i.vertex.y / 700;
  64. // apply fog
  65. UNITY_APPLY_FOG(i.fogCoord, col);
  66. return col;
  67. }
  68. ENDCG
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment