Advertisement
lanboost

PlanetShader

Feb 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ShaderGraph converted from
  2. //https://www.youtube.com/watch?v=QN39W020LqU&index=2&t=0s&list=PLFt_AvWsXl0cONs3T0By4puYy6GM22ko8
  3. //All creds to Sebastian Lague
  4.  
  5.  
  6.  
  7. Shader "PlanetOwn"
  8. {
  9.     Properties
  10.     {
  11.         _elevationMinMax("Elevation", Vector) = (0,1,0,0)
  12.         _texture("Texture", 2D) = "white" {}
  13.         _smoothness("Smoothness", Float) = 0
  14.        
  15.     }
  16.     SubShader
  17.     {
  18.         Tags { "RenderType"="Opaque" }
  19.         LOD 100
  20.  
  21.         Pass
  22.         {
  23.             CGPROGRAM
  24.             #pragma vertex vert
  25.             #pragma fragment frag
  26.             // make fog work
  27.             #pragma multi_compile_fog
  28.  
  29.             #include "UnityCG.cginc"
  30.  
  31.             struct appdata
  32.             {
  33.                 float4 vertex : POSITION;
  34.                 float2 uv : TEXCOORD0;
  35.             };
  36.  
  37.             struct v2f
  38.             {
  39.                 float2 uv : TEXCOORD0;
  40.                 UNITY_FOG_COORDS(1)
  41.                 float4 vertex : SV_POSITION;
  42.             };
  43.  
  44.             sampler2D _texture;
  45.             float2 _elevationMinMax;
  46.             float4 _texture_ST;
  47.  
  48.             v2f vert (appdata v)
  49.             {
  50.                 v2f o;
  51.                 o.vertex = UnityObjectToClipPos(v.vertex);
  52.                 o.uv = TRANSFORM_TEX(v.uv, _texture);
  53.                 UNITY_TRANSFER_FOG(o,o.vertex);
  54.                 return o;
  55.             }
  56.  
  57.             float Inverse_lerp(float a, float b, float value)
  58.             {
  59.                 return (value -a)/(b-a);
  60.             }
  61.  
  62.             fixed4 frag (v2f i) : SV_Target
  63.             {
  64.                 // sample the texture
  65.             float node_2 = Inverse_lerp(_elevationMinMax.r, 0, i.uv.g);
  66.             float node_1 = floor(node_2);
  67.                
  68.  
  69.             float2 uvt = float2(
  70.                     (
  71.                         (
  72.                             lerp(
  73.                                 0,
  74.                                 0.5,
  75.                                 Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
  76.                             )
  77.  
  78.                         *
  79.                             (
  80.                                 floor(
  81.                                     Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
  82.                                 )
  83.                                 -
  84.                                 1
  85.                             )
  86.                         )
  87.                     +
  88.                         floor(
  89.                             Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
  90.                         )
  91.                         *
  92.                         lerp(0, 1,
  93.                             Inverse_lerp(0, _elevationMinMax.g, i.uv.g)
  94.                         )
  95.                     )
  96.                 ,
  97.                     i.uv.r);
  98.  
  99.  
  100.             fixed3 col = tex2D(_texture, uvt);
  101.  
  102.                 // apply fog
  103.                 //UNITY_APPLY_FOG(i.fogCoord, col);
  104.                 return fixed4(col.r, col.g, col.b, 1);
  105.             }
  106.             ENDCG
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement