Skip to content

Commit

Permalink
spot light stuff done except it sucks
Browse files Browse the repository at this point in the history
  • Loading branch information
benpm committed Mar 18, 2023
1 parent 59a3348 commit 3dda65e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class App
entt::entity ePlane;
entt::entity eSelectPoint;
entt::entity eDragArrow;
entt::entity eSpotLight;

Vector3f selectPoint;
entt::entity eSelected = entt::null;
Expand Down
Binary file added reports/2023-03-16-22-06-47.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions reports/project7.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

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

![](2023-03-16-22-06-47.png)

> What you implemented
- Point light shadows
- Spot light shadows
- Control spot light orientation with shift + left click

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

> Additional functionalities beyond project requirements
WIP
- Point light shadows (they are implemented but not accessible)

> How to use your implementation
Expand Down
5 changes: 3 additions & 2 deletions resources/shaders/basic.frag
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ void main() {
// C *= shadow;
// float shadow = textureProj(uSpotShadowMap, vec4(v.x, v.y, v.z / uFarPlane, v.w));
// C = vec3(shadow);
float shadow = textureProj(uSpotShadowMap, vec4(
float shadow = texture(uSpotShadowMap, vec3(
(v.x / 2.0) / v.w + 0.5,
(v.y / 2.0) / v.w + 0.5,
dist / uFarPlane - 0.005, 1.0));
dist / uFarPlane - 0.005));
// float shadow = texture(uSpotShadowMap, v.xyz / v.w);
C *= shadow;

C = mix(C, mat.emissionColor, mat.emissionFactor);
Expand Down
26 changes: 17 additions & 9 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ App::App(cxxopts::ParseResult& args) {
this->spotShadowCamera->orbitDist(5.0f);
this->spotShadowCamera->orbitTheta(tau4);
this->spotShadowCamera->orbitPhi(0.0f);
entt::entity e = this->makeSpotLight(
this->eSpotLight = this->makeSpotLight(
this->spotShadowCamera->pos,
-direction(this->spotShadowCamera->rot),
Vector3f(1.0f, 1.0f, 0.9f),
Expand Down Expand Up @@ -615,6 +615,7 @@ void App::onClick(int button, bool pressed) {
case GLFW_MOUSE_BUTTON_LEFT:
this->mouseLeft = pressed;
this->camera->dragStart();
this->spotShadowCamera->dragStart();
break;
case GLFW_MOUSE_BUTTON_RIGHT:
this->mouseRight = pressed;
Expand Down Expand Up @@ -745,7 +746,14 @@ void App::simulate(float dt) {
dragDelta = panDelta * 2.0f;
dragDelta.y() *= -1.0f;
}
this->camera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
if (this->pressedKeys.count(GLFW_KEY_LEFT_SHIFT)) {
this->spotShadowCamera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
Light& spotLight = this->reg.get<Light>(this->eSpotLight);
spotLight.pos = this->spotShadowCamera->pos;
spotLight.dir = -direction(this->spotShadowCamera->rot);
} else {
this->camera->control(-this->mouseDeltaPos * dt * 0.15f, dragDelta, keyboardDelta * dt * 20.0f);
}

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

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

DebugRay& debugRay = this->reg.emplace<DebugRay>(e);
debugRay.pos = pos;
debugRay.rot = vec3(pointSphere(dir));
// DebugRay& debugRay = this->reg.emplace<DebugRay>(e);
// debugRay.pos = pos;
// debugRay.rot = vec3(pointSphere(dir));

RayTransform& rayTransform = this->reg.emplace<RayTransform>(e);
rayTransform.transform = debugRay.transform();
// RayTransform& rayTransform = this->reg.emplace<RayTransform>(e);
// rayTransform.transform = debugRay.transform();

DebugColor& debugColor = this->reg.emplace<DebugColor>(e);
debugColor.color = {1.0f, 1.0f, 0.2f, 1.0f};
// DebugColor& debugColor = this->reg.emplace<DebugColor>(e);
// debugColor.color = {1.0f, 1.0f, 0.2f, 1.0f};

return e;
}

0 comments on commit 3dda65e

Please sign in to comment.