|
|
@ -4,6 +4,7 @@
|
|
|
|
#include "ext.hpp"
|
|
|
|
#include "ext.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cmath>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Shader_Loader.h"
|
|
|
|
#include "Shader_Loader.h"
|
|
|
|
#include "Render_Utils.h"
|
|
|
|
#include "Render_Utils.h"
|
|
|
@ -23,20 +24,9 @@ const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
|
|
|
int WIDTH = 500, HEIGHT = 500;
|
|
|
|
int WIDTH = 500, HEIGHT = 500;
|
|
|
|
|
|
|
|
|
|
|
|
namespace models {
|
|
|
|
namespace models {
|
|
|
|
Core::RenderContext bedContext;
|
|
|
|
|
|
|
|
Core::RenderContext chairContext;
|
|
|
|
|
|
|
|
Core::RenderContext deskContext;
|
|
|
|
|
|
|
|
Core::RenderContext doorContext;
|
|
|
|
|
|
|
|
Core::RenderContext drawerContext;
|
|
|
|
|
|
|
|
Core::RenderContext marbleBustContext;
|
|
|
|
Core::RenderContext marbleBustContext;
|
|
|
|
Core::RenderContext materaceContext;
|
|
|
|
|
|
|
|
Core::RenderContext pencilsContext;
|
|
|
|
|
|
|
|
Core::RenderContext planeContext;
|
|
|
|
|
|
|
|
Core::RenderContext roomContext;
|
|
|
|
|
|
|
|
Core::RenderContext spaceshipContext;
|
|
|
|
Core::RenderContext spaceshipContext;
|
|
|
|
Core::RenderContext sphereContext;
|
|
|
|
Core::RenderContext sphereContext;
|
|
|
|
Core::RenderContext windowContext;
|
|
|
|
|
|
|
|
Core::RenderContext testContext;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GLuint depthMapFBO;
|
|
|
|
GLuint depthMapFBO;
|
|
|
@ -52,6 +42,7 @@ Core::Shader_Loader shaderLoader;
|
|
|
|
Core::RenderContext shipContext;
|
|
|
|
Core::RenderContext shipContext;
|
|
|
|
Core::RenderContext sphereContext;
|
|
|
|
Core::RenderContext sphereContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::list<Sun> suns;
|
|
|
|
Sun sun;
|
|
|
|
Sun sun;
|
|
|
|
GLuint VAO,VBO;
|
|
|
|
GLuint VAO,VBO;
|
|
|
|
|
|
|
|
|
|
|
@ -90,11 +81,18 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
|
|
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "cameraPos"), Spaceship::getInstance().cameraPos.x, Spaceship::getInstance().cameraPos.y, Spaceship::getInstance().cameraPos.z);
|
|
|
|
glUniform3f(glGetUniformLocation(program, "cameraPos"), Spaceship::getInstance().cameraPos.x, Spaceship::getInstance().cameraPos.y, Spaceship::getInstance().cameraPos.z);
|
|
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "sunDir"), sun.sunDir.x, sun.sunDir.y, sun.sunDir.z);
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "sunColor"), sun.sunColor.x, sun.sunColor.y, sun.sunColor.z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
|
|
|
|
const int NUM_LIGHTS = 23;
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
|
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 lightsPositions[NUM_LIGHTS];
|
|
|
|
|
|
|
|
glm::vec3 lightsColors[NUM_LIGHTS];
|
|
|
|
|
|
|
|
glm::vec3 lightsDirections[NUM_LIGHTS];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*glUniform3f(glGetUniformLocation(program, "sunDir"), sun.sunDir.x, sun.sunDir.y, sun.sunDir.z);
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "sunColor"), sun.sunColor.x, sun.sunColor.y, sun.sunColor.z);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightPos"), sun.sunPos.x, sun.sunPos.y, sun.sunPos.z);
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightColor"), sun.sunColor.x, sun.sunColor.y, sun.sunColor.z);
|
|
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), Spaceship::getInstance().spotlightConeDir.x, Spaceship::getInstance().spotlightConeDir.y, Spaceship::getInstance().spotlightConeDir.z);
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), Spaceship::getInstance().spotlightConeDir.x, Spaceship::getInstance().spotlightConeDir.y, Spaceship::getInstance().spotlightConeDir.z);
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightPos"), Spaceship::getInstance().spotlightPos.x, Spaceship::getInstance().spotlightPos.y, Spaceship::getInstance().spotlightPos.z);
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightPos"), Spaceship::getInstance().spotlightPos.x, Spaceship::getInstance().spotlightPos.y, Spaceship::getInstance().spotlightPos.z);
|
|
|
@ -128,7 +126,9 @@ void renderScene(GLFWwindow* window)
|
|
|
|
|
|
|
|
|
|
|
|
//space lamp
|
|
|
|
//space lamp
|
|
|
|
glUseProgram(programSun);
|
|
|
|
glUseProgram(programSun);
|
|
|
|
sun.draw();
|
|
|
|
for (Sun& s : suns) {
|
|
|
|
|
|
|
|
s.draw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(program);
|
|
|
|
glUseProgram(program);
|
|
|
|
|
|
|
|
|
|
|
@ -138,35 +138,14 @@ void renderScene(GLFWwindow* window)
|
|
|
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
|
|
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
|
|
|
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);
|
|
|
|
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);
|
|
|
|
|
|
|
|
|
|
|
|
drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::deskContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::doorContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::drawerContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f);
|
|
|
|
drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f);
|
|
|
|
drawObjectPBR(models::materaceContext, glm::mat4(), glm::vec3(0.9f, 0.9f, 0.9f), 0.8f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::pencilsContext, glm::mat4(), glm::vec3(0.10039f, 0.018356f, 0.001935f), 0.1f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(0.9f, 0.9f, 0.9f), 0.8f, 0.0f);
|
|
|
|
|
|
|
|
drawObjectPBR(models::windowContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//drawObjectColor(shipContext,
|
|
|
|
|
|
|
|
// glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()),
|
|
|
|
|
|
|
|
// glm::vec3(0.3, 0.3, 0.5)
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
drawObjectPBR(shipContext,
|
|
|
|
drawObjectPBR(shipContext,
|
|
|
|
Spaceship::getInstance().calculateModelMatrix(),
|
|
|
|
Spaceship::getInstance().calculateModelMatrix(),
|
|
|
|
glm::vec3(0.3, 0.3, 0.5),
|
|
|
|
glm::vec3(0.3, 0.3, 0.5),
|
|
|
|
0.2,1.0
|
|
|
|
0.2,1.0
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//test depth buffer
|
|
|
|
|
|
|
|
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
//glUseProgram(programTest);
|
|
|
|
|
|
|
|
//glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
|
|
//glBindTexture(GL_TEXTURE_2D, depthMap);
|
|
|
|
|
|
|
|
//Core::DrawContext(models::testContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
glUseProgram(0);
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -190,6 +169,30 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
|
|
|
context.initFromAssimpMesh(scene->mMeshes[0]);
|
|
|
|
context.initFromAssimpMesh(scene->mMeshes[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createSuns() {
|
|
|
|
|
|
|
|
sun = Sun(programSun, models::sphereContext, glm::vec3(0, 2, 0), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, 1);
|
|
|
|
|
|
|
|
suns.push_back(sun);
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-80, 20, 50), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(1.0f, 0.8f, 0.2f), 4.0));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(50, 40, -30), glm::vec3(-0.73633f, 0.451106, 0.023226f), glm::vec3(0.9f, 0.5f, 0.1f), 3.5));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(0, -60, 100), glm::vec3(-0.53633f, 0.551106, 0.043226f), glm::vec3(0.8f, 0.2f, 0.2f), 4.5));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(20, 80, -70), glm::vec3(0.33633f, 0.651106, 0.063226f), glm::vec3(0.5f, 0.7f, 0.9f), 3.8));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-60, -20, 30), glm::vec3(-0.23633f, 0.751106, 0.083226f), glm::vec3(0.7f, 0.2f, 0.7f), 4.2));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(70, -50, -80), glm::vec3(-0.03633f, 0.851106, 0.103226f), glm::vec3(0.1f, 0.3f, 0.9f), 3.9));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(10, 30, 60), glm::vec3(0.13633f, -0.951106, -0.123226f), glm::vec3(0.6f, 0.9f, 0.4f), 4.3));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-40, -80, -50), glm::vec3(0.33633f, -0.851106, -0.143226f), glm::vec3(0.7f, 0.5f, 0.2f), 3.7));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(90, 70, 20), glm::vec3(0.53633f, -0.751106, -0.163226f), glm::vec3(0.4f, 0.1f, 0.9f), 4.1));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-30, 10, -40), glm::vec3(0.73633f, -0.651106, -0.183226f), glm::vec3(0.8f, 0.4f, 0.1f), 4.4));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(150, -100, 80), glm::vec3(0.33633f, -0.951106, -0.143226f), glm::vec3(0.2f, 0.8f, 0.5f), 3.9));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-120, 50, -60), glm::vec3(0.73633f, 0.551106, 0.103226f), glm::vec3(0.9f, 0.2f, 0.7f), 3.6));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(0, 120, -150), glm::vec3(-0.23633f, -0.751106, 0.083226f), glm::vec3(0.5f, 0.6f, 0.9f), 3.4));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-180, -50, 120), glm::vec3(0.13633f, 0.351106, -0.003226f), glm::vec3(0.7f, 0.9f, 0.2f), 4.2));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(60, -150, 180), glm::vec3(-0.93633f, -0.451106, -0.023226f), glm::vec3(0.3f, 0.7f, 0.8f), 3.8));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(100, 80, -120), glm::vec3(0.53633f, -0.651106, 0.163226f), glm::vec3(0.8f, 0.1f, 0.4f), 4.5));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-50, -180, 150), glm::vec3(-0.33633f, 0.951106, -0.083226f), glm::vec3(0.4f, 0.8f, 0.6f), 3.5));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(200, 150, -100), glm::vec3(0.03633f, 0.151106, 0.103226f), glm::vec3(0.6f, 0.2f, 0.9f), 3.9));
|
|
|
|
|
|
|
|
suns.push_back(Sun(programSun, models::sphereContext, glm::vec3(-150, -100, -50), glm::vec3(0.83633f, -0.251106, -0.123226f), glm::vec3(0.7f, 0.5f, 0.8f), 4.1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init(GLFWwindow* window)
|
|
|
|
void init(GLFWwindow* window)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
@ -203,22 +206,12 @@ void init(GLFWwindow* window)
|
|
|
|
loadModelToContext("./models/spaceship.obj", shipContext);
|
|
|
|
loadModelToContext("./models/spaceship.obj", shipContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadModelToContext("./models/bed.obj", models::bedContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/chair.obj", models::chairContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/desk.obj", models::deskContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/door.obj", models::doorContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/drawer.obj", models::drawerContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
|
|
|
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
|
|
|
loadModelToContext("./models/materace.obj", models::materaceContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/pencils.obj", models::pencilsContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/plane.obj", models::planeContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/room.obj", models::roomContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/GameUtils::spaceship.obj", models::spaceshipContext);
|
|
|
|
loadModelToContext("./models/GameUtils::spaceship.obj", models::spaceshipContext);
|
|
|
|
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
|
|
|
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
|
|
|
loadModelToContext("./models/window.obj", models::windowContext);
|
|
|
|
|
|
|
|
loadModelToContext("./models/test.obj", models::testContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sun = Sun(programSun, models::sphereContext);
|
|
|
|
createSuns();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void shutdown(GLFWwindow* window)
|
|
|
|
void shutdown(GLFWwindow* window)
|
|
|
|