Use fixed attribute location for instanced objects.
This commit is contained in:
parent
bc7e2cd517
commit
b861c3fb73
@ -10,21 +10,24 @@ layout (std140) uniform MatrixesData
|
|||||||
|
|
||||||
uniform vec3 windDir;
|
uniform vec3 windDir;
|
||||||
|
|
||||||
|
|
||||||
in vec3 Origin;
|
|
||||||
in vec3 Orientation;
|
|
||||||
in vec3 Scale;
|
|
||||||
|
|
||||||
#if __VERSION__ >= 330
|
#if __VERSION__ >= 330
|
||||||
layout(location = 0) in vec3 Position;
|
layout(location = 0) in vec3 Position;
|
||||||
layout(location = 1) in vec3 Normal;
|
layout(location = 1) in vec3 Normal;
|
||||||
layout(location = 2) in vec4 Color;
|
layout(location = 2) in vec4 Color;
|
||||||
layout(location = 3) in vec2 Texcoord;
|
layout(location = 3) in vec2 Texcoord;
|
||||||
|
|
||||||
|
layout(location = 7) in vec3 Origin;
|
||||||
|
layout(location = 8) in vec3 Orientation;
|
||||||
|
layout(location = 9) in vec3 Scale;
|
||||||
#else
|
#else
|
||||||
in vec3 Position;
|
in vec3 Position;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
in vec4 Color;
|
in vec4 Color;
|
||||||
in vec2 Texcoord;
|
in vec2 Texcoord;
|
||||||
|
|
||||||
|
in vec3 Origin;
|
||||||
|
in vec3 Orientation;
|
||||||
|
in vec3 Scale;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out vec3 nor;
|
out vec3 nor;
|
||||||
|
@ -15,18 +15,22 @@ layout (std140) uniform MatrixesData
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
in vec3 Origin;
|
|
||||||
in vec3 Orientation;
|
|
||||||
in vec3 Scale;
|
|
||||||
|
|
||||||
#if __VERSION__ >= 330
|
#if __VERSION__ >= 330
|
||||||
layout(location = 0) in vec3 Position;
|
layout(location = 0) in vec3 Position;
|
||||||
layout(location = 1) in vec3 Normal;
|
layout(location = 1) in vec3 Normal;
|
||||||
layout(location = 3) in vec2 Texcoord;
|
layout(location = 3) in vec2 Texcoord;
|
||||||
|
|
||||||
|
layout(location = 7) in vec3 Origin;
|
||||||
|
layout(location = 8) in vec3 Orientation;
|
||||||
|
layout(location = 9) in vec3 Scale;
|
||||||
#else
|
#else
|
||||||
in vec3 Position;
|
in vec3 Position;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
in vec2 Texcoord;
|
in vec2 Texcoord;
|
||||||
|
|
||||||
|
in vec3 Origin;
|
||||||
|
in vec3 Orientation;
|
||||||
|
in vec3 Scale;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out vec3 nor;
|
out vec3 nor;
|
||||||
|
@ -7,12 +7,21 @@ layout (std140) uniform MatrixesData
|
|||||||
mat4 ShadowViewProjMatrixes[4];
|
mat4 ShadowViewProjMatrixes[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if __VERSION__ >= 330
|
||||||
|
layout(location = 0) in vec3 Position;
|
||||||
|
layout(location = 3) in vec2 Texcoord;
|
||||||
|
|
||||||
|
layout(location = 7) in vec3 Origin;
|
||||||
|
layout(location = 8) in vec3 Orientation;
|
||||||
|
layout(location = 9) in vec3 Scale;
|
||||||
|
#else
|
||||||
|
in vec3 Position;
|
||||||
|
in vec2 Texcoord;
|
||||||
|
|
||||||
in vec3 Origin;
|
in vec3 Origin;
|
||||||
in vec3 Orientation;
|
in vec3 Orientation;
|
||||||
in vec3 Scale;
|
in vec3 Scale;
|
||||||
|
#endif
|
||||||
layout(location = 0) in vec3 Position;
|
|
||||||
layout(location = 3) in vec2 Texcoord;
|
|
||||||
|
|
||||||
#ifdef VSLayer
|
#ifdef VSLayer
|
||||||
out vec2 uv;
|
out vec2 uv;
|
||||||
|
@ -154,6 +154,9 @@ GLint LoadProgram(Types ... args)
|
|||||||
glBindAttribLocation(ProgramID, 4, "SecondTexcoord");
|
glBindAttribLocation(ProgramID, 4, "SecondTexcoord");
|
||||||
glBindAttribLocation(ProgramID, 5, "Tangent");
|
glBindAttribLocation(ProgramID, 5, "Tangent");
|
||||||
glBindAttribLocation(ProgramID, 6, "Bitangent");
|
glBindAttribLocation(ProgramID, 6, "Bitangent");
|
||||||
|
glBindAttribLocation(ProgramID, 7, "Origin");
|
||||||
|
glBindAttribLocation(ProgramID, 8, "Orientation");
|
||||||
|
glBindAttribLocation(ProgramID, 9, "Scale");
|
||||||
}
|
}
|
||||||
glLinkProgram(ProgramID);
|
glLinkProgram(ProgramID);
|
||||||
|
|
||||||
|
@ -27,10 +27,6 @@ void STKInstancedSceneNode::cleanGL()
|
|||||||
continue;
|
continue;
|
||||||
if (mesh.vao)
|
if (mesh.vao)
|
||||||
glDeleteVertexArrays(1, &(mesh.vao));
|
glDeleteVertexArrays(1, &(mesh.vao));
|
||||||
if (mesh.vao_second_pass)
|
|
||||||
glDeleteVertexArrays(1, &(mesh.vao_second_pass));
|
|
||||||
if (mesh.vao_shadow_pass)
|
|
||||||
glDeleteVertexArrays(1, &(mesh.vao_shadow_pass));
|
|
||||||
glDeleteBuffers(1, &(mesh.vertex_buffer));
|
glDeleteBuffers(1, &(mesh.vertex_buffer));
|
||||||
glDeleteBuffers(1, &(mesh.index_buffer));
|
glDeleteBuffers(1, &(mesh.index_buffer));
|
||||||
}
|
}
|
||||||
@ -56,83 +52,34 @@ void STKInstancedSceneNode::createGLMeshes()
|
|||||||
isMaterialInitialized = false;
|
isMaterialInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, unsigned divisor>
|
|
||||||
void setInstanceAttribPointer()
|
|
||||||
{
|
|
||||||
glEnableVertexAttribArray(T::attrib_origin);
|
|
||||||
glVertexAttribPointer(T::attrib_origin, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
|
|
||||||
glVertexAttribDivisor(T::attrib_origin, divisor);
|
|
||||||
glEnableVertexAttribArray(T::attrib_orientation);
|
|
||||||
glVertexAttribPointer(T::attrib_orientation, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(3 * sizeof(float)));
|
|
||||||
glVertexAttribDivisor(T::attrib_orientation, divisor);
|
|
||||||
glEnableVertexAttribArray(T::attrib_scale);
|
|
||||||
glVertexAttribPointer(T::attrib_scale, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(6 * sizeof(float)));
|
|
||||||
glVertexAttribDivisor(T::attrib_scale, divisor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat)
|
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat)
|
||||||
{
|
{
|
||||||
switch (GeoMat)
|
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
||||||
{
|
glGenBuffers(1, &instances_vbo);
|
||||||
case FPSM_DEFAULT:
|
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
||||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
|
||||||
glGenBuffers(1, &instances_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedObjectPass1Shader, 1>();
|
|
||||||
if (irr_driver->getGLSLVersion() >= 150)
|
|
||||||
{
|
|
||||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedShadowShader, 4>();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FPSM_ALPHA_REF_TEXTURE:
|
|
||||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glGenBuffers(1, &instances_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedObjectRefPass1Shader, 1>();
|
|
||||||
if (irr_driver->getGLSLVersion() >= 150)
|
|
||||||
{
|
|
||||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedRefShadowShader, 4>();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FPSM_GRASS:
|
|
||||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glGenBuffers(1, &instances_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedGrassPass1Shader, 1>();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(7);
|
||||||
|
glVertexAttribPointer(7, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
|
||||||
|
glVertexAttribDivisor(7, 1);
|
||||||
|
glEnableVertexAttribArray(8);
|
||||||
|
glVertexAttribPointer(8, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(3 * sizeof(float)));
|
||||||
|
glVertexAttribDivisor(8, 1);
|
||||||
|
glEnableVertexAttribArray(9);
|
||||||
|
glVertexAttribPointer(9, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(6 * sizeof(float)));
|
||||||
|
glVertexAttribDivisor(9, 1);
|
||||||
|
|
||||||
|
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
||||||
switch (ShadedMat)
|
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
||||||
{
|
glEnableVertexAttribArray(7);
|
||||||
case SM_DEFAULT:
|
glVertexAttribPointer(7, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), 0);
|
||||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
glVertexAttribDivisor(7, 4);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
glEnableVertexAttribArray(8);
|
||||||
setInstanceAttribPointer<MeshShader::InstancedObjectPass2Shader, 1>();
|
glVertexAttribPointer(8, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(3 * sizeof(float)));
|
||||||
break;
|
glVertexAttribDivisor(8, 4);
|
||||||
case SM_ALPHA_REF_TEXTURE:
|
glEnableVertexAttribArray(9);
|
||||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
glVertexAttribPointer(9, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (GLvoid*)(6 * sizeof(float)));
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
glVertexAttribDivisor(9, 4);
|
||||||
setInstanceAttribPointer<MeshShader::InstancedObjectRefPass2Shader, 1>();
|
|
||||||
break;
|
|
||||||
case SM_GRASS:
|
|
||||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, instances_vbo);
|
|
||||||
setInstanceAttribPointer<MeshShader::InstancedGrassPass2Shader, 1>();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
@ -152,10 +99,8 @@ void STKInstancedSceneNode::setFirstTimeMaterial()
|
|||||||
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type);
|
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type);
|
||||||
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures);
|
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures);
|
||||||
initinstancedvaostate(mesh, GeometricType, ShadedType);
|
initinstancedvaostate(mesh, GeometricType, ShadedType);
|
||||||
if (mesh.vao_first_pass)
|
GeometricMesh[GeometricType].push_back(&mesh);
|
||||||
GeometricMesh[GeometricType].push_back(&mesh);
|
ShadedMesh[ShadedType].push_back(&mesh);
|
||||||
if (mesh.vao_second_pass)
|
|
||||||
ShadedMesh[ShadedType].push_back(&mesh);
|
|
||||||
}
|
}
|
||||||
isMaterialInitialized = true;
|
isMaterialInitialized = true;
|
||||||
}
|
}
|
||||||
@ -193,7 +138,7 @@ static void drawFSPMDefault(GLMesh &mesh, size_t instance_count)
|
|||||||
}
|
}
|
||||||
MeshShader::InstancedObjectPass1Shader::setUniforms(0);
|
MeshShader::InstancedObjectPass1Shader::setUniforms(0);
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_first_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
|
|
||||||
if (!mesh.textures[0])
|
if (!mesh.textures[0])
|
||||||
@ -212,7 +157,6 @@ static void drawShadowDefault(GLMesh &mesh, size_t instance_count)
|
|||||||
|
|
||||||
MeshShader::InstancedShadowShader::setUniforms();
|
MeshShader::InstancedShadowShader::setUniforms();
|
||||||
|
|
||||||
assert(mesh.vao_shadow_pass);
|
|
||||||
glBindVertexArray(mesh.vao_shadow_pass);
|
glBindVertexArray(mesh.vao_shadow_pass);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count);
|
||||||
}
|
}
|
||||||
@ -228,7 +172,7 @@ static void drawFSPMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
|
|||||||
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||||
MeshShader::InstancedObjectRefPass1Shader::setUniforms(0);
|
MeshShader::InstancedObjectRefPass1Shader::setUniforms(0);
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_first_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +187,8 @@ static void drawShadowAlphaRefTexture(GLMesh &mesh, size_t instance_count)
|
|||||||
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||||
MeshShader::InstancedRefShadowShader::setUniforms(0);
|
MeshShader::InstancedRefShadowShader::setUniforms(0);
|
||||||
|
|
||||||
assert(mesh.vao_shadow_pass);
|
|
||||||
glBindVertexArray(mesh.vao_shadow_pass);
|
glBindVertexArray(mesh.vao_shadow_pass);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count)
|
static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count)
|
||||||
@ -259,7 +202,7 @@ static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t i
|
|||||||
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||||
MeshShader::InstancedGrassPass1Shader::setUniforms(windDir, 0);
|
MeshShader::InstancedGrassPass1Shader::setUniforms(windDir, 0);
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_first_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +227,7 @@ static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjection
|
|||||||
|
|
||||||
MeshShader::InstancedObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
|
MeshShader::InstancedObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_second_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +253,7 @@ static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewPr
|
|||||||
|
|
||||||
MeshShader::InstancedObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
|
MeshShader::InstancedObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_second_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +281,7 @@ static void drawSMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMa
|
|||||||
|
|
||||||
MeshShader::InstancedGrassPass2Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), irr_driver->getInvProjMatrix(), windDir, cb->getPosition());
|
MeshShader::InstancedGrassPass2Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), irr_driver->getInvProjMatrix(), windDir, cb->getPosition());
|
||||||
|
|
||||||
glBindVertexArray(mesh.vao_second_pass);
|
glBindVertexArray(mesh.vao);
|
||||||
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,12 +43,6 @@ enum TransparentMaterial
|
|||||||
|
|
||||||
struct GLMesh {
|
struct GLMesh {
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
GLuint vao_first_pass;
|
|
||||||
GLuint vao_second_pass;
|
|
||||||
GLuint vao_glow_pass;
|
|
||||||
GLuint vao_displace_pass;
|
|
||||||
GLuint vao_displace_mask_pass;
|
|
||||||
GLuint vao_rsm_pass;
|
|
||||||
GLuint vao_shadow_pass;
|
GLuint vao_shadow_pass;
|
||||||
GLuint vertex_buffer;
|
GLuint vertex_buffer;
|
||||||
GLuint index_buffer;
|
GLuint index_buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user