Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ShaderGraph converted from
- //https://www.youtube.com/watch?v=QN39W020LqU&index=2&t=0s&list=PLFt_AvWsXl0cONs3T0By4puYy6GM22ko8
- //All creds to Sebastian Lague
- Shader "PlanetOwn"
- {
- Properties
- {
- _elevationMinMax("Elevation", Vector) = (0,1,0,0)
- _texture("Texture", 2D) = "white" {}
- _smoothness("Smoothness", Float) = 0
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 100
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- // make fog work
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- UNITY_FOG_COORDS(1)
- float4 vertex : SV_POSITION;
- };
- sampler2D _texture;
- float2 _elevationMinMax;
- float4 _texture_ST;
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = TRANSFORM_TEX(v.uv, _texture);
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- float Inverse_lerp(float a, float b, float value)
- {
- return (value -a)/(b-a);
- }
- fixed4 frag (v2f i) : SV_Target
- {
- // sample the texture
- float node_2 = Inverse_lerp(_elevationMinMax.r, 0, i.uv.g);
- float node_1 = floor(node_2);
- float2 uvt = float2(
- (
- (
- lerp(
- 0,
- 0.5,
- Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
- )
- *
- (
- floor(
- Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
- )
- -
- 1
- )
- )
- +
- floor(
- Inverse_lerp(_elevationMinMax.r, 0, i.uv.g)
- )
- *
- lerp(0, 1,
- Inverse_lerp(0, _elevationMinMax.g, i.uv.g)
- )
- )
- ,
- i.uv.r);
- fixed3 col = tex2D(_texture, uvt);
- // apply fog
- //UNITY_APPLY_FOG(i.fogCoord, col);
- return fixed4(col.r, col.g, col.b, 1);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement