Add support for spot lights with a fixed direction in model space

This commit is contained in:
Peder Bergebakken Sundt 2019-03-28 09:38:16 +01:00
parent 383d5d3f62
commit 199765e112
2 changed files with 4 additions and 1 deletions

View File

@ -208,7 +208,9 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
uint id = node->lightID;
lights[id].position = vec3(node->MV * vec4(vec3(0.0), 1.0));
lights[id].is_spot = node->nodeType == SPOT_LIGHT;
lights[id].spot_direction = node->spot_direction; // MV space
lights[id].spot_direction = (node->transform_spot)
? node->spot_direction // MV space
: vec3(node->MVnormal * vec4(node->spot_direction, 1.0));// Model space
lights[id].spot_cuttof_cos = node->spot_cuttof_cos;
lights[id].attenuation = node->attenuation;
lights[id].color = node->light_color;

View File

@ -57,6 +57,7 @@ struct SceneNode {
float spot_cuttof_cos = glm::cos(glm::radians(1.5));
vec3 spot_direction = vec3(0.0); // in MV space, must be normalized, automatically updated by spot_target
SceneNode* spot_target = nullptr; // spot will follow this node
bool transform_spot = false; // if true, spot_direction will be in model space.
// The node's position and rotation relative to its parent
vec3 position = vec3(0, 0, 0);