[Softpoly] Mirrors crash the renderer

Moderators: Rachael, dpJudas

Locked
User avatar
Rachael
Developer
Developer
Posts: 3640
Joined: Sat May 13, 2006 10:30

[Softpoly] Mirrors crash the renderer

Post by Rachael »

https://github.com/raa-eruanna/qzdoom/c ... a3d7b8bd6b

I was able to load in a debugger and put in these pointer checks (one affects the ZDoom code, however, which is why I didn't merge it into the master, but feel free to merge it if you like).

Basically, it seems like the portals for mirrors are yet undefined.

From my understanding, mirrors are done like this:
MirrorViewPosition = (xyz)MirrorStart * 2 - (xyz)View // (edit: come to think of it, this needs to also be rotated based on the MirrorLine angle, too, and then rotated back)
MirrorViewAngle = (angle)MirrorLine * 2 - (angle)PlayerView
MirrorViewMatrix.Z *= -1

I do not know how to hook that up into the triangle drawer, though. :(
Attachments
mirrortest3.wad
(1.06 KiB) Downloaded 96 times
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [Softpoly] Mirrors crash the renderer

Post by dpJudas »

The portal code, which also drives mirrors, is incomplete.

The way it is meant to work is that as RenderPolyScene draws the solid part of a scene from the player's viewpoint, it collects a list of portals seen (PolyDrawSectorPortal and PolyDrawLinePortal). Mirrors is a variation of the line portal, where the destination is the same line with the camera rotated (mirrored) in that line.

Once it collected the list of portals, it renders the solid part of each of them. It does this by calling PolyDrawLinePortal::Render, which then changes the ViewPos, ViewAngle, camera, and other nasty globals to convince the renderer that we are now standing in a new location. After that, it asks RenderPolyScene to draw the scene again where the output is restricted to just the pixels covered by the portal. If mirror rendering crashes it, the reason is probably something missing in PolyDrawLinePortal::SaveGlobals or RestoreGlobals.

The main thing making the portal stuff so incomplete is that it doesn't properly restrict what is viewable by a portal. A side effect of that is it often tries to draw half the world, plummeting the frame rate. It also doesn't properly track if a portal has already been seen, often causing it to recursively draw them over and over again until reaching the recursion limit.

Anyhow, to answer your question about the triangle drawer, the way to do it is to apply the mirror to the WorldToClip matrix. The rotation code already seems to be there in SaveGlobals (untested, looted from zdoom), but there might be a TriMatrix::scale(-1,0,0) missing for the matrix in PolyDrawLinePortal::Render. Note that mirroring like that changes all clockwise to counterclockwise, which means all the args.ccw values have to be negated. It is probably easiest to do that in PolyTriangleDrawer::draw_arrays PolyTriangleDrawer::draw, as that's what all those other places end up calling.

Hope this wasn't to complex or that I skipped over too many details. Portal/mirror rendering is probably the most advanced part of the rendering process. :)
User avatar
Rachael
Developer
Developer
Posts: 3640
Joined: Sat May 13, 2006 10:30

Re: [Softpoly] Mirrors crash the renderer

Post by Rachael »

I'll get back to you on that after I've had some rest. >_>

Do you want the pointer checks merged? They're really just safety checks but it doesn't seem like they can hurt.
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [Softpoly] Mirrors crash the renderer

Post by dpJudas »

Sleep tight. :) The last check should be there, but I'm less sure about the second one, and the first is most likely wrong. I belong to the school that believes null checks should only be done if that pointer is allowed to be null. Otherwise it sends the incorrect message to the next developer reading the code that this value can be null. I'm not so sure camera is allowed to be null in the first two situations.
User avatar
Rachael
Developer
Developer
Posts: 3640
Joined: Sat May 13, 2006 10:30

Re: [Softpoly] Mirrors crash the renderer

Post by Rachael »

All 3 of those checks are needed, unfortunately, to stop the crashing. I could put in asserts to discourage future developers from trying to pass nulls into there, since nulls clearly do not belong (and are what's causing the problem in the first place). :P

I think for now I am going to hands-off on the mirror drawing, as there were other projects I was wanting to do with the ZDoom code base. This one seems a bit out of my league at the moment, even though I do want to help out. >_<
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [Softpoly] Mirrors crash the renderer

Post by dpJudas »

What I meant is that the actual bug might be where camera is assigned a null value rather than where it is being used. In such a situation the check only further cloak the origin of the error and while it stopped it from crashing it might still not be correct.

Especially the check in the general code also used by the other renderers is suspecious. The critical question to ask there is why it only crashes for the softpoly renderer, and my hunch is that this is because camera is not meant to be null.

I would probably leave the mirror thing alone until normal line portals are working flawlessly. That entire section of code was left half-finished by me and that makes the task so much greater for you as you don't know what I finished and what I didn't. :)
User avatar
Rachael
Developer
Developer
Posts: 3640
Joined: Sat May 13, 2006 10:30

Re: [Softpoly] Mirrors crash the renderer

Post by Rachael »

Fair enough. :P
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [Softpoly] Mirrors crash the renderer

Post by dpJudas »

Got your mirrortest wad file to work, except for the sky. :)
User avatar
Rachael
Developer
Developer
Posts: 3640
Joined: Sat May 13, 2006 10:30

Re: [Softpoly] Mirrors crash the renderer

Post by Rachael »

Nice. ^_^
Locked

Return to “Closed Bugs”