This commit is contained in:
s473621 2024-02-08 09:40:55 +01:00
parent 6cd9fd3851
commit 354af7cef5
15 changed files with 305 additions and 60 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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(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(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(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(365,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
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(366,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(441,16): warning C4305: инициализация: усечение из "double" в "float"
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(545,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
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(546,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
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(595,30): 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(644,17): warning C4244: инициализация: преобразование "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(759,13): warning C4244: инициализация: преобразование "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(906,90): 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(907,94): 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(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", возможна потеря данных C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\tuple(158,47): warning C4244: инициализация: преобразование "_Ty" в "_Ty", возможна потеря данных
with with
[ [
@ -183,8 +186,8 @@ C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(220): message : в
_Pr=bool (__cdecl *)(std::tuple<int,float>,std::tuple<int,float>) _Pr=bool (__cdecl *)(std::tuple<int,float>,std::tuple<int,float>)
] ]
Создание кода Создание кода
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 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 grk-cw6.vcxproj -> C:\Users\neryt\Grafika2023\PlanetCreator\Release\grk-cw6.exe

Binary file not shown.

Binary file not shown.

View File

@ -71,6 +71,8 @@
<None Include="shaders\shader_biomes.vert" /> <None Include="shaders\shader_biomes.vert" />
<None Include="shaders\shader_pbr.frag" /> <None Include="shaders\shader_pbr.frag" />
<None Include="shaders\shader_pbr.vert" /> <None Include="shaders\shader_pbr.vert" />
<None Include="shaders\shader_pbr_instanced.frag" />
<None Include="shaders\shader_pbr_instanced.vert" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{3952C396-B1C6-44CD-96DD-C1AC15D32978}</ProjectGuid> <ProjectGuid>{3952C396-B1C6-44CD-96DD-C1AC15D32978}</ProjectGuid>

View File

@ -72,6 +72,9 @@
<ClCompile Include="src\imgui_widgets.cpp"> <ClCompile Include="src\imgui_widgets.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Distribution.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\objload.h"> <ClInclude Include="src\objload.h">
@ -107,9 +110,6 @@
<ClInclude Include="src\SOIL\image_DXT.h"> <ClInclude Include="src\SOIL\image_DXT.h">
<Filter>Source Files\SOIL</Filter> <Filter>Source Files\SOIL</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\ex_6_1.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="src\imconfig.h"> <ClInclude Include="src\imconfig.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@ -137,6 +137,15 @@
<ClInclude Include="src\imstb_truetype.h"> <ClInclude Include="src\imstb_truetype.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Distribution.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\stb_image.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ex_6_1.hpp">
<Filter>Shader Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="shaders\shader_5_sun.frag"> <None Include="shaders\shader_5_sun.frag">
@ -170,5 +179,11 @@
<None Include="shaders\shader_pbr.vert"> <None Include="shaders\shader_pbr.vert">
<Filter>Shader Files</Filter> <Filter>Shader Files</Filter>
</None> </None>
<None Include="shaders\shader_pbr_instanced.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_pbr_instanced.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -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);
}

View File

@ -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;
}

View File

@ -200,7 +200,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
int sum = 0; int sum = 0;
int chosen_number = 0; int chosen_number = 0;
std::vector<std::tuple<int, int>> probabilities; std::vector<std::tuple<int, int>> probabilities;
sum = NOTHING_SPAWNS_CUTOFF * PRECISION; sum = NOTHING_SPAWNS_CUTOFF * PRECISION;
int j = 0; int j = 0;
@ -282,6 +282,7 @@ GLuint program;
GLuint programSun; GLuint programSun;
GLuint programTex; GLuint programTex;
GLuint program_pbr; GLuint program_pbr;
GLuint program_pbr_instanced;
GLuint plantProgram; GLuint plantProgram;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
@ -326,6 +327,56 @@ struct ModelContext {
GLuint EBO; GLuint EBO;
}; };
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);
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; float aspectRatio = 1.f;
bool DoTheImportThing(const std::string& pFile) { bool DoTheImportThing(const std::string& pFile) {
@ -498,47 +549,125 @@ void drawObjectTexture_plant(Core::RenderContext &context, glm::mat4 modelMatrix
glUseProgram(0); glUseProgram(0);
} }
void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix, float scale, glm::vec3 placePoint, PlanetParams planetParams) { std::vector<glm::mat4> calculatePlantMatrices(const std::vector<glm::vec3>& plantPositions, const glm::vec3& planetPosition, float planetRadius, float plantScale) {
float planetScale = planetParams.size; std::vector<glm::mat4> plantMatrices;
//placePoint is described by normalized vector that points to a point on a sphere from inside of itself
placePoint = glm::normalize(placePoint);
//float diameter = ?; for (const auto& plantPos : plantPositions) {
glm::mat4 cobjectMatrix = objectMatrix; // Calculate the world position of the plant
cobjectMatrix = glm::scale(cobjectMatrix, glm::vec3(scale)); glm::vec3 worldPlantPos = planetPosition + plantPos * planetRadius;
float diameter = 24.4 * planetScale;
//objectMatrix = objectMatrix * glm::translate(placePoint * 0.1f); // 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::vector<glm::vec3>placePoints, 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 base = glm::vec3(0.f, 1.f, 0.f);
glm::vec3 axis; glm::vec3 axis;
float angle; float angle;
//odpowiednio obrócić glm::vec3 normalized_placePoint;
axis = glm::cross(placePoint, base); std::vector<glm::mat4> matrices;
angle = dot(base, placePoint); for (const auto& placePoint : placePoints)
angle = acos(angle); {
cobjectMatrix = cobjectMatrix * glm::rotate(cobjectMatrix, angle, axis) * glm::translate(base * diameter); objectMatrix = savedobjectMatrix;
cobjectMatrix = cobjectMatrix * glm::translate(planetParams.position * (1 / scale)); normalized_placePoint = glm::normalize(placePoint);
drawObjectBiomes(objectContext, cobjectMatrix, programBiomes); 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<glm::mat4> 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<glm::mat4> 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::vector<glm::vec3>placePoints, 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<glm::mat4> 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ę //drawObjectTexture_plantInstanced(objectContext, matrices, plant2_1Material, program_pbr, count);
//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
} }
Material plant3Material; Material plant3Material;
@ -555,8 +684,8 @@ std::vector<TexturePlantData> texturePlantDataList;
float thirdTreeStartScale = 0.0f; float thirdTreeStartScale = 0.0f;
float secTreeStartScale = 0.0f; float secTreeStartScale = 0.0f;
void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDuration, float secondTreeDuration, float thirdTreeDuration, 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, std::vector<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) glm::mat4& plantModelMatrix, Material& plant3Material, GLuint program_pbr, PlanetParams planet )
{ {
// static float thirdTreeStartScale = 0.0f; // static float thirdTreeStartScale = 0.0f;
@ -564,7 +693,8 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura
if (elapsedTime < firstTreeDuration) { if (elapsedTime < firstTreeDuration) {
float growthStage1 = ((elapsedTime ) / firstTreeDuration)*4; float growthStage1 = ((elapsedTime ) / firstTreeDuration)*4;
plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(scaleFactor + (elapsedTime / firstTreeDuration) * scaleFactor*10)); 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; elapsedTime += deltaTime;
secTreeStartScale = scaleFactor + growthStage1 * scaleFactor; secTreeStartScale = scaleFactor + growthStage1 * scaleFactor;
@ -575,7 +705,8 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura
float growthStage2 = ((elapsedTime - firstTreeDuration) / secondTreeDuration)*3; float growthStage2 = ((elapsedTime - firstTreeDuration) / secondTreeDuration)*3;
plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(secTreeStartScale * 2 + growthStage2 * scaleFactor)); 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; //std::cout << "delta " << deltaTime << std::endl;
//rozmiar //rozmiar
//if (elapsedTime >= firstTreeDuration && elapsedTime < firstTreeDuration + 4*deltaTime) { //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; float growthStage3 = ((elapsedTime - firstTreeDuration - secondTreeDuration) / thirdTreeDuration)*3;
plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + growthStage3 * scaleFactor)); 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; elapsedTime += deltaTime;
} }
else { else {
elapsedTime = 0.0;
//plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor + scaleFactor)); //plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor + scaleFactor));
plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + scaleFactor)); plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + scaleFactor));
TexturePlantData newData; TexturePlantData newData;
@ -606,9 +738,7 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura
} }
for (const auto& newData : texturePlantDataList) {
drawObjectTexture_plant(const_cast<Core::RenderContext&>(newData.thirdTreeContext), newData.plantModelMatrix, newData.plant3Material, newData.program_pbr);
}
@ -634,7 +764,7 @@ void renderScene(GLFWwindow* window)
lastFrameTime = time; lastFrameTime = time;
static float elapsedTime = 0.0f; static float elapsedTime = 0.0f;
std::cout << "delta " << time<<"chuj"<< lastFrameTime <<"elapsed"<<elapsedTime<< std::endl;
float firstTreeDuration = 2.0f; float firstTreeDuration = 2.0f;
float secondTreeDuration = 2.0f; float secondTreeDuration = 2.0f;
float thirdTreeDuration = 2.0f; float thirdTreeDuration = 2.0f;
@ -673,10 +803,12 @@ void renderScene(GLFWwindow* window)
// const Material& plantMaterial = plant.material; // Предполагаем, что у Plant есть поле Material material // const Material& plantMaterial = plant.material; // Предполагаем, что у Plant есть поле Material material
// drawObjectTexture_plant(const_cast<Plant::Plant&>(plant).modelContext, plantMatrix, plant3Material, program_pbr); // drawObjectTexture_plant(const_cast<Plant::Plant&>(plant).modelContext, plantMatrix, plant3Material, program_pbr);
std::vector<glm::vec3> positions = { plant.pos };
//animateGrowingTree(const_cast<Plant::Plant&>(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plant.pos, scaleFactor, const_cast<Plant::Plant&>(plant).stageContext1, const_cast<Plant::Plant&>(plant).stageContext2, const_cast<Plant::Plant&>(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr);
animateGrowingTree(const_cast<Plant::Plant&>(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, positions, scaleFactor, const_cast<Plant::Plant&>(plant).stageContext1, const_cast<Plant::Plant&>(plant).stageContext2, const_cast<Plant::Plant&>(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr, planet);
animateGrowingTree(const_cast<Plant::Plant&>(plant).elapsedTime, deltaTime, firstTreeDuration, secondTreeDuration, thirdTreeDuration, plant.pos, scaleFactor, const_cast<Plant::Plant&>(plant).stageContext1, const_cast<Plant::Plant&>(plant).stageContext2, const_cast<Plant::Plant&>(plant).stageContext3, plantMatrix, plant2_1Material, program_pbr); //drawObjectTexture_plantInstanced(const_cast<Plant::Plant&>(plant).stageContext3, plant3Material, program_pbr_instanced, 15, positions, planet, plantMatrix);
//(Core::RenderContext & context, std::vector<glm::mat4> modelMatrices, Material & material, GLuint program, int count, std::vector<glm::vec3>placePoints, PlanetParams planetParams)
} }
} }
@ -746,6 +878,7 @@ void init(GLFWwindow* window)
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.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"); 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 = 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); loadModelToContext2("./models/plants/polygon.obj", plantContext);
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);