Compare commits

...

4 Commits

Author SHA1 Message Date
Pawel Felcyn
60a5c80adc sun shines brughter 2024-01-04 21:48:56 +01:00
Pawel Felcyn
656756dc0a delete unnecessary models 2024-01-04 21:38:08 +01:00
Pawel Felcyn
fe7fad1258 one sun shines 2024-01-04 21:35:34 +01:00
Pawel Felcyn
7a876100dd create multiple suns 2024-01-04 20:51:01 +01:00
5 changed files with 60 additions and 62 deletions

View File

@ -6,15 +6,20 @@
class Sun class Sun
{ {
public: public:
glm::vec3 sunPos = glm::vec3(0, 2, 0); glm::vec3 sunPos;
glm::vec3 sunDir = glm::vec3(-0.93633f, 0.351106, 0.003226f); glm::vec3 sunDir;
glm::vec3 sunColor = glm::vec3(0.9f, 0.9f, 0.7f) * 5; glm::vec3 sunColor;
double scale;
GLuint program; GLuint program;
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
Sun(GLuint program, Core::RenderContext sphereContext) { Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) {
this->program = program; this->program = program;
this->sphereContext = sphereContext; this->sphereContext = sphereContext;
this->sunPos = pos;
this->sunDir = dir;
this->sunColor = color;
this->scale = scale;
} }
Sun(){} Sun(){}
@ -22,7 +27,7 @@ public:
void draw() { void draw() {
glUseProgram(program); glUseProgram(program);
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix(); glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * glm::translate(sunPos) * glm::scale(glm::vec3(0.1)); glm::mat4 transformation = viewProjectionMatrix * glm::translate(sunPos) * glm::scale(glm::vec3(scale));
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform3f(glGetUniformLocation(program, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2); glUniform3f(glGetUniformLocation(program, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2);
glUniform1f(glGetUniformLocation(program, "exposition"), 1.f); glUniform1f(glGetUniformLocation(program, "exposition"), 1.f);

View File

@ -9,8 +9,8 @@ uniform vec3 cameraPos;
uniform vec3 color; uniform vec3 color;
uniform vec3 sunDir; //uniform vec3 sunDir;
uniform vec3 sunColor; //uniform vec3 sunColor;
uniform vec3 lightPos; uniform vec3 lightPos;
uniform vec3 lightColor; uniform vec3 lightColor;
@ -114,7 +114,7 @@ void main()
vec3 ambient = AMBIENT*color; vec3 ambient = AMBIENT*color;
vec3 attenuatedlightColor = lightColor/pow(length(lightPos-worldPos),2); vec3 attenuatedlightColor = lightColor/pow(length(lightPos-worldPos),2);
vec3 ilumination; vec3 ilumination;
ilumination = ambient+PBRLight(lightDir,attenuatedlightColor,normal,viewDir); ilumination = ambient+PBRLight(lightDir,attenuatedlightColor * 300,normal,viewDir);
//flashlight //flashlight
//vec3 spotlightDir= normalize(spotlightDirTS); //vec3 spotlightDir= normalize(spotlightDirTS);
@ -126,7 +126,7 @@ void main()
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun //sun
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir); //ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1); outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);

View File

@ -15,12 +15,12 @@ out vec3 worldPos;
uniform vec3 lightPos; uniform vec3 lightPos;
uniform vec3 spotlightPos; uniform vec3 spotlightPos;
uniform vec3 cameraPos; uniform vec3 cameraPos;
uniform vec3 sunDir; //uniform vec3 sunDir;
out vec3 viewDirTS; out vec3 viewDirTS;
out vec3 lightDirTS; out vec3 lightDirTS;
out vec3 spotlightDirTS; out vec3 spotlightDirTS;
out vec3 sunDirTS; //out vec3 sunDirTS;
void main() void main()
{ {
@ -38,6 +38,6 @@ void main()
lightDirTS = TBN*L; lightDirTS = TBN*L;
vec3 SL = normalize(spotlightPos-worldPos); vec3 SL = normalize(spotlightPos-worldPos);
spotlightDirTS = TBN*SL; spotlightDirTS = TBN*SL;
sunDirTS = TBN*sunDir; //sunDirTS = TBN*sunDir;
} }

View File

@ -133,7 +133,7 @@ glm::mat4 Core::createPerspectiveMatrix()
glm::mat4 perspectiveMatrix; glm::mat4 perspectiveMatrix;
float n = 0.05; float n = 0.05;
float f = 20.; float f = 200.;
float a1 = glm::min(GameUtils::getInstance().aspectRatio, 1.f); float a1 = glm::min(GameUtils::getInstance().aspectRatio, 1.f);
float a2 = glm::min(1 / GameUtils::getInstance().aspectRatio, 1.f); float a2 = glm::min(1 / GameUtils::getInstance().aspectRatio, 1.f);
perspectiveMatrix = glm::mat4({ perspectiveMatrix = glm::mat4({

View File

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