add spaceship

This commit is contained in:
Szymon Szczubkowski 2024-01-25 23:51:55 +01:00
parent a9de5e6a71
commit 1890648b26
12 changed files with 34 additions and 8 deletions

BIN
cw_8/models/spaceship.fbx Normal file

Binary file not shown.

View File

@ -27,6 +27,15 @@ namespace texture {
GLuint planet_ao;
GLuint planet_normal;
GLuint planet_roughness;
GLuint mars_albedo;
GLuint mars_normal;
GLuint mars_ao;
GLuint ship_albedo;
GLuint ship_normal;
GLuint ship_ao;
GLuint ship_roughness;
}
float aspectRatio = 1.f;
@ -45,7 +54,7 @@ glm::mat4 createPerspectiveMatrix();
glm::mat4 createCameraMatrix();
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix);
void drawObjectPlanet(Core::RenderContext& context, glm::mat4 modelMatrix);
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint ao, GLuint normal, GLuint roughness);
void init(GLFWwindow* window)
{
@ -58,7 +67,7 @@ void init(GLFWwindow* window)
//load models here
loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/spaceship.fbx", shipContext);
loadModelToContext("./models/sun.glb", sunContext);
@ -73,6 +82,16 @@ void init(GLFWwindow* window)
texture::planet_ao = Core::LoadTexture("textures/planet/ao.jpg");
texture::planet_normal = Core::LoadTexture("textures/planet/normal.jpg");
texture::planet_roughness = Core::LoadTexture("textures/planet/roughness.jpg");
texture::mars_albedo = Core::LoadTexture("textures/mars/albedo.jpg");
texture::mars_normal = Core::LoadTexture("textures/mars/normal.png");
texture::mars_ao = Core::LoadTexture("textures/mars/ao.png");
texture::ship_albedo = Core::LoadTexture("textures/ship/albedo.png");
texture::ship_ao = Core::LoadTexture("textures/ship/ao.png");
texture::ship_normal = Core::LoadTexture("textures/ship/normal.png");
texture::ship_roughness = Core::LoadTexture("textures/ship/roughness.png");
}
void renderScene(GLFWwindow* window){
@ -85,7 +104,14 @@ void renderScene(GLFWwindow* window){
//desired objects go here
drawObjectSun(sunContext, glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time/10));
drawObjectPlanet(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-2*time));
drawObjectPBR(shipContext, glm::translate(cameraPos) * glm::translate(glm::vec3(0.85f, -0.25f, 0.f))
* glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 0, 1))
* glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 1, 0))
* glm::rotate(glm::mat4(1.0f), glm::radians(-5.f), glm::vec3(1, 0, 0))
* glm::scale(glm::vec3(0.015f)),
texture::ship_albedo, texture::ship_normal, texture::ship_ao, texture::ship_roughness);
drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::planet_albedo, texture::planet_normal, texture::planet_ao, texture::planet_roughness);
drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(-4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::mars_albedo, texture::mars_normal, texture::mars_ao, 0);
//desired objects end here
glUseProgram(0);
glfwSwapBuffers(window);
@ -107,7 +133,7 @@ void processInput(GLFWwindow* window)
cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
}
void drawObjectPlanet(Core::RenderContext& context, glm::mat4 modelMatrix) {
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
@ -118,10 +144,10 @@ void drawObjectPlanet(Core::RenderContext& context, glm::mat4 modelMatrix) {
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
glUniform3f(glGetUniformLocation(program, "lightColor"), 300, 300, 300);
Core::SetActiveTexture(texture::planet_albedo, "albedoMap", program, 0);
Core::SetActiveTexture(texture::planet_normal, "normalMap", program, 1);
Core::SetActiveTexture(texture::planet_ao, "aoMap", program, 2);
Core::SetActiveTexture(texture::planet_roughness, "roughnessMap", program, 3);
Core::SetActiveTexture(albedo, "albedoMap", program, 0);
Core::SetActiveTexture(normal, "normalMap", program, 1);
Core::SetActiveTexture(ao, "aoMap", program, 2);
Core::SetActiveTexture(roughness, "roughnessMap", program, 3);
Core::DrawContext(context);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB

BIN
cw_8/textures/mars/ao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 MiB

BIN
cw_8/textures/ship/ao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 MiB