Part 13 of 13 in Ghostveil
Looking down through every portal
Ghostveil's portal views now look down at the floor the way the room's own camera does. Most of the day went on deciding where Fantasma's feet belong in that view.
Yesterday's portal renderer had two cameras. A pillar with exactly one floor tile before a wall looked down at that tile; every other pillar looked straight ahead, where the floor is edge-on and invisible. Ghostveil is a puzzle game about pushing stones and pillars around a buried machine, so pillars move all the time, and pushing one back a single tile flipped its view from floor to wall in one step. The room around the portal never does that. Its camera always looks down from above, and the window into another room ought to agree with it.
By the end of the day every pillar view looks down. The opening above shows the tile in front of the other pillar, with the wall rising behind it. Getting there meant a detour through a hybrid view and four different heights for Fantasma.
The floor-and-wall view
The first attempt kept both cameras and stitched them together in the one-tile case. The bottom of the opening looked down at the floor tile; the top was an upright pass that drew the wall's face rising from where the tile met it. In one room it looked right. In another the top half came out solid black.
The wall pass put its camera at the depth of the wall's face, exactly on its surface. The scene walker skips any solid whose volume contains the camera, so a portal can never draw the inside of the stone it is embedded in:
if (volume.inflate(0.001).contains(camera.origin)) return;
A camera sitting on the face counts as inside the wall, so the wall dropped out and the view showed whatever was behind it. In two rooms that was the empty dark beyond the outer wall. In a third it was the other half of the room, which happened to have bricks in the right place and looked correct by accident. Moving the camera half a pixel in front of the face fixed all three, including the room that had looked fine before the fix.
Four heights for Fantasma
With the wall drawing, the next question was where Fantasma stands when she is on that floor tile. Each panel below is the same moment in the same room.
Moving her with the floor sank her below the sill, with only her hood showing. Standing her on the centre of her tile put her three art pixels higher than she stood in every other portal view. Keeping the other views' height looked consistent until I asked which of the views was the odd one out. The front view drew every figure at one height whatever its distance, so someone three tiles away stood on the sill as if they were in the doorway. The room's camera does nothing of the kind.
So the front view went, and every pillar view now uses the downward frame from the earlier post with fixed at one:
Here is the projected point and the centre of the scene crop. As before, is the point's position across the view, its depth beyond the opening, the portal's height registration and its height above its ground anchor. The new terms are , a whole-pixel shift that puts the far edge of the first floor tile on row 2 of the opening, and , which is five pixels for a standing figure and zero for everything else.
The shift comes from where that tile edge would land without it:
final edge = camera.target.dy + camera.height - camera.mouthInset - tile;
final shift = (patch.top + _firstTileEdge + rowOffset - edge)
.roundToDouble();
canvas.translate(0, shift);
draw(canvas, patch.shift(Offset(0, -shift)), camera);
The figure term comes from the room itself, whose camera draws Fantasma with her feet five pixels below the centre of her tile. A portal view is the same camera turned to face another way, so it applies the same five pixels down the opening. Standing on the tile before the far pillar, her feet now sit just behind the sill, as they would through a window that size.
What looking down costs
The opening is twenty art pixels tall at true size, so it shows a tile and a quarter of floor. A wall two tiles beyond the far pillar is now past its top edge, and so is a figure standing that far out.
The front view showed that distant wall, because it ignored distance. The downward view shows floor, which is what is actually in front of the far pillar. Motion inside a view changed too: a stone sliding towards a pillar used to stay put on screen, and now it climbs the opening one art pixel at a time, since the view is drawn at art resolution before it is scaled with the room. The room itself still moves a device pixel at a time.
A hole in a turning pillar
Checking every turn for regressions turned up an older fault. Midway through a quarter turn, a pillar standing next to a wall opened a gap, and Fantasma, standing behind it, showed through.
A turning box's corner swings about eleven pixels from its centre, so for part of the turn it passes over the wall cell beside it. The renderer dropped any pillar pixel whose ground point fell inside a wall, so a turning overhang could never paint over masonry. On screen, though, those pixels sat over the open floor north of the wall, where nothing covers them. The check now looks at the pixel's position on screen as well:
if (!_groundVisible(ground)) return _groundVisible(pixel);
A pixel whose ground is inside a wall is hidden only where masonry stands in front of it on screen; over floor it draws.
Checking it
A debug build sets up each case through the puzzle rules, plays it through the real input path and saves every frame. It covers 263 cases across the eight portal rooms: every crossing at every facing, every pillar push, every quarter turn and a stone through every pairing of portals. Frame checks against the previous build's capture of the same cases found no new hidden or broken frames. The only extra flags were the art-pixel steps of motion inside views. All 43 turns are free of the hole. The same opening at iPhone SE, iPhone Pro, Pro Max and iPad sizes is identical pixel for pixel at art resolution; only the number of device pixels behind each art pixel changes.
Two things are still missing. Portal views do not draw the shadows cast by the room's light, so the floor in front of her feet is unshaded in the view where the room shades it. The code for the front view and for switching between cameras is still in place, no longer reached, and is next to go.
The sprites come from SnowHex's Dungeon Gathering: Under The Castle; Ghostveil supplies the room construction, lighting, portal rendering and puzzle rules.