Sign in to follow this  

World to screen conversion

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, How to convert a 3D world position to screen space? I'm trying Cascaded ShadowMaps for directional lights. The last thing that remains is picking which shadowMap split to use in the result shader. The shader gets 4 distances that split up the frustum. From the nVidia example:
	// f[i].fard is originally in eye space - tell's us how far we can see.
	// Here we compute it in camera homogeneous coordinates. Basically, we calculate
	// cam_proj * (0, 0, f[i].fard, 1)^t and then normalize to [0; 1]
	far_bound[i] = 0.5f * (-frustum[i].farD * cam_projMatrix[10] + cam_projMatrix[14]) / frustum[i].farD + 0.5f;
	
	...
	in the shader, do a depth/distance check:
	if ( gl_Fragcoord.z < far_Bound[0] ) --> use texture 0   else
	if ( gl_Fragcoord.z < far_Bound[1] ) --> use texture 1   else
	if ( gl_Fragcoord.z < far_Bound[2] ) --> use texture 2   else
I'm using Cg instead of glsl, but it should have the equivalent; "WPOS" which is basically the screen position of the pixel. However, this doesn't work for me because I'm rendering on a screen filling quad, the Z component is missing. What I do have is the pixel world XYZ (not W) coordinate. I need to convert it somehow so it can be used in the comparison shown in the code above... Greetings, Rick

Share this post


Link to post
Share on other sites
Sorry for the late reply. I thought this post starved :)

Is it correct that I can reproduce that line to this shader code:
z = (mul( glstate.matrix.mvp, float4( worldPos.xyz, 1.0f ) ).z + 1.0f) / 2.0f;

Thus using the modelview projection matrix instead of proj * modelview? I tried it, but the Z value still seems to be wrong. Maybe I'm using the wrong matrix? The one above is from the current camera view, not the light perspective.

Thanks

Share this post


Link to post
Share on other sites

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this