The formula of computing depth
Closed this issue · 1 comments
Hi ~ I am confused about the formula of computing depth in attribute_fs.glsl
. The formula is as follows:
float depth = -projection_matrix[3][2] * (1.0 / zval) - projection_matrix[2][2];
But I think the correct formula is like:
float depth = -projection_matrix[2][3] * (1.0 / zval) - projection_matrix[2][2];
refenrence to http://www.songho.ca/opengl/gl_projectionmatrix.html
However, when I change the code of this line and test it , I find the model can not display in nearest place.
So, could you tell me why?
I should have put a comment there. See section 5.6 of the GLSL spec:
Applying a single subscript to a matrix treats the matrix as an array of column vectors, and selects a single column, whose type is a vector of the same size as the matrix. The leftmost column is column 0. A second subscript would then operate on the resulting vector, as defined earlier for vectors. Hence, two subscripts select a column and then a row.