Advertisement
axoila

Untitled

Mar 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void frag(v2f i, out half4 outDiffuse : COLOR0, out half4 outSpecular : COLOR1,
  2.                     out half4 outNormal : COLOR2, out half4 outEmissive : COLOR3)
  3.             {
  4.                 UNITY_SETUP_INSTANCE_ID (i);
  5.  
  6.                 i.ray = i.ray * (_ProjectionParams.z / i.ray.z);
  7.                 float2 uv = i.screenUV.xy / i.screenUV.w;
  8.                 // read depth and reconstruct world position
  9.                 float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
  10.                 depth = Linear01Depth (depth);
  11.                 float4 vpos = float4(i.ray * depth,1);
  12.                 float3 wpos = mul (unity_CameraToWorld, vpos).xyz;
  13.                 float3 opos = mul (unity_WorldToObject, float4(wpos,1)).xyz;
  14.  
  15.                 clip (float3(0.5,0.5,0.5) - abs(opos.xyz));
  16.  
  17.  
  18.                 i.uv = opos.xz+0.5;
  19.  
  20.                 half3 normal = tex2D(_NormalsCopy, uv).rgb;
  21.                 fixed3 wnormal = normal.rgb * 2.0 - 1.0;
  22.                 clip (dot(wnormal, i.orientation) - 0.3);
  23.  
  24.                 half2 metalRough = tex2D(_MetalRough, i.uv);
  25.  
  26.                 half4 col = tex2D (_MainTex, i.uv);
  27.  
  28.                 clip(col.a - 0.1);
  29.  
  30.                 half3 specColor;
  31.                 half oneMinusReflectivity;
  32.                 half3 diffuse = DiffuseAndSpecularFromMetallic(col, metalRough.x, specColor, oneMinusReflectivity);
  33.                 outDiffuse = half4(diffuse, 1);
  34.  
  35.                 fixed3 nor = UnpackNormal(tex2D(_BumpMap, i.uv));
  36.                 half3x3 norMat = half3x3(i.orientationX, i.orientationZ, i.orientation);
  37.                 nor = mul (nor, norMat);
  38.                 outNormal = half4(nor*0.5+0.5,1);
  39.  
  40.                 outSpecular = half4(specColor, 1-sqrt(metalRough.y));
  41.  
  42.                 half3 emissive = tex2D(_Emissive, i.uv) * _EmissiveColor;
  43.                 #ifndef UNITY_HDR_ON
  44.                     emissive.rgb = exp2(-emissive.rgb);
  45.                 #endif
  46.                 outEmissive = half4(emissive, col.a);
  47.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement