Using only assimp-based models, working on improving shaders

This commit is contained in:
xkamikoo 2021-02-12 00:08:28 +01:00
parent 032c080f33
commit c406c3571d
26 changed files with 60462 additions and 71 deletions

View File

@ -0,0 +1,14 @@
# Blender MTL File: 'Asteroid_4_LOW_MODEL_.blend'
# Material Count: 1
newmtl ASTEROID_LOW_POLY_4_
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd textures\\asteroid_diffuse.png
map_Bump textures\\asteroid_normal.png

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 MiB

View File

@ -5,7 +5,7 @@ layout (location = 1) out vec4 BrightColor;
uniform vec3 objectColor; uniform vec3 objectColor;
uniform vec3 cameraPos; uniform vec3 cameraPos;
uniform sampler2D colorTexture; uniform sampler2D diffuseTexture;
uniform vec3 colorTex; uniform vec3 colorTex;
in vec3 interpNormal; in vec3 interpNormal;
in vec3 fragPos; in vec3 fragPos;
@ -16,7 +16,7 @@ void main()
vec3 normal = normalize(interpNormal); vec3 normal = normalize(interpNormal);
vec3 V = normalize(cameraPos-fragPos); vec3 V = normalize(cameraPos-fragPos);
float coef = pow(max(0,dot(normal,V)),2); float coef = pow(max(0,dot(normal,V)),2);
vec4 textureColor = texture2D(colorTexture, -vTexCoord); vec4 textureColor = texture2D(diffuseTexture, -vTexCoord);
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * colorTex; vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * colorTex;
FragColor = vec4(texture + texture * coef, 1.0); FragColor = vec4(texture + texture * coef, 1.0);

View File

@ -9,12 +9,14 @@ struct PointLight {
float intensity; float intensity;
}; };
#define NR_POINT_LIGHTS 5 #define MAX_POINT_LIGHTS 64
uniform vec3 objectColor; uniform vec3 objectColor;
uniform vec3 cameraPos; uniform vec3 cameraPos;
uniform sampler2D colorTexture; uniform sampler2D diffuseTexture;
uniform PointLight pointLights[NR_POINT_LIGHTS]; uniform sampler2D normalTexture;
uniform PointLight pointLights[MAX_POINT_LIGHTS];
uniform int LightsCount;
in vec3 interpNormal; in vec3 interpNormal;
in vec3 fragPos; in vec3 fragPos;
@ -25,10 +27,10 @@ in vec2 vTexCoord;
void main() void main()
{ {
vec3 fragColor = vec3(0,0,0); vec3 fragColor = vec3(0,0,0);
vec4 textureColor = texture2D(colorTexture, vTexCoord); vec4 textureColor = texture2D(diffuseTexture, vTexCoord);
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor; vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
vec3 normal = normalize(interpNormal); vec3 normal = normalize(interpNormal);
for(int i = 0; i < NR_POINT_LIGHTS; i++) for(int i = 0; i < LightsCount; i++)
{ {
vec3 lightDir = normalize(pointLights[i].position - fragPos); vec3 lightDir = normalize(pointLights[i].position - fragPos);

View File

@ -44,19 +44,10 @@ static GLubyte* g_particule_color_data;
GLuint particle_vertex_buffer; GLuint particle_vertex_buffer;
GLuint particles_position_buffer; GLuint particles_position_buffer;
GLuint particles_color_buffer; GLuint particles_color_buffer;
double partX = -6;
double partY = 0;
double partXdir = 0;
double partYdir = 0;
double partAdir = 0;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
Core::RenderContext armContext;
std::vector<Core::Node> arm;
int ballIndex;
bool bothEngines = true; bool bothEngines = true;
GLuint textureShip_normals; GLuint textureShip_normals;
GLuint sunTexture; GLuint sunTexture;
GLuint earthTexture; GLuint earthTexture;
@ -64,16 +55,16 @@ GLuint moonTexture;
GLuint skyboxTexture; GLuint skyboxTexture;
GLuint shipTexture; GLuint shipTexture;
GLuint particleTexture; GLuint particleTexture;
obj::Model sphereModel;
obj::Model cubeModel;
obj::Model shipModel;
Core::RenderContext sphereContext; //Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
Core::RenderContext shipContext; //Core::RenderContext shipContext;
//assimp //assimp
std::shared_ptr<Model> cube;
std::shared_ptr<Model> sphere;
std::shared_ptr<Model> corvette; std::shared_ptr<Model> corvette;
std::shared_ptr<Model> asteroid;
//std::vector<Core::RenderContext> corvetteMeshes; //std::vector<Core::RenderContext> corvetteMeshes;
std::shared_ptr<Model> crewmate; std::shared_ptr<Model> crewmate;
@ -264,6 +255,22 @@ void drawFromAssimpModel(GLuint program, std::shared_ptr<Model> model, glm::mat4
glUseProgram(0); glUseProgram(0);
} }
void drawFromAssimpTexture(GLuint program, std::shared_ptr<Model> model, glm::mat4 modelMatrix, glm::vec3 color, GLuint texID)
{
glUseProgram(program);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(program, "colorTex"), color.x, color.y, color.z);
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
Core::SetActiveTexture(texID, "diffuseTexture", program, 0);
model->Draw(program);
glUseProgram(0);
}
//Skybox //Skybox
unsigned int loadCubemap(std::vector<std::string> faces) unsigned int loadCubemap(std::vector<std::string> faces)
{ {
@ -296,7 +303,7 @@ unsigned int loadCubemap(std::vector<std::string> faces)
return textureID; return textureID;
} }
void drawSkybox(GLuint program, Core::RenderContext context, GLuint texID) void drawSkybox(GLuint program, std::shared_ptr<Model> cubeModel, GLuint texID)
{ {
glUseProgram(program); glUseProgram(program);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -307,7 +314,7 @@ void drawSkybox(GLuint program, Core::RenderContext context, GLuint texID)
glUniform1i(glGetUniformLocation(program, "skybox"), 0); glUniform1i(glGetUniformLocation(program, "skybox"), 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, texID); glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
Core::DrawContext(context); cubeModel->Draw(program);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
//glDepthMask(GL_TRUE); //glDepthMask(GL_TRUE);
glUseProgram(0); glUseProgram(0);
@ -381,7 +388,7 @@ void drawObjectTexture(GLuint program, Core::RenderContext context, glm::mat4 mo
glUniform3f(glGetUniformLocation(program, "colorTex"), texture.x, texture.y, texture.z); glUniform3f(glGetUniformLocation(program, "colorTex"), texture.x, texture.y, texture.z);
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
Core::SetActiveTexture(texID, "colorTexture", program, 0); Core::SetActiveTexture(texID, "diffuseTexture", program, 0);
Core::DrawContext(context); Core::DrawContext(context);
glUseProgram(0); glUseProgram(0);
@ -442,6 +449,7 @@ void renderScene()
glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(time / 2, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.01)); glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(time / 2, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.01));
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f)); glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
glm::mat4 testModelMatrix = glm::translate(glm::vec3(1, 0, 0));
glUseProgram(programTex); glUseProgram(programTex);
@ -454,6 +462,8 @@ void renderScene()
glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-450, 0, -1500)); glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-450, 0, -1500));
lights[3].position = glm::vec3(engineRight[3][0], engineRight[3][1], engineRight[3][2]); lights[3].position = glm::vec3(engineRight[3][0], engineRight[3][1], engineRight[3][2]);
glUniform1i(glGetUniformLocation(programTex,"LightsCount"), lights.size());
for (int i = 0; i < lights.size(); i++) for (int i = 0; i < lights.size(); i++)
{ {
std::string col = "pointLights[" + std::to_string(i) + "].color"; std::string col = "pointLights[" + std::to_string(i) + "].color";
@ -469,16 +479,18 @@ void renderScene()
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1)); drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
drawFromAssimpModel(programTex, crewmate, crewmateModelMatrix, glm::vec3(1)); drawFromAssimpModel(programTex, crewmate, crewmateModelMatrix, glm::vec3(1));
drawFromAssimpModel(programTex, asteroid, testModelMatrix, glm::vec3(1));
//rysowanie Ziemi z ksiezycem //rysowanie Ziemi z ksiezycem
drawObjectTexture(programTex, sphereContext, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture); drawFromAssimpTexture(programTex, sphere, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture);
drawObjectTexture(programTex, sphereContext, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture); drawFromAssimpTexture(programTex, sphere, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
drawObjectTexture(programTex, sphereContext, planet1, glm::vec3(0.4f, 0.2f, 0.9f), moonTexture); drawFromAssimpTexture(programTex, sphere, planet1, glm::vec3(0.4f, 0.2f, 0.9f), moonTexture);
glUseProgram(programSun); glUseProgram(programSun);
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
drawObjectTexture(programSun, sphereContext, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture); drawFromAssimpTexture(programSun, sphere, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture);
drawObjectTexture(programSun, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture); drawFromAssimpTexture(programSun, sphere, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
//particlepart //particlepart
glUseProgram(programParticle); glUseProgram(programParticle);
@ -505,36 +517,7 @@ void renderScene()
lights[2].intensity = 0.00001; lights[2].intensity = 0.00001;
lights[3].intensity = 0.00001; lights[3].intensity = 0.00001;
} }
/*
if (cameraPos[0] < partX)
{
partXdir = 1;
}
else if (cameraPos[0] > partX)
{
partXdir = -1;
}
else
{
partXdir = 0;
}
if (cameraPos[2] < partY)
{
partYdir = 1;
}
else if (cameraPos[2] > partY)
{
partYdir = -1;
}
else
{
partYdir = 0;
}
if (cameraDir[0] < 0)
{
partAdir = cameraDir[0] * -1;
}
*/
for (int i = 0; i < newparticles; i++) { for (int i = 0; i < newparticles; i++) {
int particleIndex = FindUnusedParticle(); int particleIndex = FindUnusedParticle();
ParticlesContainer[particleIndex].life = 2.0f; ParticlesContainer[particleIndex].life = 2.0f;
@ -554,7 +537,7 @@ void renderScene()
float spread = 0.8; float spread = 0.8;
glm::vec3 maindir = -1 * cameraDir; //glm::vec3(partXdir*partAdir, -0.3f, partYdir*partAdir); glm::vec3 maindir = -1 * cameraDir;
glm::vec3 randomdir = glm::vec3( glm::vec3 randomdir = glm::vec3(
(rand() % 2000 - 1000.0f) / 5000.0f, (rand() % 2000 - 1000.0f) / 5000.0f,
(rand() % 2000 - 1000.0f) / 5000.0f, (rand() % 2000 - 1000.0f) / 5000.0f,
@ -616,7 +599,7 @@ void renderScene()
SortParticles(); SortParticles();
drawParticles(ParticlesCount, transformation); drawParticles(ParticlesCount, transformation);
drawSkybox(programSkybox, cubeContext, skyboxTexture); drawSkybox(programSkybox, cube, skyboxTexture);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -748,12 +731,14 @@ void init()
corvette = std::make_shared<Model>("models/Corvette-F3.obj"); corvette = std::make_shared<Model>("models/Corvette-F3.obj");
crewmate = std::make_shared<Model>("models/space_humster.obj"); crewmate = std::make_shared<Model>("models/space_humster.obj");
asteroid = std::make_shared<Model>("models/Asteroid_4_LOW_MODEL_.obj");
//shipModel = obj::loadModelFromFile("models/spaceship.obj"); //shipModel = obj::loadModelFromFile("models/spaceship.obj");
sphereModel = obj::loadModelFromFile("models/sphere.obj"); //sphereModel = obj::loadModelFromFile("models/sphere.obj");
cubeModel = obj::loadModelFromFile("models/cube.obj"); sphere = std::make_shared<Model>("models/sphere.obj");
cube = std::make_shared<Model>("models/cube.obj");
sphereContext.initFromOBJ(sphereModel); //sphereContext.initFromOBJ(sphereModel);
cubeContext.initFromOBJ(cubeModel); //cubeContext.initFromOBJ(cubeModel);
//shipContext.initFromOBJ(shipModel); //shipContext.initFromOBJ(shipModel);
shipTexture = Core::LoadTexture("textures/spaceship.png"); shipTexture = Core::LoadTexture("textures/spaceship.png");
sunTexture = Core::LoadTexture("textures/sun.png"); sunTexture = Core::LoadTexture("textures/sun.png");

View File

@ -69,17 +69,24 @@ public:
string number; string number;
string name = textures[i].type; string name = textures[i].type;
if (name == "texture_diffuse") if (name == "texture_diffuse")
number = std::to_string(diffuseNr++); glUniform1i(glGetUniformLocation(program, "diffuseTexture"), i);
//number = std::to_string(diffuseNr++);
else if (name == "texture_specular") else if (name == "texture_specular")
number = std::to_string(specularNr++); // transfer unsigned int to stream glUniform1i(glGetUniformLocation(program, "specularTexture"), i);
//number = std::to_string(specularNr++); // transfer unsigned int to stream
else if (name == "texture_normal") else if (name == "texture_normal")
number = std::to_string(normalNr++); // transfer unsigned int to stream glUniform1i(glGetUniformLocation(program, "normalTexture"), i);
//number = std::to_string(normalNr++); // transfer unsigned int to stream
else if (name == "texture_height") else if (name == "texture_height")
number = std::to_string(heightNr++); // transfer unsigned int to stream glUniform1i(glGetUniformLocation(program, "heightTexture"), i);
//number = std::to_string(heightNr++); // transfer unsigned int to stream
// now set the sampler to the correct texture unit // now set the sampler to the correct texture unit
//glUniform1i(glGetUniformLocation(program, (name + number).c_str()), i); //glUniform1i(glGetUniformLocation(program, (name + number).c_str()), i);
glUniform1i(glGetUniformLocation(program, "colorTexture"), i); //glUniform1i(glGetUniformLocation(program, "colorTexture"), i);
// and finally bind the texture // and finally bind the texture
glBindTexture(GL_TEXTURE_2D, textures[i].id); glBindTexture(GL_TEXTURE_2D, textures[i].id);
} }