Advertisement
Guest User

ParallaxMoving.shader

a guest
Sep 8th, 2019
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Parallax Moving"
  2. {
  3.     Properties
  4.     {
  5.         _Color("Color", Color) = (1,1,1,1)
  6.         _MainTex("Albedo (RGB)", 2D) = "white" {}
  7.        
  8.         _Glossiness("Smoothness", Range(0,1)) = 0.5
  9.         _Metallic("Metallic", Range(0,1)) = 0.0
  10.         _DepthMap("DepthMap", 2D) = "grey" {}
  11.         _Normal("Normal", 2D) = "bump" {}
  12.         _Parallax("Parallax Depth", Range(0,10)) = 0.0
  13.         _Layers("Parallax Layers", Range(0,10)) = 1.0
  14.         _Speed("Speed", Range(0,10)) = 1.0
  15.         _Distort("Albedo Deep (RGB)", 2D) = "white" {}
  16.  
  17.  
  18.     }
  19.         SubShader
  20.         {
  21.             Tags { "RenderType" = "Opaque" }
  22.             LOD 200
  23.  
  24.             CGPROGRAM
  25.             // Physically based Standard lighting model, and enable shadows on all light types
  26.             #pragma surface surf Standard fullforwardshadows
  27.  
  28.             // Use shader model 3.0 target, to get nicer looking lighting
  29.             #pragma target 3.0
  30.  
  31.             sampler2D _MainTex;
  32.  
  33.             struct Input
  34.             {
  35.                 float2 uv_MainTex;
  36.                 float2 uv_Normal;
  37.                 float3 viewDir;
  38.                 float2 uv_MainTex2;
  39.             };
  40.  
  41.             half _Glossiness;
  42.             half _Metallic;
  43.             fixed4 _Color;
  44.  
  45.             float _Parallax;
  46.             sampler2D _DepthMap, _Normal, _Distort;
  47.             float _Layers, _Speed;
  48.  
  49.             // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  50.             // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  51.             // #pragma instancing_options assumeuniformscaling
  52.             UNITY_INSTANCING_BUFFER_START(Props)
  53.                 // put more per-instance properties here
  54.             UNITY_INSTANCING_BUFFER_END(Props)
  55.  
  56.             void surf(Input IN, inout SurfaceOutputStandard o)
  57.             {
  58.                 // depth map for parallax  
  59.                 float d = tex2D(_DepthMap, IN.uv_MainTex).r;
  60.                 float distort = tex2D(_Distort, IN.uv_MainTex).r;
  61.                 for (float i = 0; i < _Layers; i++)
  62.                 {
  63.                     IN.uv_MainTex += ParallaxOffset(tex2D(_DepthMap, IN.uv_MainTex - (_Time.x * _Speed )+ distort), _Parallax, IN.viewDir);
  64.  
  65.                 }
  66.                 o.Normal = UnpackNormal(tex2D(_Normal, saturate(IN.uv_MainTex)));
  67.                 // Albedo comes from a texture tinted by color
  68.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  69.            
  70.                 o.Albedo = c.rgb;
  71.                 // Metallic and smoothness come from slider variables
  72.                 o.Metallic = _Metallic;
  73.                 o.Smoothness = _Glossiness;
  74.                 o.Alpha = c.a;
  75.             }
  76.             ENDCG
  77.         }
  78.             FallBack "Diffuse"
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement