Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void frag(v2f i, out half4 outDiffuse : COLOR0, out half4 outSpecular : COLOR1,
- out half4 outNormal : COLOR2, out half4 outEmissive : COLOR3)
- {
- UNITY_SETUP_INSTANCE_ID (i);
- i.ray = i.ray * (_ProjectionParams.z / i.ray.z);
- float2 uv = i.screenUV.xy / i.screenUV.w;
- // read depth and reconstruct world position
- float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
- depth = Linear01Depth (depth);
- float4 vpos = float4(i.ray * depth,1);
- float3 wpos = mul (unity_CameraToWorld, vpos).xyz;
- float3 opos = mul (unity_WorldToObject, float4(wpos,1)).xyz;
- clip (float3(0.5,0.5,0.5) - abs(opos.xyz));
- i.uv = opos.xz+0.5;
- half3 normal = tex2D(_NormalsCopy, uv).rgb;
- fixed3 wnormal = normal.rgb * 2.0 - 1.0;
- clip (dot(wnormal, i.orientation) - 0.3);
- half2 metalRough = tex2D(_MetalRough, i.uv);
- half4 col = tex2D (_MainTex, i.uv);
- clip(col.a - 0.1);
- half3 specColor;
- half oneMinusReflectivity;
- half3 diffuse = DiffuseAndSpecularFromMetallic(col, metalRough.x, specColor, oneMinusReflectivity);
- outDiffuse = half4(diffuse, 1);
- fixed3 nor = UnpackNormal(tex2D(_BumpMap, i.uv));
- half3x3 norMat = half3x3(i.orientationX, i.orientationZ, i.orientation);
- nor = mul (nor, norMat);
- outNormal = half4(nor*0.5+0.5,1);
- outSpecular = half4(specColor, 1-sqrt(metalRough.y));
- half3 emissive = tex2D(_Emissive, i.uv) * _EmissiveColor;
- #ifndef UNITY_HDR_ON
- emissive.rgb = exp2(-emissive.rgb);
- #endif
- outEmissive = half4(emissive, col.a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement