unsigned int FirstProgram = glGetUniformBlockIndex(shaders.ShaderPrograms[0]->mProgram, "Matrices");//достаю номер юниформ блока в первой шейдерной программе
unsigned int SecondProgram = glGetUniformBlockIndex(shaders.ShaderPrograms[1]->mProgram, "Matrices");//достаю номер юниформ во второй шейдерной программе
glUniformBlockBinding(shaders.ShaderPrograms[0]->mProgram, FirstProgram, 0);
glUniformBlockBinding(shaders.ShaderPrograms[1]->mProgram, SecondProgram, 0);
unsigned int uboMatrices;
glGenBuffers(1, &uboMatrices);
glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices);
glBufferData(GL_UNIFORM_BUFFER, 2 * sizeof(glm::mat4), NULL, GL_STATIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glBindBufferRange(GL_UNIFORM_BUFFER, 0, uboMatrices, 0, 2 * sizeof(glm::mat4));
glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(proj));
glBindBuffer(GL_UNIFORM_BUFFER, 0);
#version 330
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec3 normals;
layout (std140) uniform Matrices1
{
mat4 projectionMatrix;
mat4 ViewMatrix;
};
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoord;
uniform mat4 ModelMatrix;
void main()
{
gl_Position = projectionMatrix * ViewMatrix * ModelMatrix * vec4(position, 1.0f);
FragPos = vec3(ModelMatrix * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(ModelMatrix))) * normals;
TexCoord = uv;
}
#version 330
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec3 normals;
layout (std140) uniform Matrices2
{
mat4 projectionMatrix;
mat4 ViewMatrix;
};
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoord;
uniform mat4 ModelMatrix;
void main()
{
gl_Position = projectionMatrix * ViewMatrix * ModelMatrix * vec4(position, 1.0f);
FragPos = vec3(ModelMatrix * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(ModelMatrix))) * normals;
TexCoord = uv;
#version 330
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec3 normals;
layout (std140) uniform Matrices3
{
mat4 projectionMatrix;
mat4 ViewMatrix;
};
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoord;
uniform mat4 ModelMatrix;
void main()
{
gl_Position = projectionMatrix * ViewMatrix * ModelMatrix * vec4(position, 1.0f);
FragPos = vec3(ModelMatrix * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(ModelMatrix))) * normals;
TexCoord = uv;
}