Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Could some one help me to understand this code and explain it?

It's about converting from 3D space to 2D position, so that I can use it in another Effects (.fx) files, but I am a bit confused.

float viewportWidth;
float viewportHight;

//  calculate the 2D screen Position of a 3D position
float2 postProjectionToScreen(float4 position)
{
    float2 screenPos = position.xy/position.w;
    return 0.5f *(float2(screenPos.x,-screenPos.y)+1);
}

//  Calculate the size of one half of a pixel , to convert
//  between texels and pixels
float2 halfPixel()
{
    return 0.5f/float2(viewportWidth,viewportHight);
}
share|improve this question
Quick note on context/origin: gamedev.stackexchange.com/questions/23808/… – tugs Jul 27 '12 at 23:55
thanks for you man – Mohammad Ahmed Jul 31 '12 at 21:01

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.