Fix spot lights

This commit is contained in:
MrLetsplay 2022-10-13 11:15:52 +02:00
parent d7ea3bb62e
commit 0944fc6206
4 changed files with 13 additions and 5 deletions

View File

@ -268,6 +268,7 @@ int start() {
glUniform3fv(glGetUniformLocation(kekData.shader->id, (prefix + "position").c_str()), 1, glm::value_ptr(l->getPosition()));
glUniform3fv(glGetUniformLocation(kekData.shader->id, (prefix + "direction").c_str()), 1, glm::value_ptr(l->direction));
glUniform3fv(glGetUniformLocation(kekData.shader->id, (prefix + "attenuation").c_str()), 1, glm::value_ptr(glm::vec3(l->constant, l->linear, l->quadratic)));
glUniform2fv(glGetUniformLocation(kekData.shader->id, (prefix + "cutoff").c_str()), 1, glm::value_ptr(glm::vec2(glm::cos(l->innerCutoff), glm::cos(l->outerCutoff))));
numSpotLights++;
break;
}

View File

@ -43,11 +43,13 @@ void DirectionalLight::lookAt(glm::vec3 direction){
this->direction = direction;
}
SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic): Light(color) {
SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff): Light(color) {
this->direction = direction;
this->constant = constant;
this->linear = linear;
this->quadratic = quadratic;
this->innerCutoff = innerCutoff;
this->outerCutoff = outerCutoff;
}
SpotLight::~SpotLight() {

View File

@ -59,8 +59,9 @@ class SpotLight: public Light, public DefaultObject {
public:
glm::vec3 direction;
float constant, linear, quadratic;
float innerCutoff, outerCutoff;
SpotLight(glm::vec3 color, glm::vec3 direction, float constantFalloff, float linearFalloff, float quadraticFalloff);
SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff);
~SpotLight();

View File

@ -26,11 +26,15 @@ int main(int argc, char **argv) {
scene->addObject(test2);
}
//PointLight *light = new PointLight(glm::vec3(1), 1, 1, 1);
//PointLight *light = new PointLight(glm::vec3(1), 1, 0, 1);
//scene->lights->add(light);
DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1));
scene->lights->add(l);
//DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1));
//scene->lights->add(l);
SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f));
spot->moveTo(glm::vec3(0, 0, 5));
scene->lights->add(spot);
Engine::setActiveScene(scene);