From aa75b018f3b97c72b57de68867417cbda51439c3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 3 Dec 2022 03:41:32 +0000 Subject: Initial commit of the shadow map generator and shadows render interface Lots of hard coding, buggy in places, far from great, but the basics work. --- game/terrain.cpp | 8 ++++++++ game/terrain.h | 1 + game/vehicles/railVehicle.cpp | 6 ++++++ game/vehicles/railVehicle.h | 2 ++ game/vehicles/railVehicleClass.cpp | 7 +++++++ game/vehicles/railVehicleClass.h | 2 ++ game/vehicles/train.cpp | 5 +++++ game/vehicles/train.h | 2 ++ 8 files changed, 33 insertions(+) (limited to 'game') diff --git a/game/terrain.cpp b/game/terrain.cpp index 31f7fb1..f798254 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -93,3 +94,10 @@ Terrain::render(const SceneShader & shader) const water->bind(); meshes.apply(&Mesh::Draw); } + +void +Terrain::shadows(const ShadowMapper & shadowMapper) const +{ + shadowMapper.fixedPoint.use(); + meshes.apply(&Mesh::Draw); +} diff --git a/game/terrain.h b/game/terrain.h index 70f947c..879d173 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -16,6 +16,7 @@ public: explicit Terrain(std::shared_ptr); void render(const SceneShader & shader) const override; + void shadows(const ShadowMapper &) const override; void tick(TickDuration) override; float waveCycle {0.F}; diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 0cf4e72..bcde68f 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -17,6 +17,12 @@ RailVehicle::render(const SceneShader & shader) const rvClass->render(shader, location, bogies); } +void +RailVehicle::shadows(const ShadowMapper & shadowMapper) const +{ + rvClass->shadows(shadowMapper, location); +} + void RailVehicle::move(const Train * t, float & trailBy) { diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index 39900cc..f172a28 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -10,6 +10,7 @@ #include class SceneShader; +class ShadowMapper; class Ray; class Train; @@ -20,6 +21,7 @@ public: void move(const Train *, float & trailBy); void render(const SceneShader & shader) const override; + void shadows(const ShadowMapper & shadowMapper) const override; [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; Location location; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 5bcdc6e..dff1416 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -1,5 +1,6 @@ #include "railVehicleClass.h" #include "gfx/gl/sceneShader.h" +#include "gfx/gl/shadowMapper.h" #include "gfx/models/mesh.h" #include "gfx/models/obj.h" #include "gfx/models/texture.h" @@ -50,6 +51,12 @@ RailVehicleClass::render( bogies[b]->Draw(); } } +void +RailVehicleClass::shadows(const ShadowMapper & shadowMapper, const Location & location) const +{ + shadowMapper.dynamicPoint.use(location); + bodyMesh->Draw(); +} float RailVehicleClass::bogieOffset(ObjParser & o) diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 7249e76..bd74ab9 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -6,6 +6,7 @@ #include class SceneShader; +class ShadowMapper; class Texture; class ObjParser; class Location; @@ -15,6 +16,7 @@ public: explicit RailVehicleClass(const std::string & name); void render(const SceneShader &, const Location &, const std::array &) const; + void shadows(const ShadowMapper &, const Location &) const; std::array bogies; Mesh::Ptr bodyMesh; diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index 8fb48f5..0332c04 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -16,6 +16,11 @@ Train::render(const SceneShader & shader) const { apply(&Renderable::render, shader); } +void +Train::shadows(const ShadowMapper & shadowMapper) const +{ + apply(&Renderable::shadows, shadowMapper); +} Location Train::getBogiePosition(float linkDist, float dist) const diff --git a/game/vehicles/train.h b/game/vehicles/train.h index dfdcf62..91f7ddb 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -14,6 +14,7 @@ #include class SceneShader; +class ShadowMapper; class Ray; class Train : public Vehicle, public Collection, public Can, public Can { @@ -27,6 +28,7 @@ public: } void render(const SceneShader & shader) const override; + void shadows(const ShadowMapper & shadowMapper) const override; [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; -- cgit v1.2.3