diff --git a/PlanetCreator/Release/grk-cw6.exe b/PlanetCreator/Release/grk-cw6.exe index 4d3a9c5..51a0a67 100644 Binary files a/PlanetCreator/Release/grk-cw6.exe and b/PlanetCreator/Release/grk-cw6.exe differ diff --git a/PlanetCreator/Release/grk-cw6.pdb b/PlanetCreator/Release/grk-cw6.pdb index 0324c7d..6162ce9 100644 Binary files a/PlanetCreator/Release/grk-cw6.pdb and b/PlanetCreator/Release/grk-cw6.pdb differ diff --git a/PlanetCreator/cw 6/Release/Distribution.obj b/PlanetCreator/cw 6/Release/Distribution.obj index a69bedc..5b3ff5d 100644 Binary files a/PlanetCreator/cw 6/Release/Distribution.obj and b/PlanetCreator/cw 6/Release/Distribution.obj differ diff --git a/PlanetCreator/cw 6/Release/Render_Utils.obj b/PlanetCreator/cw 6/Release/Render_Utils.obj index 7656e43..429fe09 100644 Binary files a/PlanetCreator/cw 6/Release/Render_Utils.obj and b/PlanetCreator/cw 6/Release/Render_Utils.obj differ diff --git a/PlanetCreator/cw 6/Release/grk-cw6.iobj b/PlanetCreator/cw 6/Release/grk-cw6.iobj index e40fbbd..17525a3 100644 Binary files a/PlanetCreator/cw 6/Release/grk-cw6.iobj and b/PlanetCreator/cw 6/Release/grk-cw6.iobj differ diff --git a/PlanetCreator/cw 6/Release/grk-cw6.ipdb b/PlanetCreator/cw 6/Release/grk-cw6.ipdb index 7e6cebc..75563ee 100644 Binary files a/PlanetCreator/cw 6/Release/grk-cw6.ipdb and b/PlanetCreator/cw 6/Release/grk-cw6.ipdb differ diff --git a/PlanetCreator/cw 6/Release/grk-cw6.log b/PlanetCreator/cw 6/Release/grk-cw6.log index f00249a..51c43b6 100644 --- a/PlanetCreator/cw 6/Release/grk-cw6.log +++ b/PlanetCreator/cw 6/Release/grk-cw6.log @@ -5,17 +5,20 @@ C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(136,15): warning C4 C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(157,23): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(205,30): warning C4244: =: преобразование "float" в "int", возможна потеря данных C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(211,20): warning C4244: =: преобразование "int" в "float", возможна потеря данных -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(390,16): warning C4305: инициализация: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(494,61): warning C4305: аргумент: усечение из "double" в "GLfloat" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(495,61): warning C4305: аргумент: усечение из "double" в "GLfloat" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(509,17): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(629,13): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(773,90): warning C4305: аргумент: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(774,94): warning C4305: аргумент: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(775,98): warning C4305: аргумент: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(776,100): warning C4305: аргумент: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(779,104): warning C4305: аргумент: усечение из "double" в "float" -C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(780,94): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(365,61): warning C4305: аргумент: усечение из "double" в "GLfloat" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(366,61): warning C4305: аргумент: усечение из "double" в "GLfloat" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(441,16): warning C4305: инициализация: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(545,61): warning C4305: аргумент: усечение из "double" в "GLfloat" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(546,61): warning C4305: аргумент: усечение из "double" в "GLfloat" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(595,30): warning C4305: инициализация: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(644,17): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(759,13): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(906,90): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(907,94): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(908,98): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(909,100): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(912,104): warning C4305: аргумент: усечение из "double" в "float" +C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(913,94): warning C4305: аргумент: усечение из "double" в "float" C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\tuple(158,47): warning C4244: инициализация: преобразование "_Ty" в "_Ty", возможна потеря данных with [ @@ -183,8 +186,8 @@ C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(220): message : в _Pr=bool (__cdecl *)(std::tuple,std::tuple) ] Создание кода - 2 of 2535 functions (<0.1%) were compiled, the rest were copied from previous compilation. + 46 of 2621 functions ( 1.8%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation - 23 functions had inline decision re-evaluated but remain unchanged + 28 functions had inline decision re-evaluated but remain unchanged Создание кода завершено grk-cw6.vcxproj -> C:\Users\neryt\Grafika2023\PlanetCreator\Release\grk-cw6.exe diff --git a/PlanetCreator/cw 6/Release/grk-cw6.tlog/link.read.1.tlog b/PlanetCreator/cw 6/Release/grk-cw6.tlog/link.read.1.tlog index a637f30..239a9b4 100644 Binary files a/PlanetCreator/cw 6/Release/grk-cw6.tlog/link.read.1.tlog and b/PlanetCreator/cw 6/Release/grk-cw6.tlog/link.read.1.tlog differ diff --git a/PlanetCreator/cw 6/Release/main.obj b/PlanetCreator/cw 6/Release/main.obj index b3f4e9f..ab2220e 100644 Binary files a/PlanetCreator/cw 6/Release/main.obj and b/PlanetCreator/cw 6/Release/main.obj differ diff --git a/PlanetCreator/cw 6/Release/vc142.pdb b/PlanetCreator/cw 6/Release/vc142.pdb index 46403ce..91c3ed1 100644 Binary files a/PlanetCreator/cw 6/Release/vc142.pdb and b/PlanetCreator/cw 6/Release/vc142.pdb differ diff --git a/PlanetCreator/cw 6/grk-cw6.vcxproj b/PlanetCreator/cw 6/grk-cw6.vcxproj index d8b365a..1fa2dac 100644 --- a/PlanetCreator/cw 6/grk-cw6.vcxproj +++ b/PlanetCreator/cw 6/grk-cw6.vcxproj @@ -71,6 +71,8 @@ + + {3952C396-B1C6-44CD-96DD-C1AC15D32978} diff --git a/PlanetCreator/cw 6/grk-cw6.vcxproj.filters b/PlanetCreator/cw 6/grk-cw6.vcxproj.filters index 27330b1..2352b7e 100644 --- a/PlanetCreator/cw 6/grk-cw6.vcxproj.filters +++ b/PlanetCreator/cw 6/grk-cw6.vcxproj.filters @@ -72,6 +72,9 @@ Source Files + + Source Files + @@ -107,9 +110,6 @@ Source Files\SOIL - - Source Files - Header Files @@ -137,6 +137,15 @@ Header Files + + Header Files + + + Header Files + + + Shader Files + @@ -170,5 +179,11 @@ Shader Files + + Shader Files + + + Shader Files + \ No newline at end of file diff --git a/PlanetCreator/cw 6/shaders/shader_pbr_instanced.frag b/PlanetCreator/cw 6/shaders/shader_pbr_instanced.frag new file mode 100644 index 0000000..9f2a55b --- /dev/null +++ b/PlanetCreator/cw 6/shaders/shader_pbr_instanced.frag @@ -0,0 +1,72 @@ +#version 430 core +#define PI 3.14159265359 + +float AMBIENT = 0.1; + +uniform vec3 albedo; +uniform float metallic; +uniform float roughness; +uniform vec3 color; +uniform vec3 lightPos; +uniform vec3 viewPos; +uniform vec3 ambientColor; +uniform sampler2D colorTexture; + +in vec3 fragNormal; +in vec3 fragPosition; +in vec2 texCoords; + +out vec4 outColor; + +float specularD(float NdotH, float roughness) +{ + float alpha = roughness * roughness; + float alpha2 = alpha * alpha; + float cos2ThetaH = NdotH * NdotH; + + float expTerm = (cos2ThetaH - 1.0) / (alpha2 * cos2ThetaH); + return exp(expTerm) / (PI * alpha2 * pow(cos2ThetaH + alpha2 - 1.0, 2.0)); +} + +vec3 specularF(float LdotH, vec3 F0) +{ + return F0 + (vec3(1.0) - F0) * pow(1.0 - LdotH, 5.0); +} + +float specularG(float NdotL, float NdotV, float roughness) +{ + float k = (roughness + 1.0) * (roughness + 1.0) / 8.0; + + float GL = NdotL / (NdotL * (1.0 - k) + k); + float GV = NdotV / (NdotV * (1.0 - k) + k); + + return GL * GV; +} + +void main() +{ + vec3 normal = normalize(fragNormal); + vec3 viewDir = normalize(viewPos - fragPosition); + vec3 lightDir = normalize(lightPos - fragPosition); + + vec3 F0 = vec3(0.04); + F0 = mix(F0, albedo, metallic); + + float NdotL = max(dot(normal, lightDir), 0.0); + float NdotV = max(dot(normal, viewDir), 0.0); + + vec3 H = normalize(lightDir + viewDir); + float NdotH = max(dot(normal, H), 0.0); + float LdotH = max(dot(lightDir, H), 0.0); + vec3 albedo = texture(colorTexture, texCoords).rgb; + albedo *= 2.0; + vec3 specular = F0 * (specularD(NdotH, roughness) * specularF(LdotH, F0) * specularG(NdotL, NdotV, roughness)) / (4.0 * NdotL * NdotV); + + vec3 diffuse = (1.0 - F0) * albedo / PI; + + vec3 ambient = ambientColor * AMBIENT; + + vec3 finalColor = ambient + (diffuse + specular) * NdotL; + + outColor = vec4(finalColor, 1.0); +} diff --git a/PlanetCreator/cw 6/shaders/shader_pbr_instanced.vert b/PlanetCreator/cw 6/shaders/shader_pbr_instanced.vert new file mode 100644 index 0000000..6e29fbd --- /dev/null +++ b/PlanetCreator/cw 6/shaders/shader_pbr_instanced.vert @@ -0,0 +1,20 @@ +#version 430 core + +layout(location = 0) in vec3 inPosition; +layout(location = 1) in vec3 inNormal; +layout(location = 2) in vec2 inTexCoord; +layout(location = 6) in mat4 transformations; +layout(location = 10) in mat4 modelMatrix; + + +out vec2 texCoords; +out vec3 fragNormal; +out vec3 fragPosition; +uniform sampler2D colorTexture; +void main() +{ + gl_Position = transformations * vec4(inPosition, 1.0); + fragPosition = (modelMatrix* vec4(inPosition,1)).xyz; + texCoords = inTexCoord; + fragNormal = (modelMatrix* vec4(inNormal,0)).xyz; +} diff --git a/PlanetCreator/cw 6/src/ex_6_1.hpp b/PlanetCreator/cw 6/src/ex_6_1.hpp index ccb0ef9..fb43928 100644 --- a/PlanetCreator/cw 6/src/ex_6_1.hpp +++ b/PlanetCreator/cw 6/src/ex_6_1.hpp @@ -200,7 +200,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector plant int sum = 0; int chosen_number = 0; std::vector> probabilities; - + sum = NOTHING_SPAWNS_CUTOFF * PRECISION; int j = 0; @@ -282,6 +282,7 @@ GLuint program; GLuint programSun; GLuint programTex; GLuint program_pbr; +GLuint program_pbr_instanced; GLuint plantProgram; Core::Shader_Loader shaderLoader; @@ -326,6 +327,56 @@ struct ModelContext { GLuint EBO; }; +void DrawContextInstanced(Core::RenderContext& context, std::vector transformations, std::vector Modelmatrices, int numberOfInstances, Material material, 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); + std::size_t mat4Size = sizeof(glm::mat4); + 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"), 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); + + 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); + +} float aspectRatio = 1.f; bool DoTheImportThing(const std::string& pFile) { @@ -498,47 +549,125 @@ void drawObjectTexture_plant(Core::RenderContext &context, glm::mat4 modelMatrix glUseProgram(0); } -void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix, float scale, glm::vec3 placePoint, PlanetParams planetParams) { - float planetScale = planetParams.size; - //placePoint is described by normalized vector that points to a point on a sphere from inside of itself - placePoint = glm::normalize(placePoint); +std::vector calculatePlantMatrices(const std::vector& plantPositions, const glm::vec3& planetPosition, float planetRadius, float plantScale) { + std::vector plantMatrices; - //float diameter = ?; - glm::mat4 cobjectMatrix = objectMatrix; - cobjectMatrix = glm::scale(cobjectMatrix, glm::vec3(scale)); - float diameter = 24.4 * planetScale; - //objectMatrix = objectMatrix * glm::translate(placePoint * 0.1f); + for (const auto& plantPos : plantPositions) { + // Calculate the world position of the plant + glm::vec3 worldPlantPos = planetPosition + plantPos * planetRadius; + + // Calculate the orientation + // The up vector for the plant is the normalization of the plant's position relative to the planet's center + glm::vec3 upVector = glm::normalize(plantPos); + + // Calculate the forward vector for the plant + // This can be any vector perpendicular to the up vector, for simplicity we can use the cross product with a world up vector (e.g., glm::vec3(0, 1, 0)) + glm::vec3 worldUp = glm::vec3(0, 1, 0); + glm::vec3 forwardVector = glm::cross(worldUp, upVector); + if (glm::length(forwardVector) < 0.001f) // If the up vector and world up vector are collinear, choose a different vector for the cross product + forwardVector = glm::cross(glm::vec3(1, 0, 0), upVector); + forwardVector = glm::normalize(forwardVector); + + // Calculate the right vector + glm::vec3 rightVector = glm::cross(upVector, forwardVector); + rightVector = glm::normalize(rightVector); + + // Construct the rotation matrix from the orientation vectors + glm::mat4 rotationMatrix = glm::mat4(1.0f); + rotationMatrix[0] = glm::vec4(rightVector, 0.0f); + rotationMatrix[1] = glm::vec4(upVector, 0.0f); + rotationMatrix[2] = glm::vec4(-forwardVector, 0.0f); // OpenGL is right-handed, so we invert the forward vector + + // Construct the model matrix + glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), worldPlantPos) * rotationMatrix * glm::scale(glm::mat4(1.0f), glm::vec3(plantScale)); + + plantMatrices.push_back(modelMatrix); + } + + return plantMatrices; +} + + +void drawObjectTexture_plantInstanced(Core::RenderContext& context, Material& material, GLuint program, int count, std::vectorplacePoints, PlanetParams planetParams, glm::mat4 plantMatrix) { + glm::mat4 objectMatrix; + glm::mat4 savedobjectMatrix; + savedobjectMatrix = glm::scale(objectMatrix, glm::vec3(0.25)); + float diameter = 24.4 * 0.25; glm::vec3 base = glm::vec3(0.f, 1.f, 0.f); glm::vec3 axis; float angle; - //odpowiednio obrócić - axis = glm::cross(placePoint, base); - angle = dot(base, placePoint); - angle = acos(angle); - cobjectMatrix = cobjectMatrix * glm::rotate(cobjectMatrix, angle, axis) * glm::translate(base * diameter); - cobjectMatrix = cobjectMatrix * glm::translate(planetParams.position * (1 / scale)); - drawObjectBiomes(objectContext, cobjectMatrix, programBiomes); + glm::vec3 normalized_placePoint; + std::vector matrices; + for (const auto& placePoint : placePoints) + { + objectMatrix = savedobjectMatrix; + normalized_placePoint = glm::normalize(placePoint); + axis = glm::cross(normalized_placePoint, base); + angle = dot(base, normalized_placePoint); + angle = acos(angle); + objectMatrix = objectMatrix * glm::rotate(objectMatrix, angle, axis) * glm::translate(base * diameter); + objectMatrix = objectMatrix * glm::translate(planetParams.position * (1 / 0.25)); + matrices.push_back( plantMatrix); + } + + //std::vector matr1 = calculatePlantMatrices(placePoints, planetParams.position, (planetParams.size)/4, 0.2f); + glUseProgram(program); + Core::SetActiveTexture(material.textureID, "colorTexture", program, 0); + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + std::vector transformations; + for (const auto& matrix : matrices) + { + 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, matrices, count, material, program); + glUseProgram(0); +} + +void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix, float scale, std::vectorplacePoints, PlanetParams planetParams, int count) { + float planetScale = planetParams.size; + //placeObjectOnPlanet(plant_specimens[0].modelContext, glm::mat4(), 0.2, current_type_plant_positions, planet, plant_type_count); + glm::mat4 savedobjectMatrix; + savedobjectMatrix = glm::scale(objectMatrix, glm::vec3(scale)); + float diameter = 24.4 * planetScale; + glm::vec3 base = glm::vec3(0.f, 1.f, 0.f); + glm::vec3 axis; + float angle; + glm::vec3 normalized_placePoint; + std::vector matrices; + matrices.clear(); + for (const auto& placePoint : placePoints) + { + objectMatrix = savedobjectMatrix; + normalized_placePoint = glm::normalize(placePoint); + axis = glm::cross(normalized_placePoint, base); + angle = dot(base, normalized_placePoint); + angle = acos(angle); + objectMatrix = objectMatrix * glm::rotate(objectMatrix, angle, axis) * glm::translate(base * diameter); + objectMatrix = objectMatrix * glm::translate(planetParams.position * (1 / scale)); + matrices.push_back(objectMatrix); + } - // wysunąć w dobrą stronę - - - - //objectMatrix = objectMatrix * glm::lookAt( - // placePoint, - // glm::vec3(0, 0, 0), - // glm::vec3(0.0f, 0.0f, 1.0f)); - - - //* objectMatrix; - //*glm::translate(placePoint) - //TEMPORARY DRAW FUNCTION - + //drawObjectTexture_plantInstanced(objectContext, matrices, plant2_1Material, program_pbr, count); } + Material plant3Material; @@ -555,8 +684,8 @@ std::vector texturePlantDataList; float thirdTreeStartScale = 0.0f; float secTreeStartScale = 0.0f; void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDuration, float secondTreeDuration, float thirdTreeDuration, - glm::vec3 plantPosition, float scaleFactor, Core::RenderContext& plant_1_1_small_Context, Core::RenderContext& plant_1_1Context, Core::RenderContext& thirdTreeContext, - glm::mat4& plantModelMatrix, Material& plant3Material, GLuint program_pbr) + std::vector plantPosition, float scaleFactor, Core::RenderContext& plant_1_1_small_Context, Core::RenderContext& plant_1_1Context, Core::RenderContext& thirdTreeContext, + glm::mat4& plantModelMatrix, Material& plant3Material, GLuint program_pbr, PlanetParams planet ) { // static float thirdTreeStartScale = 0.0f; @@ -564,7 +693,8 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura if (elapsedTime < firstTreeDuration) { float growthStage1 = ((elapsedTime ) / firstTreeDuration)*4; plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(scaleFactor + (elapsedTime / firstTreeDuration) * scaleFactor*10)); - drawObjectTexture_plant(plant_1_1_small_Context, plantModelMatrix, plant3Material, program_pbr); + //drawObjectTexture_plant(plant_1_1_small_Context, plantModelMatrix, plant3Material, program_pbr); + drawObjectTexture_plantInstanced(plant_1_1_small_Context, plant3Material, program_pbr_instanced, 15, plantPosition, planet, plantModelMatrix); elapsedTime += deltaTime; secTreeStartScale = scaleFactor + growthStage1 * scaleFactor; @@ -575,7 +705,8 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura float growthStage2 = ((elapsedTime - firstTreeDuration) / secondTreeDuration)*3; plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(secTreeStartScale * 2 + growthStage2 * scaleFactor)); - drawObjectTexture_plant(plant_1_1Context, plantModelMatrix, plant3Material, program_pbr); + //drawObjectTexture_plant(plant_1_1Context, plantModelMatrix, plant3Material, program_pbr); + drawObjectTexture_plantInstanced(plant_1_1Context, plant3Material, program_pbr_instanced, 15, plantPosition, planet, plantModelMatrix); //std::cout << "delta " << deltaTime << std::endl; //rozmiar //if (elapsedTime >= firstTreeDuration && elapsedTime < firstTreeDuration + 4*deltaTime) { @@ -589,11 +720,12 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura float growthStage3 = ((elapsedTime - firstTreeDuration - secondTreeDuration) / thirdTreeDuration)*3; plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + growthStage3 * scaleFactor)); - drawObjectTexture_plant(thirdTreeContext, plantModelMatrix, plant3Material, program_pbr); + // drawObjectTexture_plant(thirdTreeContext, plantModelMatrix, plant3Material, program_pbr); + drawObjectTexture_plantInstanced(thirdTreeContext, plant3Material, program_pbr_instanced, 15, plantPosition, planet, plantModelMatrix); elapsedTime += deltaTime; } else { - + elapsedTime = 0.0; //plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor + scaleFactor)); plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + scaleFactor)); TexturePlantData newData; @@ -606,9 +738,7 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura } - for (const auto& newData : texturePlantDataList) { - drawObjectTexture_plant(const_cast(newData.thirdTreeContext), newData.plantModelMatrix, newData.plant3Material, newData.program_pbr); - } + @@ -634,7 +764,7 @@ void renderScene(GLFWwindow* window) lastFrameTime = time; static float elapsedTime = 0.0f; - std::cout << "delta " << time<<"chuj"<< lastFrameTime <<"elapsed"<(plant).modelContext, plantMatrix, plant3Material, program_pbr); + std::vector positions = { plant.pos }; + //animateGrowingTree(const_cast(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plant.pos, scaleFactor, const_cast(plant).stageContext1, const_cast(plant).stageContext2, const_cast(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr); + animateGrowingTree(const_cast(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, positions, scaleFactor, const_cast(plant).stageContext1, const_cast(plant).stageContext2, const_cast(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr, planet); - animateGrowingTree(const_cast(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plant.pos, scaleFactor, const_cast(plant).stageContext1, const_cast(plant).stageContext2, const_cast(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr); - - + //drawObjectTexture_plantInstanced(const_cast(plant).stageContext3, plant3Material, program_pbr_instanced, 15, positions, planet, plantMatrix); + //(Core::RenderContext & context, std::vector modelMatrices, Material & material, GLuint program, int count, std::vectorplacePoints, PlanetParams planetParams) } } @@ -746,6 +878,7 @@ void init(GLFWwindow* window) 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"); loadModelToContext2("./models/plants/polygon.obj", plantContext); loadModelToContext("./models/sphere.obj", sphereContext);