code cleanup
This commit is contained in:
parent
2e4bbb6443
commit
2cc420e957
@ -101,19 +101,6 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
|
||||
}
|
||||
|
||||
void loadModelToContext2(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
Assimp::Importer import;
|
||||
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FindInvalidData);
|
||||
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
context.initFromAssimpMesh2(scene->mMeshes[0]);
|
||||
}
|
||||
namespace Plant
|
||||
{
|
||||
|
||||
@ -132,15 +119,10 @@ namespace Plant
|
||||
|
||||
this->pos = glm::vec3(1, 0, 0);
|
||||
this->material = material;
|
||||
//this->pos = glm::vec3((rand() % 100) / 100, (rand() % 100) / 100, (rand() % 100) / 100);
|
||||
}
|
||||
|
||||
|
||||
float calcProbability(float xValue, float mean, float sd)
|
||||
{
|
||||
float temp = (xValue - mean) / sd * sqrt(2);
|
||||
return (1 + erf(temp)) / 2;
|
||||
}
|
||||
float calcProbability2(float xValue, float mean, float sd)
|
||||
{
|
||||
float n = sd * 2 * sqrt(3.14); //normalization factor
|
||||
float p = exp(-pow(xValue - mean, 2) / (2 * pow(sd, 2))); // unnormalized pdf
|
||||
@ -209,9 +191,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
|
||||
int j = 0;
|
||||
std::cout << "Plant Probabilities:" << std::endl;
|
||||
for (auto& plant : plants) {
|
||||
|
||||
//TODO: add humidity calculations
|
||||
probability = plant.calcProbability2(planet.humidity, plant.humMean, plant.humSD) * plant.calcProbability2(planet.temperature, plant.tempMean, plant.tempSD);
|
||||
probability = plant.calcProbability(planet.humidity, plant.humMean, plant.humSD) * plant.calcProbability(planet.temperature, plant.tempMean, plant.tempSD);
|
||||
std::cout << probability << std::endl;
|
||||
probability = int(probability * PRECISION);
|
||||
std::tuple<int, int>probIdPair = std::make_tuple(j, probability);
|
||||
@ -272,7 +252,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
|
||||
|
||||
|
||||
}
|
||||
PlanetParams populatePlanet2(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
PlanetParams populatePlanetInstancingDemo(PlanetParams planet, std::vector<Plant::Plant> plants)
|
||||
{
|
||||
|
||||
int HOW_MANY_PLANTS = 1000;
|
||||
@ -389,13 +369,11 @@ void DrawContextInstanced(Core::RenderContext& context, std::vector<glm::mat4> t
|
||||
}
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
//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.9);
|
||||
@ -428,21 +406,7 @@ struct ModelContext {
|
||||
|
||||
|
||||
float aspectRatio = 1.f;
|
||||
bool DoTheImportThing(const std::string& pFile) {
|
||||
// Create an instance of the Importer class
|
||||
Assimp::Importer importer;
|
||||
|
||||
// And have it read the given file with some example postprocessing
|
||||
// Usually - if speed is not the most important aspect for you - you'll
|
||||
// probably to request more postprocessing than we do in this example.
|
||||
const aiScene* scene = importer.ReadFile(pFile,
|
||||
aiProcess_CalcTangentSpace |
|
||||
aiProcess_Triangulate |
|
||||
aiProcess_JoinIdenticalVertices |
|
||||
aiProcess_SortByPType);
|
||||
return scene;
|
||||
|
||||
}
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
@ -482,7 +446,7 @@ void renderImGui() {
|
||||
}
|
||||
if (ImGui::Button("Instancing")) {
|
||||
planets.clear();
|
||||
newPlanetParams = populatePlanet2(newPlanetParams, plant_specimens);
|
||||
newPlanetParams = populatePlanetInstancingDemo(newPlanetParams, plant_specimens);
|
||||
planets.push_back(newPlanetParams);
|
||||
newPlanetParams.Plant_info.clear();
|
||||
newPlanetParams.Plant_type_count.clear();
|
||||
@ -646,7 +610,6 @@ void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::v
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(prog, "color"), color.x, color.y, color.z);
|
||||
//glUniform3f(glGetUniformLocation(prog, "lightPos"), 0,0,0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
|
||||
|
||||
@ -679,20 +642,7 @@ void renderSun() {
|
||||
}
|
||||
|
||||
|
||||
void drawObjectBiomes(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint program) {
|
||||
GLuint prog = program;
|
||||
glUseProgram(prog);
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(prog, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z);
|
||||
|
||||
Core::DrawContext(context);
|
||||
glUseProgram(0);
|
||||
|
||||
}
|
||||
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program) {
|
||||
program;
|
||||
glUseProgram(program);
|
||||
@ -722,7 +672,6 @@ void drawObjectTexture_plant(Core::RenderContext& context, glm::mat4 modelMatrix
|
||||
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);
|
||||
@ -739,18 +688,6 @@ 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);
|
||||
|
||||
DrawContextInstanced(context, transformations, modelMatrices, count, material, program);
|
||||
glUseProgram(0);
|
||||
}
|
||||
@ -879,27 +816,12 @@ void renderScene(GLFWwindow* window)
|
||||
float firstTreeDuration = 20.0f;
|
||||
float secondTreeDuration = 8.0f;
|
||||
float thirdTreeDuration = 5.0f;
|
||||
//static float elapsedTime = 0.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);
|
||||
float scaleFactor = 0.025f;
|
||||
glm::mat4 plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor));
|
||||
//for (int i = 0; i < 5; i++) {
|
||||
// placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 1.f)), sphereContext, planetMatrix);
|
||||
// placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||
// placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||
// placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix);
|
||||
// placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix);
|
||||
//}
|
||||
|
||||
//placeObjectOnPlanet(plantContext ,glm::scale(glm::mat4(),glm::vec3(0.2)), normalize(glm::vec3(1.f,0.f,1.f)), sphereContext, planetMatrix);
|
||||
//placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.f, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||
|
||||
//drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(60.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||
//drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(90.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||
//drawObjectBiomes(plantContext, glm::eulerAngleX(30.f) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||
for (const auto& planet : planets) {
|
||||
glm::mat4 modelMatrix = glm::translate(planet.position) * glm::scale(glm::vec3(planet.size));
|
||||
drawObjectTexture(sphereContext, modelMatrix, planet.texture, programTex);
|
||||
@ -928,43 +850,17 @@ void renderScene(GLFWwindow* window)
|
||||
{
|
||||
current_type_plant_positions.push_back(std::get<1>(plant));
|
||||
}
|
||||
for (int i = 0; i < types_count; i++)
|
||||
{
|
||||
|
||||
//placeObjectOnPlanet(plant_specimens[std::get<0>(plant)].modelContext, glm::mat4(), 0.2, std::get<1>(plant), planet, plant_type_count);
|
||||
|
||||
}
|
||||
//for (const auto& plant : plants)
|
||||
//TODO: REMOVE PLACEHOLDER
|
||||
|
||||
//animateGrowingTree(elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plant.pos, scaleFactor, plant_2_1_small_Context, plant_2_1_med_Context, plant_2_1Context, plantModelMatrix, plant2_1Material, program_pbr);
|
||||
|
||||
}
|
||||
skyPos = cameraPos;
|
||||
glm::mat4 skyMatrix = glm::scale(glm::vec3(skySize));
|
||||
glm::mat4 skyTranslate = glm::translate(skyPos);
|
||||
drawSky(cubeContext, skyTranslate * skyMatrix, texture::background);
|
||||
|
||||
//placeObjectOnPlanet(plant2Context, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(1.0, 0.0, 1.0)), sphereContext, planetMatrix);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
applyBloom();
|
||||
renderSun();
|
||||
|
||||
|
||||
//drawObjectColor(plant2Context, plantModelMatrix, glm::vec3(1,1,1), program);
|
||||
// drawObjectColor(plant3Context,glm::translate(glm::vec3(1.0f, 0.5f, 3.0f)) *glm::scale(glm::vec3(0.03f)) *glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),glm::vec3(1, 1, 1), program);
|
||||
//drawObjectTexture_plant(plant_1_1_small_Context, plantModelMatrix, plant3Material, program_pbr);
|
||||
//drawObjectTexture_plant(plant_2_1_small_Context, plantModelMatrix, plant2_1Material, program_pbr);
|
||||
|
||||
//drawObjectColor(plant2Context, plantModelMatrix, glm::vec3(1, 1, 1), program);
|
||||
|
||||
|
||||
//animateGrowingTree(elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plantPosition, scaleFactor, plant_1_1_small_Context, plant_1_1_med_Context, plant_1_1Context, plantModelMatrix, plant3Material, program_pbr);
|
||||
|
||||
//animateGrowingTree(elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plantPosition1, scaleFactor, plant_2_1_small_Context, plant_2_1_med_Context, plant_2_1Context, plantModelMatrix, plant2_1Material, program_pbr);
|
||||
|
||||
//animateGrowingTree(elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plantPosition2, scaleFactor, plant_2_1_small_Context, plant_2_1_med_Context, plant_2_1Context, plantModelMatrix, plant2_1Material, program_pbr);
|
||||
|
||||
renderImGui();
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
@ -976,7 +872,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
}
|
||||
//TODO :REMOVE THIS
|
||||
|
||||
|
||||
|
||||
@ -999,24 +894,14 @@ void init(GLFWwindow* window)
|
||||
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
|
||||
programBiomes = shaderLoader.CreateProgram("shaders/shader_biomes.vert", "shaders/shader_biomes.frag");
|
||||
program_pbr = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
||||
program_pbr_instanced = shaderLoader.CreateProgram("shaders/shader_pbr_instanced.vert", "shaders/shader_pbr_instanced.frag");
|
||||
program_sky = shaderLoader.CreateProgram("shaders/shader_sky.vert", "shaders/shader_sky.frag");
|
||||
program_blur = shaderLoader.CreateProgram("shaders/blur.vert", "shaders/blur.frag");
|
||||
program_bloom_final = shaderLoader.CreateProgram("shaders/bloom_final.vert", "shaders/bloom_final.frag");
|
||||
loadModelToContext2("./models/plants/polygon.obj", plantContext);
|
||||
|
||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
//plant 1-1
|
||||
loadModelToContext("./models/plant_1_1_zmn.obj", plant_1_1Context);
|
||||
loadModelToContext("./models/plant_1_1_med_zmn.obj", plant_1_1_med_Context);
|
||||
loadModelToContext("./models/plant_1_1_small_zmn.obj", plant_1_1_small_Context);
|
||||
//plant 2-2
|
||||
loadModelToContext("./models/plant_2_1_small.obj", plant_2_1_small_Context);
|
||||
loadModelToContext("./models/plant_2_1_med.obj", plant_2_1_med_Context);
|
||||
loadModelToContext("./models/plant_2_1.obj", plant_2_1Context);
|
||||
loadModelToContext2("./models/plant_4.ply", plant3Context);
|
||||
|
||||
|
||||
// setupBuffers(plantContex_test);
|
||||
texture::earth = Core::LoadTexture("textures/earth2.png");
|
||||
@ -1031,9 +916,8 @@ void init(GLFWwindow* window)
|
||||
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
|
||||
loadModelToContext("./models/cube.obj", cubeContext);
|
||||
texture::background = Core::LoadCubeMap("./textures/skyCut.jpg");
|
||||
plant_specimens.push_back(Plant::Plant(7, 5, 7, 5, "plant1_s", "./models/plant_1_1.obj", plant3Material));
|
||||
plant_specimens.push_back(Plant::Plant(5, 5, 5, 5, "plant1_m", "./models/plant_2_1.obj", plant2_1Material));
|
||||
|
||||
plant_specimens.push_back(Plant::Plant(40, 5, 40, 5, "drzewo_lisciaste", "./models/plant_1_1.obj", plant3Material));
|
||||
plant_specimens.push_back(Plant::Plant(25, 5, 25, 5, "drzewo_iglaste", "./models/plant_2_1.obj", plant2_1Material));
|
||||
|
||||
defaultTexture = Core::LoadTexture("textures/1.png");
|
||||
if (defaultTexture == 0) {
|
||||
@ -1084,17 +968,7 @@ void processInput(GLFWwindow* window)
|
||||
}
|
||||
|
||||
|
||||
//// funkcja jest glowna petla
|
||||
//void renderLoop(GLFWwindow* window) {
|
||||
// while (!glfwWindowShouldClose(window))
|
||||
// {
|
||||
// processInput(window);
|
||||
//
|
||||
// renderScene(window);
|
||||
// glfwPollEvents();
|
||||
// }
|
||||
//}
|
||||
////}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user