B
B
BelBES2014-04-04 16:18:20
Android
BelBES, 2014-04-04 16:18:20

What does the ModelViewProjection matrix do in OpenGL ES 2.0?

Hello!
Working with shaders in Android, there was a slight dissonance in understanding what is happening, I can’t figure out what should be assigned to the gl_Position variable inside the shader.
Consider two cases:
1) I pass to the shader the coordinates of 3D points with coordinates lying inside the unit cube. Inside the vertex shader, I simply assign them (bringing them to a uniform look) to the gl_Position variable and when working, the Shader itself projects these points onto the screen plane in accordance with the current viewport.
2) Now let's say that I pass an attribute with 3D vertex coordinates and a Model-View-Projection matrix to the shader. By applying the MVP matrix to the vertex coordinates, I will get 2D coordinates on some plane (let's say they lie within some VGA image). And here a dissonance arises, how should this resulting plane and my current viewport be related, in what form should I put the received coordinates in gl_Position and what will the shader do next with these points before drawing, because there the coordinates are no longer limited to a single cube?
Can someone clarify these questions for me?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kosmos89, 2014-04-04
@kosmos89

The shader itself projects

You write a shader, how can he do something himself? It is the rasterization block that "projects" them.
The process is as follows: the output of the vertex shader is three-dimensional homogeneous vertex coordinates. The hardware rasterizer takes these vertices, divides x,y,z by w and draws only those that fall into the (-1,-1,-1)-(1,1,1) cube (actually, triangles still need to be taken into account here that are partly off screen). In this case, the x and y coordinates determine the coordinates of the resulting pixel on the screen.
The projection matrix must be built in such a way that the w-coordinate is written with a value somehow related to z.
More information can be found here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question