Advertisement
luluco250

Get normals from depth buffer

Dec 26th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. float3 PS_Gbuffer(float4 pos : SV_POSITION, float2 uv : TEXCOORD) : SV_TARGET {
  2.     float z = ReShade::GetLinearizedDepth(uv);
  3.     float dx = BUFFER_RCP_WIDTH;
  4.     float dy = BUFFER_RCP_HEIGHT;
  5.     float dzdx = (ReShade::GetLinearizedDepth(uv + float2(dx, 0.0)) - ReShade::GetLinearizedDepth(uv + float2(-dx, 0.0))) / (2.0 * dx);
  6.     float dzdy = (ReShade::GetLinearizedDepth(uv + float2(0.0, dy)) - ReShade::GetLinearizedDepth(uv + float2(0.0, -dy))) / (2.0 * dy);
  7.     float3 d = float3(dzdx, -dzdy, z);
  8.     float3 n = normalize(d);
  9.     return n;
  10.     /*float3 lightDirection = float3(1.0, -2.0, 3.0);
  11.     float shading = 0.5 + 0.5 * dot(n, normalize(lightDirection));
  12.     return shading;*/
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement