Compare commits

..

No commits in common. "31d2af576d2c4b684aa6b42aa0e026b9c4d2ae10" and "5b34df6782bb3d125ed91a6097277149bf1124c1" have entirely different histories.

View File

@ -336,17 +336,21 @@ glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
glm::vec3 sunPosition = glm::vec3(0.0f, 10.0f, 10.0f); // Позиция солнца
glm::vec3 sunColor = glm::vec3(1.0f, 1.0f, 1.0f); // Цвет солнца
glm::vec3 skyPos = glm::vec3(0.f, 0.f, 0.f);
bool refresh = true;
float skySize = 4.f;
float currentTime = 0.0;
GLuint VAO, VBO, matricesBuffer;
GLuint VAO, VBO;
glm::mat4 planetMatrix = glm::mat4();
void DrawContextInstancedSetup(Core::RenderContext& context, std::vector<glm::mat4> transformations, std::vector<glm::mat4> Modelmatrices, int numberOfInstances, Material material, GLuint program, bool refresh)
{ VAO = context.vertexArray;
void DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> transformations, std::vector<glm::mat4> Modelmatrices, int numberOfInstances, Material material, GLuint program)
{
GLuint VAO = context.vertexArray;
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, transformations.size() * sizeof(glm::mat4), transformations.data(), GL_STATIC_DRAW);
std::size_t mat4Size = sizeof(glm::mat4);
for (int i = 0; i < 4; i++) {
@ -354,6 +358,7 @@ void DrawContextInstancedSetup(Core::RenderContext& context, std::vector<glm::ma
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);
@ -362,16 +367,6 @@ void DrawContextInstancedSetup(Core::RenderContext& context, std::vector<glm::ma
glVertexAttribPointer(10 + i, 4, GL_FLOAT, GL_FALSE, mat4Size, (void*)(sizeof(glm::vec4) * i));
glVertexAttribDivisor(10 + i, 1);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> transformations, std::vector<glm::mat4> Modelmatrices, int numberOfInstances, Material material, GLuint program,bool refresh)
{
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindBuffer(GL_ARRAY_BUFFER, matricesBuffer);
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
glUniform1f(glGetUniformLocation(program, "shininess"), material.Ns);
@ -382,6 +377,7 @@ void DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> t
glUniform1i(glGetUniformLocation(program, "illuminationModel"), material.illum);
glUniform1f(glGetUniformLocation(program, "metallic"), 0.05);
glUniform1f(glGetUniformLocation(program, "roughness"), 0.9);
glDrawElementsInstanced(
GL_TRIANGLES, // mode
context.size, // count
@ -390,6 +386,7 @@ void DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> t
);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
@ -453,7 +450,6 @@ void renderImGui() {
planets.push_back(newPlanetParams);
newPlanetParams.Plant_info.clear();
newPlanetParams.Plant_type_count.clear();
refresh = true;
}
ImGui::End();
@ -682,7 +678,7 @@ void drawObjectTexture_plant(Core::RenderContext& context, glm::mat4 modelMatrix
Core::DrawContext(context);
glUseProgram(0);
}
void drawObjectTexture_plantInstanced(Core::RenderContext& context, std::vector<glm::mat4> modelMatrices, Material& material, GLuint program, int count,bool refresh) {
void drawObjectTexture_plantInstanced(Core::RenderContext& context, std::vector<glm::mat4> modelMatrices, Material& material, GLuint program, int count) {
glUseProgram(program);
Core::SetActiveTexture(material.textureID, "colorTexture", program, 0);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -692,11 +688,10 @@ void drawObjectTexture_plantInstanced(Core::RenderContext& context, std::vector<
glm::mat4 transformation = viewProjectionMatrix * matrix;
transformations.push_back(transformation);
}
DrawContextInstancedSetup(context, transformations, modelMatrices, count, material, program, refresh);
DrawContextInstanced(context, transformations, modelMatrices, count, material, program,refresh);
DrawContextInstanced(context, transformations, modelMatrices, count, material, program);
glUseProgram(0);
}
void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix, float scale, std::vector<glm::vec3>placePoints, PlanetParams planetParams, int count, Material material,bool refresh) {
void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix, float scale, std::vector<glm::vec3>placePoints, PlanetParams planetParams, int count, Material material) {
float planetScale = planetParams.size;
glm::mat4 savedobjectMatrix;
@ -715,13 +710,14 @@ void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMat
axis = glm::cross(normalized_placePoint, base);
angle = dot(base, normalized_placePoint);
angle = acos(angle);
objectMatrix = objectMatrix * glm::translate(planetParams.position * (1 / scale)) * glm::rotate(objectMatrix, angle, axis) * glm::translate(base * diameter);
//objectMatrix = objectMatrix * glm::translate(planetParams.position * (1 / scale));
objectMatrix = objectMatrix * glm::rotate(objectMatrix, angle, axis) * glm::translate(base * diameter);
objectMatrix = objectMatrix * glm::translate(planetParams.position * (1 / scale));
matrices.push_back(objectMatrix);
}
drawObjectTexture_plantInstanced(objectContext, matrices, material, program_pbr_instanced, count,refresh);
drawObjectTexture_plantInstanced(objectContext, matrices, material, program_pbr_instanced, count);
@ -811,22 +807,21 @@ void renderScene(GLFWwindow* window)
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::mat4 transformation;
/*float currentTime = glfwGetTime();
float time = glfwGetTime();
static double lastFrameTime = 0.0;
float deltaTime = static_cast<float>(currentTime - lastFrameTime);
lastFrameTime = currentTime;
float deltaTime = static_cast<float>(time - lastFrameTime);
lastFrameTime = time;
float firstTreeDuration = 20.0f;
float secondTreeDuration = 8.0f;
float thirdTreeDuration = 5.0f;*/
float thirdTreeDuration = 5.0f;
glm::vec3 plantPosition = glm::vec3(1.f, 0.f, 3.5f);
glm::vec3 plantPosition1 = glm::vec3(1.f, 0.f, 1.5f);
glm::vec3 plantPosition2 = glm::vec3(1.f, 0.f, 0.5f);
glm::vec3 plantPosition3 = glm::vec3(1.f, 0.f, -0.5f);
renderSun();
//float scaleFactor = 0.025f;
//glm::mat4 plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor));
float scaleFactor = 0.025f;
glm::mat4 plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor));
for (const auto& planet : planets) {
glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size));
drawObjectTexture(sphereContext, modelMatrix, planet.texture, programTex);
@ -846,7 +841,7 @@ void renderScene(GLFWwindow* window)
current_type_plant_positions.push_back(std::get<1>(plants[iterator]));
iterator += 1;
}
placeObjectOnPlanet(plant_specimens[i].modelContext, glm::mat4(), 0.2, current_type_plant_positions, planet, plant_type_count, plant_specimens[0].material,refresh);
placeObjectOnPlanet(plant_specimens[i].modelContext, glm::mat4(), 0.2, current_type_plant_positions, planet, plant_type_count, plant_specimens[0].material);
}
current_type_plant_positions.clear();
@ -868,7 +863,6 @@ void renderScene(GLFWwindow* window)
renderImGui();
glfwSwapBuffers(window);
refresh = false;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{