Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Top-down view: a wall seen from the player's side stays whole, and the room cut reaches under floors and bridges outdoors

Alan Saundersebef7bf04f51
diff --git a/apps/openmw/mwlua/camerabindings.cpp b/apps/openmw/mwlua/camerabindings.cpp
index 60c53cc..92293ba 100644
--- a/apps/openmw/mwlua/camerabindings.cpp
+++ b/apps/openmw/mwlua/camerabindings.cpp
@@ -81,6 +81,9 @@ namespace MWLua
ids->push_back(getId(ptr));
return LObjectList{ std::move(ids) };
};
+ // Isowind: the radius around the player within which the top-down camera cuts the room (ceilings and upper
+ // floors over them, the walls in the way), indoors and under cover outdoors; 0 where nothing is cut
+ api["getCutawayRadius"] = [renderingManager]() { return renderingManager->getCutawayRadius(); };
api["getThirdPersonDistance"] = [camera]() { return camera->getCameraDistance(); };
api["setPreferredThirdPersonDistance"]
diff --git a/apps/openmw/mwrender/occlusionfader.cpp b/apps/openmw/mwrender/occlusionfader.cpp
index cf9a97b..80fb4b1 100644
--- a/apps/openmw/mwrender/occlusionfader.cpp
+++ b/apps/openmw/mwrender/occlusionfader.cpp
@@ -2,6 +2,7 @@
#include <algorithm>
#include <array>
+#include <cmath>
#include <osg/BlendFunc>
#include <osg/Group>
@@ -28,6 +29,13 @@ namespace MWRender
// How long something must have stopped being in the way before it fades back, so walking past a row of
// posts or along a wall's edge doesn't make it flicker.
constexpr float sFadeOutDelay = 0.35f;
+ // Cover (isPlayerCovered): looked for straight up from this far over the player's feet (over their head), to
+ // this far up, from over them and from this far around them; and only something this level counts (the
+ // first thing hit: a branch or a leaf of a tree over them is no roof).
+ constexpr float sCoverFrom = 135.f;
+ constexpr float sCoverHeight = 1200.f;
+ constexpr float sCoverSpread = 200.f;
+ constexpr float sCoverFlatness = 0.6f;
MWWorld::Ptr findPtr(const osg::NodePath& nodePath)
{
@@ -98,6 +106,7 @@ namespace MWRender
};
osg::ref_ptr<osgUtil::IntersectorGroup> group = new osgUtil::IntersectorGroup;
+ std::vector<osg::ref_ptr<osgUtil::LineSegmentIntersector>> toPlayer;
for (const osg::Vec3f& point : points)
{
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector
@@ -105,17 +114,36 @@ namespace MWRender
// Every object along the way, not only the nearest
intersector->setIntersectionLimit(osgUtil::Intersector::NO_LIMIT);
group->addIntersector(intersector);
+ toPlayer.push_back(intersector);
+ }
+
+ // Straight up from over the player's head and from around them, for whatever hangs over them (isPlayerCovered)
+ const osg::Vec3f along = across ^ osg::Vec3f(0.f, 0.f, 1.f);
+ const osg::Vec3f overhead = feet + osg::Vec3f(0.f, 0.f, sCoverFrom);
+ const std::array<osg::Vec3f, 5> coverFrom = {
+ overhead,
+ overhead + across * sCoverSpread,
+ overhead - across * sCoverSpread,
+ overhead + along * sCoverSpread,
+ overhead - along * sCoverSpread,
+ };
+ std::vector<osg::ref_ptr<osgUtil::LineSegmentIntersector>> upward;
+ for (const osg::Vec3f& from : coverFrom)
+ {
+ osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(
+ osgUtil::Intersector::MODEL, from, from + osg::Vec3f(0.f, 0.f, sCoverHeight));
+ intersector->setIntersectionLimit(osgUtil::Intersector::LIMIT_NEAREST);
+ group->addIntersector(intersector);
+ upward.push_back(intersector);
}
mVisitor->reset();
mVisitor->setIntersector(group);
mSceneRoot->accept(*mVisitor);
- for (const osg::ref_ptr<osgUtil::Intersector>& intersector : group->getIntersectors())
+ for (const auto& intersector : toPlayer)
{
- const auto& intersections
- = static_cast<osgUtil::LineSegmentIntersector*>(intersector.get())->getIntersections();
- for (const auto& intersection : intersections)
+ for (const auto& intersection : intersector->getIntersections())
{
MWWorld::Ptr ptr = findPtr(intersection.nodePath);
// (Paged objects, merged with their neighbours, have no Ptr of their own and can't be faded alone)
@@ -123,6 +151,19 @@ namespace MWRender
out.push_back(ptr);
}
}
+
+ mPlayerCovered = false;
+ for (const auto& intersector : upward)
+ {
+ const auto& intersections = intersector->getIntersections();
+ if (intersections.empty())
+ continue;
+ if (std::abs(intersections.begin()->getWorldIntersectNormal().z()) > sCoverFlatness)
+ {
+ mPlayerCovered = true;
+ break;
+ }
+ }
}
void OcclusionFader::update(float dt, const osg::Vec3f& eye, const MWWorld::Ptr& player, bool active)
@@ -139,6 +180,8 @@ namespace MWRender
std::vector<MWWorld::Ptr> occluders;
if (active && !player.isEmpty() && player.isInCell())
findOccluders(eye, player, occluders);
+ else
+ mPlayerCovered = false;
for (const MWWorld::Ptr& ptr : occluders)
{
diff --git a/apps/openmw/mwrender/occlusionfader.hpp b/apps/openmw/mwrender/occlusionfader.hpp
index 0231178..5530948 100644
--- a/apps/openmw/mwrender/occlusionfader.hpp
+++ b/apps/openmw/mwrender/occlusionfader.hpp
@@ -43,6 +43,10 @@ namespace MWRender
/// Objects currently fading out or faded; the top-down cursor picks through these.
std::vector<MWWorld::Ptr> getFadedObjects() const;
+ /// Whether something level (a floor, a bridge, a canton's tier) hangs over the player or right around them,
+ /// as of the last update while active; the room-like cut then applies outdoors too (RenderingManager::update).
+ bool isPlayerCovered() const { return mPlayerCovered; }
+
private:
struct Faded
{
@@ -66,6 +70,7 @@ namespace MWRender
osg::ref_ptr<osg::Group> mSceneRoot;
osg::ref_ptr<osgUtil::IntersectionVisitor> mVisitor;
std::map<osg::Node*, Faded> mFaded;
+ bool mPlayerCovered = false;
};
}
diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp
index aba6d20..f021a13 100644
--- a/apps/openmw/mwrender/renderingmanager.cpp
+++ b/apps/openmw/mwrender/renderingmanager.cpp
@@ -726,12 +726,20 @@ namespace MWRender
// Top-down camera (shaders/lib/util/cutaway.glsl): outdoors, whole objects between the camera and the
// player fade out (OcclusionFader); indoors the room is cut cleanly instead (walls in front, the roof and
- // upper floors), with nothing left see-through.
+ // upper floors), with nothing left see-through. Outdoors under a floor, a bridge or a canton's tier the
+ // room-like cut applies as well, close around the player: the fade alone leaves whatever hangs over the
+ // way ahead of them whole.
+ constexpr float indoorCutawayRadius = 4000.f;
+ constexpr float coveredCutawayRadius = 900.f;
const bool topDown = mCamera->getMode() == Camera::Mode::Static;
const bool indoors = player.isInCell() && !player.getCell()->getCell()->isExterior();
mOcclusionFader->update(dt, mCamera->getPosition(), player, topDown && !indoors);
- const float overheadTarget = topDown && indoors ? 4000.f : 0.f;
+ float overheadTarget = 0.f;
+ if (topDown && indoors)
+ overheadTarget = indoorCutawayRadius;
+ else if (topDown && mOcclusionFader->isPlayerCovered())
+ overheadTarget = coveredCutawayRadius;
mCutawayOverheadRadius += (overheadTarget - mCutawayOverheadRadius) * std::min(1.f, dt * 5.f);
mCutawayOverheadUniform->set(mCutawayOverheadRadius);
}
diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp
index 6dab180..2c04422 100644
--- a/apps/openmw/mwrender/renderingmanager.hpp
+++ b/apps/openmw/mwrender/renderingmanager.hpp
@@ -182,6 +182,10 @@ namespace MWRender
/// The objects the top-down camera currently fades out because they stand in front of the player.
std::vector<MWWorld::Ptr> getFadedObjects() const;
+ /// The radius around the player within which the top-down camera cuts the room (ceilings and upper floors
+ /// over them, the walls in the way): indoors, and outdoors under cover; 0 where nothing is cut.
+ float getCutawayRadius() const { return mCutawayOverheadRadius; }
+
RayResult castRay(const osg::Vec3f& origin, const osg::Vec3f& dest, bool ignorePlayer,
bool ignoreActors = false, std::span<const MWWorld::Ptr> ignoreList = {});
@@ -373,7 +377,8 @@ namespace MWRender
// Top-down camera: what stands between it and the player fades out (see OcclusionFader)
std::unique_ptr<OcclusionFader> mOcclusionFader;
- // Indoors, ceilings and upper floors over the player are removed within this radius around them
+ // Indoors (and outdoors under cover), ceilings and upper floors over the player are removed within this
+ // radius around them, and the walls in the way cut
float mCutawayOverheadRadius = 0.f;
osg::ref_ptr<osg::Uniform> mCutawayOverheadUniform;
diff --git a/files/shaders/lib/util/cutaway.glsl b/files/shaders/lib/util/cutaway.glsl
index 5665130..6652327 100644
--- a/files/shaders/lib/util/cutaway.glsl
+++ b/files/shaders/lib/util/cutaway.glsl
@@ -10,8 +10,11 @@
// shader applies; OcclusionFader blends faded objects and keeps them out of the depth buffer), so post-processing
// that reads depth (ambient occlusion, fog) sees the scene behind them rather than a dither;
// - indoors (cutawayOverheadRadius, set by RenderingManager::update; nothing fades there) the room is seen like a
-// dollhouse, cut with clean edges: what stands between the player and the camera ends at waist height, and
-// everything above door height (roof, rafters, ceilings, upper floors, people upstairs) is removed;
+// dollhouse, cut with clean edges: the walls between the player and the camera (the faces that hide the room from
+// it, not a wall seen from the player's own side) end at waist height, and everything above door height (roof,
+// rafters, ceilings, upper floors, people upstairs) is removed. Outdoors the same happens, in a smaller circle,
+// while a floor, a bridge or a canton's tier hangs over the player (OcclusionFader::isPlayerCovered): the fade
+// alone would leave whatever hangs over the way ahead of them whole;
// - wherever something still covers the player (a hill, a faded ghost), it shows their silhouette, outlined, so
// they are never lost.
// Nothing at or below the player's feet is faded, so floors and the ground they stand on stay solid even when they
@@ -161,12 +164,32 @@ vec2 applyCutaway(vec3 viewPos, vec3 viewNormal, bool terrain)
}
// Indoors: walls (and anything else tall) between the player and the camera end at waist height across the
- // room, like a dollhouse, so the room and whoever is in it can be seen; outdoors only the window above opens
+ // room, like a dollhouse, so the room and whoever is in it can be seen; outdoors only the window above opens.
+ // Only the faces that hide the room: a face seen from the player's side (it points their way) has the room
+ // in front of it, so it stays whole however the wall runs; before, every bit of a wall nearer the camera
+ // than the player was cut, and a wall running diagonally past them lost its half toward the camera. A face
+ // seen from behind (two-sided geometry) is turned round first. Tops and other level surfaces have no side:
+ // they are cut within the right angle toward the camera from the player, which for a wall running past the
+ // player is where its faces are cut too.
if (cutawayOverheadRadius > 1.0 && inFront)
{
- float around = 1.0 - smoothstep(cutawayOverheadRadius * 0.8, cutawayOverheadRadius,
- length(world.xy - playerPos.xy));
- cut = max(cut, around * step(CUTAWAY_WALL_HEIGHT, world.z - playerPos.z));
+ vec3 facing = gl_FrontFacing ? worldNormal : -worldNormal;
+ vec2 fromPlayer = world.xy - playerPos.xy;
+ bool hidesRoom;
+ if (abs(facing.z) < 0.7)
+ hidesRoom = dot(facing.xy, fromPlayer) > 0.0;
+ else
+ {
+ float ahead = dot(fromPlayer, towardCamera);
+ float aside = length(fromPlayer - towardCamera * ahead);
+ hidesRoom = ahead > aside;
+ }
+ if (hidesRoom)
+ {
+ float around = 1.0 - smoothstep(cutawayOverheadRadius * 0.8, cutawayOverheadRadius,
+ length(fromPlayer));
+ cut = max(cut, around * step(CUTAWAY_WALL_HEIGHT, world.z - playerPos.z));
+ }
}
// Indoors: ceilings and upper floors above the player's head (surfaces facing up or down), and everything
diff --git a/isowind/README.txt b/isowind/README.txt
index ff7a53d..46bfa61 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -159,9 +159,11 @@ does the map). Zoom it with the mouse wheel over it while a menu is open, or in
where you can also keep it pointing north.
Walls, roofs and trees between you and the camera open up in a circle around you, so you can always
-see yourself. Indoors you see the room like a dollhouse: walls toward the camera end at waist height,
-and ceilings and the floor above are removed. Doors are never hidden. Hovering over a creature or person shows a ring under them: blue if peaceful (light
-blue when in reach), red if hostile (orange when in weapon reach).
+see yourself. Indoors you see the room like a dollhouse: the walls between you and the camera end at
+waist height (a wall you see from your own side stays whole), and ceilings and the floor above are
+removed. Under a floor, a bridge or a canton's tier outdoors (Vivec) the same happens close around
+you. Doors are never hidden. Hovering over a creature or person shows a ring under them: blue if
+peaceful (light blue when in reach), red if hostile (orange when in weapon reach).
Options
-------
diff --git a/isowind/mod/scripts/isowind/topdown.lua b/isowind/mod/scripts/isowind/topdown.lua
index 2ce61cc..bc3ab7f 100644
--- a/isowind/mod/scripts/isowind/topdown.lua
+++ b/isowind/mod/scripts/isowind/topdown.lua
@@ -345,24 +345,52 @@ local function segmentDistance(p, a, b)
return (p - (a + ab * t)):length()
end
--- What the camera fades out (shaders/lib/util/cutaway.glsl): the engine fades whole objects that stand in front of
--- the player (camera.getFadedObjects), and indoors removes ceilings and upper floors over them. Floors and the
--- ground below their knees always stay.
+-- What the camera cuts away (shaders/lib/util/cutaway.glsl): the engine fades whole objects that stand in front of
+-- the player (camera.getFadedObjects), and indoors, or under a floor or a bridge outdoors, removes ceilings and upper
+-- floors over them and cuts the walls in the way, within camera.getCutawayRadius of them. Floors and the ground below
+-- their knees always stay.
local fadedObjects = {}
+local cutawayRadius = 0
local function updateFadedObjects()
fadedObjects = {}
for _, object in ipairs(camera.getFadedObjects()) do
fadedObjects[object.id] = true
end
+ cutawayRadius = camera.getCutawayRadius and camera.getCutawayRadius() or 0
end
+-- Toward the camera along the ground (unit length)
+local function towardCamera()
+ local f = view.forward
+ local length = math.sqrt(f.x * f.x + f.y * f.y)
+ if length < 1e-4 then return v3(0, -1, 0) end
+ return v3(-f.x / length, -f.y / length, 0)
+end
+
+-- The shader's rules, for a surface the cursor's ray hit from its front (normal: its facing)
local function isCutAway(pos, object, normal)
- if pos.z < self.position.z + 25 then return false end
+ local height = pos.z - self.position.z
+ if height < 25 then return false end
if object and fadedObjects[object.id] then return true end
- -- Indoors: surfaces facing up or down above the player's head
- if self.cell and not self.cell.isExterior and pos.z > self.position.z + 200 then
- return normal ~= nil and math.abs(normal.z) > 0.5
+ if cutawayRadius <= 1 then return false end
+ local rel = pos - self.position
+ local flat = math.sqrt(rel.x * rel.x + rel.y * rel.y)
+ if flat > cutawayRadius * 0.9 then return false end
+ -- Everything above the storey, and ceilings and upper floors over the player's head
+ if height > 230 then return true end
+ if height > 200 and normal and math.abs(normal.z) > 0.5 then return true end
+ -- Above waist height between the player and the camera: faces that hide the room from it (pointing away from the
+ -- player), and level surfaces within the right angle toward the camera
+ if height > 110 and normal then
+ local toward = towardCamera()
+ local ahead = rel.x * toward.x + rel.y * toward.y
+ if ahead > 10 then
+ if math.abs(normal.z) < 0.7 then
+ return normal.x * rel.x + normal.y * rel.y > 0
+ end
+ return ahead > math.sqrt(math.max(0, flat * flat - ahead * ahead))
+ end
end
return false
end