Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/deph"
- {
- Properties
- {
- _MainTexL ("Texture L", 2D) = "white" {}
- _MainTexR ("Texture R", 2D) = "white" {}
- _Size ("Texture Size", Vector) = (256,256,0,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 _MainTexL;
- sampler2D _MainTexR;
- fixed4 _Size;
- float4 _MainTex_ST;
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uv = v.uv;
- //UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed4 frag (v2f inp) : SV_Target
- {
- //fixed4 col = tex2D(_MainTexL, i.uv)*0.5 + tex2D(_MainTexR, i.uv)*0.5;
- fixed3 col=0;
- fixed dpX = 1/_Size.x;
- fixed dpY = 1/_Size.y;
- fixed3 minW = fixed3(100,100,100);
- fixed d = 0;
- fixed3 wght = 0;
- for(int i=0; i < int(_Size.z); i++) {
- wght = 0;
- int y=0;
- for(int y = -2; y <= 2; y++) {
- for(int x=-2; x <= 2; x++) {
- float4 lw = tex2D(_MainTexL, inp.uv + float2(x * dpX,y * dpY)) - tex2D(_MainTexR, inp.uv + float2((x+i) * dpX,y * dpY));
- wght += (lw*lw).rgb;
- }
- }
- if(wght.r < minW.r && wght.g < minW.g && wght.b < minW.b) {
- minW = wght;
- d = float(i) / _Size.z;
- }
- }
- return fixed4(d,d,d,1);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment