Mir

Merge lp:~vanvugt/mir/perspective into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1502
Proposed branch: lp:~vanvugt/mir/perspective
Merge into: lp:mir
Diff against target: 38 lines (+16/-2)
1 file modified
src/server/compositor/gl_renderer.cpp (+16/-2)
To merge this branch: bzr merge lp:~vanvugt/mir/perspective
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Aguirre (community) Approve
Alan Griffiths Approve
Review via email: mp+212085@code.launchpad.net

Commit message

GLRenderer: Add support for 3D perspective projection.

While your vertices remain at Z=0 you won't notice any change and things will
remain flat. However if you now use Z!=0 you will see 3D perspective (e.g.
render_surfaces).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

The failure is unrelated. It's bug 1295231 again.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Nice

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/compositor/gl_renderer.cpp'
2--- src/server/compositor/gl_renderer.cpp 2014-03-20 11:36:34 +0000
3+++ src/server/compositor/gl_renderer.cpp 2014-03-24 02:41:17 +0000
4@@ -48,7 +48,6 @@
5 "void main() {\n"
6 " vec4 mid = vec4(centre, 0.0, 0.0);\n"
7 " vec4 transformed = (transform * (vec4(position, 1.0) - mid)) + mid;\n"
8- " transformed.z = 0.0;\n" // avoid clipping while we lack depth/perspective
9 " gl_Position = display_transform * screen_to_gl_coords * transformed;\n"
10 " v_texcoord = texcoord;\n"
11 "}\n"
12@@ -304,10 +303,25 @@
13 * (top-left is (-1,1), bottom-right is (1,-1))
14 */
15 glm::mat4 screen_to_gl_coords = glm::translate(glm::mat4(1.0f), glm::vec3{-1.0f, 1.0f, 0.0f});
16+
17+ /*
18+ * Perspective division is one thing that can't be done in a matrix
19+ * multiplication. It happens after the matrix multiplications. GL just
20+ * scales {x,y} by 1/w. So modify the final part of the projection matrix
21+ * to set w ([3]) to be the incoming z coordinate ([2]).
22+ */
23+ screen_to_gl_coords[2][3] = -1.0f;
24+
25+ float const vertical_fov_degrees = 30.0f;
26+ float const near =
27+ (rect.size.height.as_float() / 2.0f) /
28+ std::tan((vertical_fov_degrees * M_PI / 180.0f) / 2.0f);
29+ float const far = -near;
30+
31 screen_to_gl_coords = glm::scale(screen_to_gl_coords,
32 glm::vec3{2.0f / rect.size.width.as_float(),
33 -2.0f / rect.size.height.as_float(),
34- 1.0f});
35+ 2.0f / (near - far)});
36 screen_to_gl_coords = glm::translate(screen_to_gl_coords,
37 glm::vec3{-rect.top_left.x.as_float(),
38 -rect.top_left.y.as_float(),

Subscribers

People subscribed via source and target branches