Skip to content

Commit 3dda65e

Browse files
committed
spot light stuff done except it sucks
1 parent 59a3348 commit 3dda65e

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

include/app.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class App
101101
entt::entity ePlane;
102102
entt::entity eSelectPoint;
103103
entt::entity eDragArrow;
104+
entt::entity eSpotLight;
104105

105106
Vector3f selectPoint;
106107
entt::entity eSelected = entt::null;

reports/2023-03-16-22-06-47.png

91.7 KB
Loading

reports/project7.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33

44
![](2023-03-13-23-29-41.png)
55

6+
![](2023-03-16-22-06-47.png)
7+
68
> What you implemented
79
8-
- Point light shadows
10+
- Spot light shadows
11+
- Control spot light orientation with shift + left click
912

1013
> What you could not implement
1114
12-
WIP
15+
- There are issues with the spot light shadow projection that I don't understand :(
1316

1417
> Additional functionalities beyond project requirements
1518
16-
WIP
19+
- Point light shadows (they are implemented but not accessible)
1720

1821
> How to use your implementation
1922

resources/shaders/basic.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,11 @@ void main() {
158158
// C *= shadow;
159159
// float shadow = textureProj(uSpotShadowMap, vec4(v.x, v.y, v.z / uFarPlane, v.w));
160160
// C = vec3(shadow);
161-
float shadow = textureProj(uSpotShadowMap, vec4(
161+
float shadow = texture(uSpotShadowMap, vec3(
162162
(v.x / 2.0) / v.w + 0.5,
163163
(v.y / 2.0) / v.w + 0.5,
164-
dist / uFarPlane - 0.005, 1.0));
164+
dist / uFarPlane - 0.005));
165+
// float shadow = texture(uSpotShadowMap, v.xyz / v.w);
165166
C *= shadow;
166167

167168
C = mix(C, mat.emissionColor, mat.emissionFactor);

src/app.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ App::App(cxxopts::ParseResult& args) {
306306
this->spotShadowCamera->orbitDist(5.0f);
307307
this->spotShadowCamera->orbitTheta(tau4);
308308
this->spotShadowCamera->orbitPhi(0.0f);
309-
entt::entity e = this->makeSpotLight(
309+
this->eSpotLight = this->makeSpotLight(
310310
this->spotShadowCamera->pos,
311311
-direction(this->spotShadowCamera->rot),
312312
Vector3f(1.0f, 1.0f, 0.9f),
@@ -615,6 +615,7 @@ void App::onClick(int button, bool pressed) {
615615
case GLFW_MOUSE_BUTTON_LEFT:
616616
this->mouseLeft = pressed;
617617
this->camera->dragStart();
618+
this->spotShadowCamera->dragStart();
618619
break;
619620
case GLFW_MOUSE_BUTTON_RIGHT:
620621
this->mouseRight = pressed;
@@ -745,7 +746,14 @@ void App::simulate(float dt) {
745746
dragDelta = panDelta * 2.0f;
746747
dragDelta.y() *= -1.0f;
747748
}
748-
this->camera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
749+
if (this->pressedKeys.count(GLFW_KEY_LEFT_SHIFT)) {
750+
this->spotShadowCamera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
751+
Light& spotLight = this->reg.get<Light>(this->eSpotLight);
752+
spotLight.pos = this->spotShadowCamera->pos;
753+
spotLight.dir = -direction(this->spotShadowCamera->rot);
754+
} else {
755+
this->camera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
756+
}
749757

750758
// Physics simulation
751759
// constexpr float dampingFactor = 0.25f;
@@ -1189,15 +1197,15 @@ entt::entity App::makeSpotLight(const Vector3f& pos, const Vector3f& dir, const
11891197

11901198
this->reg.emplace<uLight>(e);
11911199

1192-
DebugRay& debugRay = this->reg.emplace<DebugRay>(e);
1193-
debugRay.pos = pos;
1194-
debugRay.rot = vec3(pointSphere(dir));
1200+
// DebugRay& debugRay = this->reg.emplace<DebugRay>(e);
1201+
// debugRay.pos = pos;
1202+
// debugRay.rot = vec3(pointSphere(dir));
11951203

1196-
RayTransform& rayTransform = this->reg.emplace<RayTransform>(e);
1197-
rayTransform.transform = debugRay.transform();
1204+
// RayTransform& rayTransform = this->reg.emplace<RayTransform>(e);
1205+
// rayTransform.transform = debugRay.transform();
11981206

1199-
DebugColor& debugColor = this->reg.emplace<DebugColor>(e);
1200-
debugColor.color = {1.0f, 1.0f, 0.2f, 1.0f};
1207+
// DebugColor& debugColor = this->reg.emplace<DebugColor>(e);
1208+
// debugColor.color = {1.0f, 1.0f, 0.2f, 1.0f};
12011209

12021210
return e;
12031211
}

0 commit comments

Comments
 (0)