Answer the question
In order to leave comments, you need to log in
What is the difference between mvpmatrix and those that are set separately and should they be connected (separately) and in what cases?
What is the difference between mvpmatrix(m_shaderProgramm.setUniformValue("MVPMatrix", m_projectionMatrix * modelViewMatrix);) and those that are set separately and should they be connected (separately) and in what cases?
attribute vec4 a_position;
attribute vec2 a_textcoord;
uniform mat4 MVPMatrix;
uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 Projectionmatrix;
varying vec2 TexCoord;
void main(void)
{
gl_Position = MVPMatrix * a_position;
TexCoord = a_textcoord;
}
void MainWindow::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 modelViewMatrix;
modelViewMatrix.setToIdentity();
modelViewMatrix.translate(0.0f, 0.0f, -5.0f);
modelViewMatrix.rotate(m_rotation);
m_texture->bind(0);
//m_shaderProgramm.bind();
m_shaderProgramm.setUniformValue("MVPMatrix", m_projectionMatrix * modelViewMatrix);
m_shaderProgramm.setUniformValue("Texture", 0);
// Bind buffers
m_vertexBuffer.bind();
m_indexBuffer.bind();
int offset = 0;
int location = m_shaderProgramm.attributeLocation("a_position");
m_shaderProgramm.enableAttributeArray(location);
m_shaderProgramm.setAttributeBuffer(location, GL_FLOAT, offset, 3, sizeof(VertexData));
offset += sizeof(QVector3D);
location = m_shaderProgramm.attributeLocation("a_textcoord");
m_shaderProgramm.enableAttributeArray(location);
m_shaderProgramm.setAttributeBuffer(location, GL_FLOAT, offset, 2, sizeof(VertexData));
glDrawElements(GL_TRIANGLES, m_indexBuffer.size(), GL_UNSIGNED_INT, 0);
}
Answer the question
In order to leave comments, you need to log in
For a better understanding of the material, you should study at least this article .
ModelMatrix
- это матрица преобразования локального пространства геометрии конкретного объекта.ModelMatrix
.ViewMatrix
- матрица отображения любого внешнего пространства в пространство вида - пространство взора наблюдателя. Наблюдатель (камера) воспринимает объекты только внутри своего собственного локального пространства. Чтобы наблюдатель мог увидеть объект, объект необходимо отобразить из его родного пространства в пространство вида камеры, где он или попадет в область проекции, или не попадет.Projectionmatrix
- матрица отображения видового пространства в пространство проекции вида. Фактически это отображение выполняет проецирование некоторого участка видового пространства на плоскость. Именно отображенная таким образом геометрия становится видимой при презентации кадра.ModelMatrix
.ViewMatrix
.Projectionmatrix
.Projectionmatrix
и ViewMatrix
уникальны для камеры, а вот матрицы ModelMatrix
уникальны уже для каждого объекта отдельно.Projectionmatrix
the ViewMatrix
frame presentation process is unchanged, the cost of 48 operations for each position looks like waste. If, before the presentation, the view space itself is mapped to the projection space, i.e. multiply ViewMatrix
andProjectionmatrix
in the correct order, then with the help of the resulting matrix, the viewProjectionMatrix
number of operations per position can be reduced to 32. viewProjectionMatrix
and ModelMatrix
in the correct order, then thanks to the resulting matrix, the MVPMatrix
number of operations per position will decrease to initial 16. viewProjectionMatrix
and MVPMatrix
simply allow to reduce the complexity of the presentation of the frame. However, during the presentation, it may be necessary to determine the position of the geometry in some intermediate space, therefore, in addition to MVPMatrix
the shader, it is customary to give both ModelMatrix
, and camera matrices. MVPMatrix
is undoubtedly always needed, then any other matrix should be added to the shader only on the basis of a meaningful need. The GPU registers for a shader are not rubbery and can get clogged with redundant data very quickly. In addition, the less data is transferred to the shader on each frame, the faster the frame presentation is performed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question