Compare commits

...

4 Commits

Author SHA1 Message Date
afdb6c6d01 final 2024-02-08 12:42:03 +01:00
01482ed96a :))) 2024-02-08 11:53:34 +01:00
354af7cef5 UPDATE)) 2024-02-08 09:40:55 +01:00
6cd9fd3851 mcl 2024-02-08 09:38:13 +01:00
41 changed files with 200303 additions and 127 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +1,32 @@
 main.cpp
C:\Windows Kits\10\Include\10.0.22000.0\shared\minwindef.h(130,1): warning C4005: APIENTRY: изменение макроопределения
C:\Users\neryt\Grafika2023\PlanetCreator\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : см. предыдущее определение "APIENTRY"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(127,15): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(178,30): warning C4244: =: преобразование "float" в "int", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(184,20): warning C4244: =: преобразование "int" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(355,16): warning C4305: инициализация: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(459,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(460,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(473,17): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(588,13): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(722,92): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(723,96): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(724,100): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(725,102): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(728,106): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(729,96): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(138,15): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(159,23): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(207,30): warning C4244: =: преобразование "float" в "int", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(213,20): warning C4244: =: преобразование "int" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(389,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(390,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(468,16): warning C4305: инициализация: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(572,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(573,61): warning C4305: аргумент: усечение из "double" в "GLfloat"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(622,30): warning C4305: инициализация: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(671,17): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(778,16): warning C4244: инициализация: преобразование "_Rep" в "unsigned int", возможна потеря данных
with
[
_Rep=std::chrono::system_clock::rep
]
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(817,13): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(984,90): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(985,94): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(986,98): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(987,100): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(990,104): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(991,94): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(992,102): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(993,105): warning C4305: аргумент: усечение из "double" в "float"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(994,95): 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
[
@ -90,8 +102,8 @@ C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.2
_Tag=std::_Unpack_tuple_t,
_Tpl=std::tuple<int,float>
]
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(185): message : выполняется компиляция ссылки на экземпляр шаблон функции "std::tuple<int,int>::tuple<int,float,0>(std::tuple<int,float> &&) noexcept"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(185): message : выполняется компиляция ссылки на экземпляр шаблон функции "std::tuple<int,int>::tuple<int,float,0>(std::tuple<int,float> &&) noexcept"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(214): message : выполняется компиляция ссылки на экземпляр шаблон функции "std::tuple<int,int>::tuple<int,float,0>(std::tuple<int,float> &&) noexcept"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(214): message : выполняется компиляция ссылки на экземпляр шаблон функции "std::tuple<int,int>::tuple<int,float,0>(std::tuple<int,float> &&) noexcept"
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\tuple(158,47): warning C4244: инициализация: преобразование "const int" в "_Ty", возможна потеря данных
with
[
@ -174,7 +186,7 @@ C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.2
_RanIt=std::tuple<int,int> *,
_Pr=bool (__cdecl *)(std::tuple<int,float>,std::tuple<int,float>)
]
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(193): message : выполняется компиляция ссылки на экземпляр шаблон функции "void std::sort<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,bool(__cdecl *)(std::tuple<int,float>,std::tuple<int,float>)>(const _RanIt,const _RanIt,_Pr)"
C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(222): message : выполняется компиляция ссылки на экземпляр шаблон функции "void std::sort<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,bool(__cdecl *)(std::tuple<int,float>,std::tuple<int,float>)>(const _RanIt,const _RanIt,_Pr)"
with
[
_Ty=std::tuple<int,int>,
@ -182,8 +194,8 @@ C:\Users\neryt\Grafika2023\PlanetCreator\cw 6\src\ex_6_1.hpp(193): message : в
_Pr=bool (__cdecl *)(std::tuple<int,float>,std::tuple<int,float>)
]
Создание кода
2 of 2460 functions (<0.1%) were compiled, the rest were copied from previous compilation.
1 of 2523 functions (<0.1%) 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
24 functions had inline decision re-evaluated but remain unchanged
Создание кода завершено
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,10 @@
<None Include="shaders\shader_biomes.vert" />
<None Include="shaders\shader_pbr.frag" />
<None Include="shaders\shader_pbr.vert" />
<None Include="shaders\shader_pbr_instanced.frag" />
<None Include="shaders\shader_pbr_instanced.vert" />
<None Include="shaders\shader_sky.frag" />
<None Include="shaders\shader_sky.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{3952C396-B1C6-44CD-96DD-C1AC15D32978}</ProjectGuid>

View File

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

View File

@ -11,6 +11,6 @@ Pos=4,3
Size=218,129
[Window][Dodawanie nowej planety]
Pos=23,7
Pos=146,127
Size=282,158

View File

@ -0,0 +1,40 @@
# Blender v2.90.0 OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube
v -10.000000 -10.000000 10.000000
v -10.000000 10.000000 10.000000
v -10.000000 -10.000000 -10.000000
v -10.000000 10.000000 -10.000000
v 10.000000 -10.000000 10.000000
v 10.000000 10.000000 10.000000
v 10.000000 -10.000000 -10.000000
v 10.000000 10.000000 -10.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.125000 0.500000
vt 0.125000 0.750000
vt 0.875000 0.500000
vt 0.875000 0.750000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl _PBR
s 1
f 1/1/1 2/2/1 4/3/1 3/4/1
f 3/4/2 4/3/2 8/5/2 7/6/2
f 7/6/3 8/5/3 6/7/3 5/8/3
f 5/8/4 6/7/4 2/9/4 1/10/4
f 3/11/5 7/6/5 5/8/5 1/12/5
f 8/5/6 4/13/6 2/14/6 6/7/6

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,19 @@
#version 430 core
layout (location = 0) out vec4 out_color;
layout (location = 1) out vec4 BrightColor;
uniform samplerCube skybox;
in vec3 texCoord;
void main()
{
vec4 finalColor =texture(skybox,texCoord);
float brightness = dot(vec3(finalColor.x,finalColor.y, finalColor.z ), vec3(0.2126, 0.7152, 0.0722));
if(brightness > 1.0)
BrightColor = vec4(vec3(finalColor.x,finalColor.y, finalColor.z ), 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
out_color = texture(skybox,texCoord);
}

View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
uniform mat4 transformation;
out vec3 texCoord;
void main()
{
texCoord = vertexPosition;
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -1,14 +1,14 @@
#include "Texture.h"
#include "Texture.h"
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
#include "SOIL/SOIL.h"
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
#include "SOIL/SOIL.h"
typedef unsigned char byte;
GLuint Core::LoadTexture( const char * filepath )
GLuint Core::LoadTexture(const char* filepath)
{
GLuint id;
glGenTextures(1, &id);
@ -20,7 +20,7 @@ GLuint Core::LoadTexture( const char * filepath )
int w, h;
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
@ -28,12 +28,39 @@ GLuint Core::LoadTexture( const char * filepath )
return id;
}
GLuint Core::LoadCubeMap(const char* filepath) {
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
int w, h;
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
}
return id;
}
void Core::SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit)
void Core::SetActiveTexture(GLuint textureID, const char* shaderVariableName, GLuint programID, int textureUnit)
{
glUniform1i(glGetUniformLocation(programID, shaderVariableName), textureUnit);
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, textureID);
}
void Core::SetActiveBackground(GLuint textureID, const char* shaderVariableName, GLuint programID, int textureUnit)
{
glUniform1i(glGetUniformLocation(programID, shaderVariableName), textureUnit);
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
}

View File

@ -6,10 +6,13 @@
namespace Core
{
GLuint LoadTexture(const char * filepath);
GLuint LoadCubeMap(const char* filepath);
// textureID - identyfikator tekstury otrzymany z funkcji LoadTexture
// shaderVariableName - nazwa zmiennej typu 'sampler2D' w shaderze, z ktora ma zostac powiazana tekstura
// programID - identyfikator aktualnego programu karty graficznej
// textureUnit - indeks jednostki teksturujacej - liczba od 0 do 7. Jezeli uzywa sie wielu tekstur w jednym shaderze, to kazda z nich nalezy powiazac z inna jednostka.
void SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit);
void SetActiveBackground(GLuint textureID, const char* shaderVariableName, GLuint programID, int textureUnit);
}

View File

@ -17,11 +17,15 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include <random>
#include <chrono>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
const double M_PI = 3.14159265358979323846;
struct Material {
float Ns; // shininess
@ -91,7 +95,7 @@ void loadMTLAndGetTextureID(const std::string& filePath, Material& material) {
void loadModelToContext2(std::string path, Core::RenderContext& context)
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FindInvalidData);
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
@ -99,7 +103,7 @@ void loadModelToContext2(std::string path, Core::RenderContext& context)
return;
}
context.initFromAssimpMesh2(scene->mMeshes[0]);
context.initFromAssimpMesh(scene->mMeshes[0]);
}
namespace Plant
{
@ -107,18 +111,25 @@ namespace Plant
class Plant {
public:
float humMean; float humSD; float tempMean; float tempSD; std::string name; std::string fileName; Core::RenderContext modelContext; glm::vec3 pos;
float humMean; float humSD; float tempMean; float tempSD; float elapsedTime; std::string name; std::string fileName; Core::RenderContext modelContext; Core::RenderContext stageContext1; Core::RenderContext stageContext2; Core::RenderContext stageContext3; glm::vec3 pos;
Plant(float humMean, float humSD, float tempMean, float tempSD, std::string name, std::string fileName) {
this->humMean = humMean;
this->humSD = humSD;
this->tempMean = tempMean;
this->tempSD = tempSD;
this->name = name;
this->elapsedTime = 0.0;
this->fileName = fileName;
this->modelContext = Core::RenderContext();
loadModelToContext2("./models/plants/polygon.obj", modelContext);
this->stageContext1 = Core::RenderContext();
this->stageContext2 = Core::RenderContext();
this->stageContext3 = Core::RenderContext();
this->pos = glm::vec3(1,0,0);
loadModelToContext2(fileName+".obj", modelContext);
loadModelToContext2(fileName+"_small.obj", stageContext1);
loadModelToContext2(fileName+ "_med.obj", stageContext2);
loadModelToContext2(fileName+ ".obj", stageContext3);
//this->pos = glm::vec3((rand() % 100) / 100, (rand() % 100) / 100, (rand() % 100) / 100);
}
@ -143,6 +154,24 @@ struct PlanetParams {
std::vector<Plant::Plant> plants = std::vector<Plant::Plant>();
};
std::vector<glm::vec3> distributePlantsOnSphere(const glm::vec3& center, float radius, int count) {
std::vector<glm::vec3> positions;
float angleIncrement = M_PI * (3 - sqrt(5)); // Золотое сечение в радианах
for (int i = 0; i < count; ++i) {
float t = float(i) / float(count);
float inclination = acos(1 - 2 * t); // Полярный угол
float azimuth = angleIncrement * i; // Азимутальный угол
float x = sin(inclination) * cos(azimuth) ;
float y = sin(inclination) * sin(azimuth) ;
float z = cos(inclination);
std::cout << x<<" "<<y << " " << z << std::endl;
positions.push_back(center + radius * glm::vec3(x, y, z));
}
return positions;
}
struct Climate {
float tempMin, tempMax;
float precipMin, precipMax;
@ -173,7 +202,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
int sum = 0;
int chosen_number = 0;
std::vector<std::tuple<int, int>> probabilities;
sum = NOTHING_SPAWNS_CUTOFF * PRECISION;
int j = 0;
@ -211,6 +240,14 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
std::cout << "got a winner " << plant.name << std::endl;
plant.pos = glm::vec3((1.0 * (rand() / (RAND_MAX + 1.0))), (1.0 * (rand() / (RAND_MAX + 1.0))), (1.0 * (rand() / (RAND_MAX + 1.0))));
planet.plants.push_back(plant);
// Распределение растений по поверхности планеты
std::vector<glm::vec3> plantPositions = distributePlantsOnSphere(planet.position, planet.size, planet.plants.size());
for (size_t i = 0; i < plantPositions.size(); ++i) {
planet.plants[i].pos = plantPositions[i];
planet.plants[i].elapsedTime = 0.0;
}
}
}
@ -241,17 +278,31 @@ namespace texture {
GLuint sun;
GLuint earthNormal;
GLuint asteroidNormal;
GLuint background;
}
GLuint program_sky;
GLuint program_blur;
GLuint program_bloom_final;
GLuint program;
GLuint programSun;
GLuint programTex;
GLuint program_pbr;
GLuint plantProgram;
GLuint program_pbr_instanced;
Core::Shader_Loader shaderLoader;
Core::RenderContext cubeContext;
GLuint plantProgram;
GLuint programBiomes;
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);
float skySize = 4.f;
Core::RenderContext plantContext;
Core::RenderContext sphereContext;
@ -263,14 +314,23 @@ Core::RenderContext plant_2_1Context;
Core::RenderContext plant_2_1_small_Context;
Core::RenderContext plant_2_1_med_Context;
Core::RenderContext plant_4_1Context;
Core::RenderContext plant_4_1_small_Context;
Core::RenderContext plant_4_1_med_Context;
Core::RenderContext plant_7_1Context;
Core::RenderContext plant_7_1_small_Context;
Core::RenderContext plant_7_1_med_Context;
Core::RenderContext plant3Context;
Core::RenderContext plant2Context;
Core::RenderContext plant2_1Context;
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
glm::vec3 sunPosition = glm::vec3(0.0f, 0.0f, 0.0f); // Позиция солнца
glm::vec3 sunColor = glm::vec3(1.0f, 1.0f, 1.0f); // Цвет солнца
//glm::vec3 sunPosition = glm::vec3(0.0f, 0.0f, 0.0f); // Позиция солнца
//glm::vec3 sunColor = glm::vec3(1.0f, 1.0f, 1.0f); // Цвет солнца
@ -291,6 +351,58 @@ struct ModelContext {
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);
//glClear(GL_ELEMENT_ARRAY_BUFFER);
glClear(GL_ARRAY_BUFFER);
}
float aspectRatio = 1.f;
bool DoTheImportThing(const std::string& pFile) {
@ -339,6 +451,7 @@ void renderImGui() {
ImGui::SliderFloat("Temperatura", &newPlanetParams.temperature, 0.0f, 10.0f); // Слайдер для осадков
if (ImGui::Button("Dodac")) {
//planets.clear();
newPlanetParams = populatePlanet(newPlanetParams, plant_specimens);
planets.push_back(newPlanetParams);
}
@ -439,7 +552,7 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
}
void drawObjectTexture_plant(Core::RenderContext& context, glm::mat4 modelMatrix, const Material& material, GLuint program) {
void drawObjectTexture_plant(Core::RenderContext &context, glm::mat4 modelMatrix, const Material& material, GLuint program) {
glUseProgram(program);
Core::SetActiveTexture(material.textureID, "colorTexture", program, 0);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -458,53 +571,133 @@ void drawObjectTexture_plant(Core::RenderContext& context, glm::mat4 modelMatrix
glUniform1i(glGetUniformLocation(program, "illuminationModel"), material.illum);
glUniform1f(glGetUniformLocation(program, "metallic"), 0.05);
glUniform1f(glGetUniformLocation(program, "roughness"), 0.2);
// std::cout << "DRAWWW " << std::endl;
Core::DrawContext(context);
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<glm::mat4> calculatePlantMatrices(const std::vector<glm::vec3>& plantPositions, const glm::vec3& planetPosition, float planetRadius, float plantScale) {
std::vector<glm::mat4> 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::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 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<glm::mat4> 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<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ę
//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;
Material plant2_1Material;
PlanetParams TestPlanet = PlanetParams();
struct TexturePlantData {
@ -515,59 +708,65 @@ struct TexturePlantData {
};
std::vector<TexturePlantData> texturePlantDataList;
#include <cmath>
#include <random>
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<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, PlanetParams planet )
{
// static float thirdTreeStartScale = 0.0f;
//pierwsze drzewo
if (elapsedTime < firstTreeDuration) {
plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor + (elapsedTime / firstTreeDuration) * scaleFactor));
drawObjectTexture_plant(plant_1_1_small_Context, plantModelMatrix, plant3Material, program_pbr);
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_plantInstanced(plant_1_1_small_Context, plant3Material, program_pbr_instanced, 15, plantPosition, planet, plantModelMatrix);
elapsedTime += deltaTime;
secTreeStartScale = scaleFactor + growthStage1 * scaleFactor;
}
// drugie drzewo
else if (elapsedTime < firstTreeDuration + secondTreeDuration) {
float growthStage2 = ((elapsedTime - firstTreeDuration) / secondTreeDuration);
plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(scaleFactor + growthStage2 * scaleFactor));
drawObjectTexture_plant(plant_1_1Context, plantModelMatrix, plant3Material, program_pbr);
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_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) {
//if (elapsedTime >= firstTreeDuration && elapsedTime < firstTreeDuration + 4*deltaTime) {
thirdTreeStartScale = scaleFactor + growthStage2 * scaleFactor;
//std::cout << "thirdTreeStartScale: " << thirdTreeStartScale << std::endl;
}
// }
elapsedTime += deltaTime;
}
//trzecie drzewo
else if (elapsedTime < firstTreeDuration + secondTreeDuration + thirdTreeDuration) {
float growthStage3 = ((elapsedTime - firstTreeDuration - secondTreeDuration) / thirdTreeDuration);
plantModelMatrix = glm::translate(plantPosition) * glm::scale(glm::vec3(thirdTreeStartScale*2 + growthStage3 * scaleFactor));
drawObjectTexture_plant(thirdTreeContext, plantModelMatrix, plant3Material, program_pbr);
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_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 = glm::translate(plantPosition) * glm::scale(glm::vec3(thirdTreeStartScale*2 + scaleFactor));
TexturePlantData newData;
newData.thirdTreeContext = thirdTreeContext;
newData.plantModelMatrix = plantModelMatrix;
newData.plant3Material = plant3Material;
newData.program_pbr = program_pbr;
texturePlantDataList.push_back(newData);
//plantModelMatrix = plantModelMatrix * glm::scale(glm::vec3(thirdTreeStartScale*3 + scaleFactor));
//TexturePlantData newData;
//newData.thirdTreeContext = thirdTreeContext;
//newData.plantModelMatrix = plantModelMatrix;
//newData.plant3Material = plant3Material;
//newData.program_pbr = program_pbr;
//texturePlantDataList.push_back(newData);
// drawObjectTexture_plant(thirdTreeContext, plantModelMatrix, plant3Material, program_pbr);
elapsedTime = 0;
}
for (const auto& newData : texturePlantDataList) {
drawObjectTexture_plant(const_cast<Core::RenderContext&>(newData.thirdTreeContext), newData.plantModelMatrix, newData.plant3Material, newData.program_pbr);
}
@ -575,15 +774,45 @@ void animateGrowingTree(float& elapsedTime, float deltaTime, float firstTreeDura
Core::RenderContext& getRandomContext(Plant::Plant& plant) {
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine engine(seed);
std::uniform_int_distribution<int> distribution(0, 2); // Диапазон от 0 до 2 включительно
int choice = distribution(engine);
switch (choice) {
case 0:
return plant.modelContext;
case 1:
return plant.stageContext1;
case 2:
return plant.stageContext2;
default:
return plant.stageContext3; // На случай, если что-то пойдет не так, вернем stageContext3
}
}
void drawSky(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
glUseProgram(program_sky);
Core::SetActiveBackground(texture, "skybox", program_sky, 0);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program_sky, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program_sky, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
glUseProgram(0);
}
void renderScene(GLFWwindow* window)
{
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
//glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::mat4 transformation;
float time = glfwGetTime();
@ -593,10 +822,10 @@ void renderScene(GLFWwindow* window)
lastFrameTime = time;
static float elapsedTime = 0.0f;
std::cout << "delta " << time<<"chuj"<< lastFrameTime <<"elapsed"<<elapsedTime<< std::endl;
float firstTreeDuration = 20.0f;
float secondTreeDuration = 8.0f;
float thirdTreeDuration = 5.0f;
float firstTreeDuration = 2.0f;
float secondTreeDuration = 2.0f;
float thirdTreeDuration = 2.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);
@ -619,25 +848,41 @@ void renderScene(GLFWwindow* window)
//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);
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), planet.position) * glm::scale(glm::mat4(1.0f), glm::vec3(planet.size));
drawObjectTexture(sphereContext, modelMatrix, planet.texture, programTex); // Отрисовка планеты
std::vector<Plant::Plant>plants = planet.plants;
for (const auto& plant : plants)
//TODO: REMOVE PLACEHOLDER
// placeObjectOnPlanet(plant_1_1Context, glm::mat4(), 0.2, plant.pos, planet);
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);
for ( auto& plant : planet.plants) {
glm::vec3 normal = glm::normalize(plant.pos - planet.position);
glm::quat orientation = glm::rotation(glm::vec3(0.0f, 1.0f, 0.0f), normal);
glm::mat4 plantMatrix = glm::translate(glm::mat4(1.0f), plant.pos) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1.0f), glm::vec3(0.1f)); // Масштаб адаптируйте под свои нужды
// Теперь используем материал, связанный с каждым растением
// const Material& plantMaterial = plant.material; // Предполагаем, что у Plant есть поле Material material
// static Core::RenderContext& chosenContext = getRandomContext(const_cast<Plant::Plant&>(plant));
drawObjectTexture_plant(const_cast<Plant::Plant&>(plant).modelContext, plantMatrix, plant3Material, program_pbr);
//drawObjectTexture_plant(chosenContext, 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_instanced, planet);
// drawObjectTexture_plantInstanced(const_cast<Plant::Plant&>(plant).stageContext3, plant3Material, program_pbr, 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)
}
// 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);
}
//placeObjectOnPlanet(plant2Context, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(1.0, 0.0, 1.0)), sphereContext, planetMatrix);
renderSun();
skyPos = cameraPos;
glm::mat4 skyMatrix = glm::scale(glm::vec3(skySize));
glm::mat4 skyTranslate = glm::translate(skyPos);
drawSky(cubeContext, skyTranslate * skyMatrix, texture::planet1);
//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);
//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);
@ -651,6 +896,7 @@ void renderScene(GLFWwindow* window)
//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);
//glfwSwapBuffers(window);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
@ -680,6 +926,8 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
void init(GLFWwindow* window)
{
@ -695,19 +943,33 @@ 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");
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);
loadModelToContext("./models/plant_1_1.obj", plant_1_1Context);
loadModelToContext("./models/plant_1_1_med.obj", plant_1_1_med_Context);
loadModelToContext("./models/plant_1_1_small.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);
loadModelToContext("./models/plant_3_1_small.obj", plant_4_1_small_Context);
loadModelToContext("./models/plant_3_1_med.obj", plant_4_1_med_Context);
loadModelToContext("./models/plant_3_1.obj", plant_4_1Context);
loadModelToContext("./models/plant_7_1_small.obj", plant_7_1_small_Context);
loadModelToContext("./models/plant_7_1_med.obj", plant_7_1_med_Context);
loadModelToContext("./models/plant_7_1.obj", plant_7_1Context);
// setupBuffers(plantContex_test);
texture::earth=Core::LoadTexture("textures/earth2.png");
texture::clouds = Core::LoadTexture("textures/clouds.jpg");
@ -719,22 +981,28 @@ void init(GLFWwindow* window)
loadMTLAndGetTextureID("./models/plant_1_1.mtl", plant3Material);
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
plant_specimens.push_back(Plant::Plant(1, 0.99, 1, 1, "testPlant2", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.95, 1, 1, "testPlantXXXXX", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.93, 1, 1, "testPlantAAAAAAAAA", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.90, 1, 1, "testPlantCCCCCCCCCCC", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.5, 1, 1, "testPlantBBBBBBBBB", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 1, 1, 1, "testPlantFFFFFFFFFFFF", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.2, 1, 1, "testPlant!!!!!!!!!!!!!!!!", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.1, 1, 1, "testPlant_MAYBE", "./models/plant_4.ply"));
plant_specimens.push_back(Plant::Plant(1, 0.99, 1, 1, "testPlant2", "./models/plant_3_1"));
plant_specimens.push_back(Plant::Plant(1, 0.95, 1, 1, "testPlantXXXXX", "./models/plant_2_1"));
plant_specimens.push_back(Plant::Plant(1, 0.93, 1, 1, "testPlantAAAAAAAAA", "./models/plant_7_1"));
plant_specimens.push_back(Plant::Plant(1, 0.90, 1, 1, "testPlantCCCCCCCCCCC", "./models/plant_3_1"));
plant_specimens.push_back(Plant::Plant(1, 0.5, 1, 1, "testPlantBBBBBBBBB", "./models/plant_2_1"));
plant_specimens.push_back(Plant::Plant(1, 1, 1, 1, "testPlantFFFFFFFFFFFF", "./models/plant_7_1"));
plant_specimens.push_back(Plant::Plant(1, 0.2, 1, 1, "testPlant!!!!!!!!!!!!!!!!", "./models/plant_3_1"));
plant_specimens.push_back(Plant::Plant(1, 0.1, 1, 1, "testPlant_MAYBE", "./models/plant_7_1"));
plant_specimens.push_back(Plant::Plant(1, 0.85, 1, 1, "testPlantFFFFFFFFFFFF1", "./models/plant_2_1"));
plant_specimens.push_back(Plant::Plant(1, 0.2, 1, 1, "testPlant!!!!!!!!!!!!!!!!1", "./models/plant_3_1"));
plant_specimens.push_back(Plant::Plant(1, 0.1, 1, 1, "testPlant_MAYBE1", "./models/plant_7_1"));
defaultTexture = Core::LoadTexture("textures/1.png");
loadModelToContext("./models/cube.obj", cubeContext);
texture::background = Core::LoadCubeMap("./textures/SkyCut2.jpg");
defaultTexture = Core::LoadTexture("textures/3.png");
if (defaultTexture == 0) {
std::cout << "Failed to load default texture" << std::endl;
}
climates.push_back({ -10, 0, 0, 50, Core::LoadTexture("textures/1.png") });
climates.push_back({ 0, 10, 50, 100, Core::LoadTexture("textures/2.png") });
climates.push_back({ -10, 0, 1, 50, Core::LoadTexture("textures/1.png") });
climates.push_back({ 0, 10, 1, 50, Core::LoadTexture("textures/2.png") });
climates.push_back({ 10, 30, 50, 100, Core::LoadTexture("textures/3.jpg") });
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB