Guest User

Untitled

a guest
Oct 27th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. Shader "Unlit/deph"
  2. {
  3.     Properties
  4.     {
  5.         _MainTexL ("Texture L", 2D) = "white" {}
  6.         _MainTexR ("Texture R", 2D) = "white" {}
  7.         _Size ("Texture Size", Vector) = (256,256,0,0)
  8.     }
  9.     SubShader
  10.     {
  11.         Tags { "RenderType"="Opaque" }
  12.         LOD 100
  13.  
  14.         Pass
  15.         {
  16.             CGPROGRAM
  17.             #pragma vertex vert
  18.             #pragma fragment frag
  19.             // make fog work
  20.             #pragma multi_compile_fog
  21.            
  22.             #include "UnityCG.cginc"
  23.  
  24.             struct appdata
  25.             {
  26.                 float4 vertex : POSITION;
  27.                 float2 uv : TEXCOORD0;
  28.             };
  29.  
  30.             struct v2f
  31.             {
  32.                 float2 uv : TEXCOORD0;
  33.                 UNITY_FOG_COORDS(1)
  34.                 float4 vertex : SV_POSITION;
  35.             };
  36.  
  37.             sampler2D _MainTexL;
  38.             sampler2D _MainTexR;
  39.             fixed4 _Size;
  40.            
  41.             float4 _MainTex_ST;
  42.            
  43.             v2f vert (appdata v)
  44.             {
  45.                 v2f o;
  46.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  47.                 o.uv = v.uv;
  48.                 //UNITY_TRANSFER_FOG(o,o.vertex);
  49.                 return o;
  50.             }
  51.            
  52.             fixed4 frag (v2f inp) : SV_Target
  53.             {
  54.                
  55.                 //fixed4 col = tex2D(_MainTexL, i.uv)*0.5 + tex2D(_MainTexR, i.uv)*0.5;
  56.                 fixed3 col=0;
  57.                 fixed dpX = 1/_Size.x;
  58.                 fixed dpY = 1/_Size.y;
  59.                
  60.                 fixed3 minW = fixed3(100,100,100);
  61.                 fixed d = 0;
  62.                 fixed3 wght = 0;
  63.                
  64.                 for(int i=0; i < int(_Size.z); i++) {
  65.                     wght = 0;
  66.                         int y=0;
  67.                     for(int y = -2; y <= 2; y++) {
  68.                         for(int x=-2; x <= 2; x++) {
  69.                             float4 lw = tex2D(_MainTexL, inp.uv + float2(x * dpX,y * dpY)) - tex2D(_MainTexR, inp.uv + float2((x+i) * dpX,y * dpY));
  70.                             wght += (lw*lw).rgb;
  71.                         }
  72.                     }
  73.                     if(wght.r < minW.r && wght.g < minW.g && wght.b < minW.b) {
  74.                         minW = wght;
  75.                         d = float(i) / _Size.z;
  76.                     }
  77.                 }
  78.                
  79.                 return fixed4(d,d,d,1);
  80.             }
  81.             ENDCG
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment