qxsl2000

09-02-2014, 01:10 PM

hi,guys. i've saw a code snippet from gpu gmes 2,chapter 21:"High Quality Antialiased Rasterization", and really confused by the following code related space transforming:

// Compute a standard projection matrix from a field of view, hither and

// yon plans and screen resolution. This does not include tile offsets.

Matrix4

compute_cam2ras (float fov, float hither, float yon, int resx, int resy)

{

// Set up a projection matrix from camera to screen space (incl. aspect)

float aspect = float (resx) / float (resy);

Matrix4 cam2scr = Matrix4::PerspectiveMatrix (fov, aspect, hither, yon);

// Set up a 2D matrix from screen space to NDC (halve and translate)

Matrix4 scr2ndc = //what's does the matrix mean? why it post-mulply after cam2scr matrix(in homogeneous clip space)?

Matrix4 (0.5, 0, 0, 0,

0, -0.5, 0, 0,

0, 0, 1, 0,

0.5, 0.5, 0, 1);

// Set up a 2D matrix from NDC to raster space (OpenGL projection matrix)

Matrix4 ndc2ras =

Matrix4 ((float)resx, 0, 0, 0,

0, (float)resy, 0, 0,

0, 0, 1, 0,

0, 0, 0, 1);

Matrix4 cam2ras = cam2scr * scr2ndc * ndc2ras;

return cam2ras;

}

that comments above the "Matrix4 scr2ndc" line says transforming from screen space (viewport?) to NDC. how could it be that because cam2scr matrix was in homogeneous clip space,why not be transforming from NDC to screen space, e.g (-1,1) map to (0,1). those matries were really fuzzy. maybe something i can't figure out it ,correct me . i'll appreciate. thank you very much.:)

// Compute a standard projection matrix from a field of view, hither and

// yon plans and screen resolution. This does not include tile offsets.

Matrix4

compute_cam2ras (float fov, float hither, float yon, int resx, int resy)

{

// Set up a projection matrix from camera to screen space (incl. aspect)

float aspect = float (resx) / float (resy);

Matrix4 cam2scr = Matrix4::PerspectiveMatrix (fov, aspect, hither, yon);

// Set up a 2D matrix from screen space to NDC (halve and translate)

Matrix4 scr2ndc = //what's does the matrix mean? why it post-mulply after cam2scr matrix(in homogeneous clip space)?

Matrix4 (0.5, 0, 0, 0,

0, -0.5, 0, 0,

0, 0, 1, 0,

0.5, 0.5, 0, 1);

// Set up a 2D matrix from NDC to raster space (OpenGL projection matrix)

Matrix4 ndc2ras =

Matrix4 ((float)resx, 0, 0, 0,

0, (float)resy, 0, 0,

0, 0, 1, 0,

0, 0, 0, 1);

Matrix4 cam2ras = cam2scr * scr2ndc * ndc2ras;

return cam2ras;

}

that comments above the "Matrix4 scr2ndc" line says transforming from screen space (viewport?) to NDC. how could it be that because cam2scr matrix was in homogeneous clip space,why not be transforming from NDC to screen space, e.g (-1,1) map to (0,1). those matries were really fuzzy. maybe something i can't figure out it ,correct me . i'll appreciate. thank you very much.:)