Skip to content

Commit 2716773

Browse files
committed
fix: fix light direction and spotlight
1 parent 5ca26fb commit 2716773

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

assets/shaders/lit.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ vec3 calcLight(
117117

118118
if(light.type == LIGHT_SPOT) {
119119
float theta = dot(L, normalize(-light.direction));
120-
float innerCos = light.spotAngles.x;
121-
float outerCos = light.spotAngles.y;
120+
float innerCos = cos(light.spotAngles.x);
121+
float outerCos = cos(light.spotAngles.y);
122122
float epsilon = innerCos - outerCos;
123123
float spot = clamp((theta - outerCos) / epsilon, 0.0, 1.0);
124124
attenuation *= spot;

src/common/systems/forward-renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace our {
161161
// assume default light direction points to - z direction in local space
162162
// so away from the camera if the light is attached to the camera
163163
// this could be useful for rifle flashlight for example
164-
lightData.direction = glm::normalize(glm::vec3(localToWorld * glm::vec4(0, 0, 1, 0)));
164+
lightData.direction = glm::normalize(glm::vec3(localToWorld * glm::vec4(0, 0, -1, 0)));
165165
lightData.attenuation = light->attenuation;
166166
lightData.spotAngles = light->spotAngles;
167167
sceneLights.push_back(lightData);

0 commit comments

Comments
 (0)