Skip to content

Instantly share code, notes, and snippets.

@v3c70r
Last active September 16, 2015 19:53
Show Gist options
  • Save v3c70r/21312f645a6ab6746cc1 to your computer and use it in GitHub Desktop.
Save v3c70r/21312f645a6ab6746cc1 to your computer and use it in GitHub Desktop.
vec4 uvToEye(vec2 texCoord, float z) //screen to camera coordinate
{
const vec4 viewport = vec4(0, 0, 1, 1);
vec3 ndcPos;
//ndcPos.xy = ((2.0 * texCoord.xy)-(2.0*viewport.xy))/(viewport.zw)-1;
ndcPos.xy = 2 * (texCoord.xy) - vec2(1.0, 1.0);
ndcPos.z = (2.0 * z - 1.0);
vec4 clipPos;
//clipPos.w = camMats.projMat[3][2]/ (ndcPos.z - (camMats.projMat[2][2]/camMats.projMat[2][3]));
clipPos.w = camMats.projMat[3][2] / ( ndcPos.z + camMats.projMat[2][2]);
clipPos.xyz = ndcPos*clipPos.w;
return inverse(camMats.projMat) * clipPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment