Skip to content

Instantly share code, notes, and snippets.

@galek
Forked from jimmiebergmann/depth_to_position.glsl
Created November 22, 2016 07:41
Show Gist options
  • Save galek/d969447adcf8365602edc95631112d76 to your computer and use it in GitHub Desktop.
Save galek/d969447adcf8365602edc95631112d76 to your computer and use it in GitHub Desktop.
PS3 GLSL Depth to position
//Convert to 24bit
const float3 depthFactor = float3(65536.0f/16777215.0f, 256.0f/16777215.0f, 1.0f/16777215.0f );
float GetDepth( float4 raw_depth )
{
return dot( round( raw_depth.xyz * 255.0f.xxx ), depthFactor.xyz);
}
float2 texcoord = in.vpos/g_Resolution;
pos.xy = in.vpo;
pos.z = GetDepth( tex2D(g_Depthmap,texcoord).rgba );
pos = 2.0*pos-1.0;
float4 Clip = mul(g_MatrixInverseViewProj,float4(pos,1.0));
pos = (Clip.xyz / Clip.w);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment