FlattenTerrain.shader 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Shader "Custom/FlattenTerrain" {
  2. Properties{
  3. _Tess("Tessellation", Range(1,32)) = 4
  4. _EdgeLength("Edge length", Range(1,50)) = 15
  5. _MainTex("Base (RGB)", 2D) = "white" {}
  6. _DispTex("Disp Texture", 2D) = "gray" {}
  7. _Displacement("Displacement", Range(0, 10.0)) = 0.3
  8. _Color("Color", color) = (1,1,1,0)
  9. _SpecColor("Spec color", color) = (0.5,0.5,0.5,0.5)
  10. }
  11. SubShader{
  12. Tags{ "RenderType" = "Opaque" }
  13. LOD 300
  14. CGPROGRAM
  15. #pragma surface surf BlinnPhong addshadow fullforwardshadows vertex:disp tessellate:tessFixed nolightmap
  16. #pragma target 5.0
  17. #include "Tessellation.cginc"
  18. struct appdata {
  19. float4 vertex : POSITION;
  20. float3 normal : NORMAL;
  21. float2 texcoord : TEXCOORD0;
  22. };
  23. float _EdgeLength;
  24. float4 tessEdge(appdata v0, appdata v1, appdata v2)
  25. {
  26. return UnityEdgeLengthBasedTess(v0.vertex, v1.vertex, v2.vertex, _EdgeLength);
  27. }
  28. float _Tess;
  29. float4 tessFixed()
  30. {
  31. return _Tess;
  32. }
  33. sampler2D _DispTex;
  34. float _Displacement;
  35. void disp(inout appdata v)
  36. {
  37. float d = (1 - tex2Dlod(_DispTex, float4(v.texcoord.xy,0,0)).r) * _Displacement;
  38. v.vertex.y += _Displacement - d;
  39. // v.normal *= -1;
  40. }
  41. struct Input {
  42. float2 uv_MainTex;
  43. };
  44. sampler2D _MainTex;
  45. fixed4 _Color;
  46. void surf(Input IN, inout SurfaceOutput o) {
  47. half4 c = tex2D(_DispTex, IN.uv_MainTex) * _Color;
  48. if (c.r == 0) clip(-1);
  49. c.a = 0;
  50. o.Albedo = c;
  51. o.Specular = 0.2;
  52. o.Gloss = 1.0;
  53. }
  54. ENDCG
  55. }
  56. FallBack "Diffuse"
  57. }