spaceship light

This commit is contained in:
Pawel Felcyn 2024-01-03 20:56:56 +01:00
parent 5ee26a6c64
commit 5c8faba1f8
2 changed files with 12 additions and 16 deletions

View File

@ -8,6 +8,11 @@ public:
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f); glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f); glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9) * 3;
float spotlightPhi = 3.14 / 4;
glm::mat4 calculateModelMatrix() { glm::mat4 calculateModelMatrix() {
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
@ -46,5 +51,8 @@ public:
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0)); spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0)); spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
spotlightConeDir = spaceshipDir;
} }
}; };

View File

@ -66,13 +66,6 @@ float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0); glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6); glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6);
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3;
float spotlightPhi = 3.14 / 4;
float lastTime = -1.f; float lastTime = -1.f;
float deltaTime = 0.f; float deltaTime = 0.f;
@ -145,10 +138,10 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z); glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z); glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spaceship.spotlightConeDir.x, spaceship.spotlightConeDir.y, spaceship.spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z); glUniform3f(glGetUniformLocation(program, "spotlightPos"), spaceship.spotlightPos.x, spaceship.spotlightPos.y, spaceship.spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship.spotlightColor.x, spaceship.spotlightColor.y, spaceship.spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship.spotlightPhi);
Core::DrawContext(context); Core::DrawContext(context);
} }
@ -214,11 +207,6 @@ void renderScene(GLFWwindow* window)
0.2,1.0 0.2,1.0
); );
spotlightPos = spaceship.spaceshipPos + 0.2 * spaceship.spaceshipDir;
spotlightConeDir = spaceship.spaceshipDir;
//test depth buffer //test depth buffer
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glUseProgram(programTest); //glUseProgram(programTest);