-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.cpp
More file actions
46 lines (39 loc) · 1.83 KB
/
Light.cpp
File metadata and controls
46 lines (39 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Light.h"
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
using namespace glm;
// Required for constexpr static members (pre-C++17 inline)
constexpr float PointLight::PRESETS[3];
// ================================================================
// PointLight
// ================================================================
void PointLight::apply(Shader& shader) {
shader.setVec3 ("pointLightPos", position.x, position.y, position.z);
shader.setVec3 ("pointLightColor", color.x, color.y, color.z);
shader.setFloat("pointBrightness", brightness);
}
void PointLight::cycleIntensity() {
presetIndex = (presetIndex + 1) % 3;
brightness = PRESETS[presetIndex];
const char* names[] = { "Low", "Medium", "High" };
std::cout << "[PointLight] Intensity: " << names[presetIndex] << std::endl;
}
// ================================================================
// DirectionalLight
// ================================================================
void DirectionalLight::apply(Shader& shader) {
shader.setVec3 ("dirLightDir", direction.x, direction.y, direction.z);
shader.setVec3 ("dirLightColor", color.x, color.y, color.z);
shader.setFloat("dirBrightness", brightness);
}
// ================================================================
// SpotLight
// ================================================================
void SpotLight::apply(Shader& shader) {
shader.setVec3 ("spotPos", position.x, position.y, position.z);
shader.setVec3 ("spotDir", direction.x, direction.y, direction.z);
shader.setVec3 ("spotColor", color.x, color.y, color.z);
shader.setFloat("spotBrightness", brightness);
shader.setFloat("spotCutOff", glm::cos(glm::radians(cutOff)));
shader.setFloat("spotOuterCutOff",glm::cos(glm::radians(outerCutOff)));
}