instancing but scale is messed up
This commit is contained in:
parent
3f757feb4a
commit
ac6a01d5be
@ -214,22 +214,58 @@ void Core::DrawContext(Core::RenderContext& context)
|
||||
|
||||
|
||||
|
||||
void Core::DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> transformations,std::vector<glm::mat4> Modelmatrices,int numberOfInstances, GLuint program)
|
||||
void Core::DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> transformations, std::vector<glm::mat4> Modelmatrices, int numberOfInstances,GLuint program)
|
||||
{
|
||||
|
||||
|
||||
GLuint VAO = context.vertexArray;
|
||||
glBindVertexArray(VAO);
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, transformations.size() * sizeof(glm::mat4), transformations.data(), GL_STATIC_DRAW);
|
||||
GLuint VAO = context.vertexArray;
|
||||
glBindVertexArray(VAO);
|
||||
std::size_t mat4Size = sizeof(glm::mat4);
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, mat4Size, (void*)0);
|
||||
glVertexAttribDivisor(6, 1);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
glEnableVertexAttribArray(6+i);
|
||||
glVertexAttribPointer(6 + i, 4, GL_FLOAT, GL_FALSE, mat4Size, (void*)(sizeof(glm::vec4) * i));
|
||||
glVertexAttribDivisor(6 + i, 1);
|
||||
}
|
||||
GLuint matricesBuffer;
|
||||
glGenBuffers(1, &matricesBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, matricesBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, Modelmatrices.size() * sizeof(glm::mat4), Modelmatrices.data(), GL_STATIC_DRAW);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
glEnableVertexAttribArray(10 + i);
|
||||
glVertexAttribPointer(10 + i, 4, GL_FLOAT, GL_FALSE, mat4Size, (void*)(sizeof(glm::vec4) * i));
|
||||
glVertexAttribDivisor(10 + i, 1);
|
||||
}
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
|
||||
//Material
|
||||
glUniform1f(glGetUniformLocation(program, "shininess"), 0);
|
||||
glUniform3f(glGetUniformLocation(program, "ambientColor"), 0, 0,0 );
|
||||
glUniform3f(glGetUniformLocation(program, "specularColor"), 0,0 , 0);
|
||||
glUniform3f(glGetUniformLocation(program, "emissiveColor"), 0,0 ,0 );
|
||||
glUniform1f(glGetUniformLocation(program, "opticalDensity"),0 );
|
||||
//glUniform1f(glGetUniformLocation(program, "dissolve"), material.d);
|
||||
glUniform1i(glGetUniformLocation(program, "illuminationModel"), 0);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), 0.05);
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), 0.2);
|
||||
|
||||
/* std::size_t vec4Size = sizeof(glm::vec4);
|
||||
glDrawElementsInstanced(
|
||||
GL_TRIANGLES, // mode
|
||||
context.size, // count
|
||||
GL_UNSIGNED_INT, // type
|
||||
(void*)0, numberOfInstances // element array buffer offset
|
||||
);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
|
||||
/* std::size_t vec4Size = sizeof(glm::vec4);
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 4 * vec4Size, (void*)0);*
|
||||
glEnableVertexAttribArray(4);
|
||||
@ -250,16 +286,4 @@ void Core::DrawContextInstanced(Core::RenderContext& context, std::vector<glm::m
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
//glVertexAttribPointer(modelMatrixLocation, 3, GL_FLOAT, GL_FALSE,sizeof(glm::mat4), (void*)0);
|
||||
//glVertexAttribDivisor(modelMatrixLocation, 1);
|
||||
//glBindVertexArray(context.vertexArray);
|
||||
glDrawElementsInstanced(
|
||||
GL_TRIANGLES, // mode
|
||||
context.size, // count
|
||||
GL_UNSIGNED_INT, // type
|
||||
(void*)0, numberOfInstances // element array buffer offset
|
||||
);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
//glBindVertexArray(context.vertexArray);
|
@ -155,7 +155,7 @@ bool sortFunction(std::tuple<int, float> objA, std::tuple<int, float> objB)
|
||||
PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
{
|
||||
float probability=0.5f;
|
||||
int HOW_MANY_PLANTS = 10000;
|
||||
int HOW_MANY_PLANTS = 100;
|
||||
int PRECISION = 10000;
|
||||
float NOTHING_SPAWNS_CUTOFF = 0.0;
|
||||
int sum = 0;
|
||||
@ -320,7 +320,7 @@ glm::mat4 createPerspectiveMatrix()
|
||||
|
||||
glm::mat4 perspectiveMatrix;
|
||||
float n = 0.05;
|
||||
float f = 15.;
|
||||
float f = 100.;
|
||||
float a1 = glm::min(aspectRatio, 1.f);
|
||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
||||
perspectiveMatrix = glm::mat4({
|
||||
@ -417,18 +417,17 @@ void drawObjectTexture_plantInstanced(Core::RenderContext& context, std::vector<
|
||||
glm::mat4 transformation = viewProjectionMatrix* matrix;
|
||||
transformations.push_back(transformation);
|
||||
}
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
|
||||
//Material
|
||||
glUniform1f(glGetUniformLocation(program, "shininess"), material.Ns);
|
||||
glUniform3f(glGetUniformLocation(program, "ambientColor"), material.Ka.r, material.Ka.g, material.Ka.b);
|
||||
glUniform3f(glGetUniformLocation(program, "specularColor"), material.Ks.r, material.Ks.g, material.Ks.b);
|
||||
glUniform3f(glGetUniformLocation(program, "emissiveColor"), material.Ke.r, material.Ke.g, material.Ke.b);
|
||||
glUniform1f(glGetUniformLocation(program, "opticalDensity"), material.Ni);
|
||||
//glUniform1f(glGetUniformLocation(program, "dissolve"), material.d);
|
||||
glUniform1i(glGetUniformLocation(program, "illuminationModel"), material.illum);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), 0.05);
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), 0.2);
|
||||
//glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
|
||||
////Material
|
||||
//glUniform1f(glGetUniformLocation(program, "shininess"), material.Ns);
|
||||
//glUniform3f(glGetUniformLocation(program, "ambientColor"), material.Ka.r, material.Ka.g, material.Ka.b);
|
||||
//glUniform3f(glGetUniformLocation(program, "specularColor"), material.Ks.r, material.Ks.g, material.Ks.b);
|
||||
//glUniform3f(glGetUniformLocation(program, "emissiveColor"), material.Ke.r, material.Ke.g, material.Ke.b);
|
||||
//glUniform1f(glGetUniformLocation(program, "opticalDensity"), material.Ni);
|
||||
////glUniform1f(glGetUniformLocation(program, "dissolve"), material.d);
|
||||
//glUniform1i(glGetUniformLocation(program, "illuminationModel"), material.illum);
|
||||
//glUniform1f(glGetUniformLocation(program, "metallic"), 0.05);
|
||||
//glUniform1f(glGetUniformLocation(program, "roughness"), 0.2);
|
||||
|
||||
Core::DrawContextInstanced(context, transformations,modelMatrices,count,program);
|
||||
glUseProgram(0);
|
||||
|
Loading…
Reference in New Issue
Block a user