Monday, October 5, 2020

Mirror Reflections and Player Models Gone Wrong

This is just a short post to show off some of the interesting and amusing mistakes I made while working on the previous mirror reflection post. Well, they're not all mistakes, a few were just experiments I decided to do.

Here is a screenshot that's similar to what I saw when disabling (or, um, incorrectly implementing) the reflection operation. The mirror is an image of the player's view of the mirror itself. Since it's updated in realtime, each frame takes another image of the previous image, zoomed out a bit based on the camera distance from the mirror. This stacks up some number of reflection images on top of each other, which will converge to something like this when the player stops moving.

The original bug looked a bit different from this where the mirror was a smaller recursive zoomed in copy of the mirror itself where the mirror-in-mirror converged to a tiny point in the middle of the screen. Unfortunately, I never saved a screenshot of the original problem and I can't seem to get the code back into a state that looks like that. Like this.

Here is what happens when I make the same "mistake" but also draw the player model in the reflection image. Rather than the mirror, we see the inside of the player model's head, since that's where the "camera" is. It looks like someone stretched the skin from a man's head over a canvas and hung it on the wall like a picture. I have no idea what's up with the eyes.


Did you ever try to look at something on your face very closely in a mirror, and you lean in so close that the front of your face goes through the mirror's surface and you're looking through your head? Yeah, I hate it when that happens to me.


Yeah, I know, that's not realistic. You can't see through your face when looking closely into a mirror! In the real world, ... there's no back face culling. You'll see inside your head instead, like this:


If I move a bit closer so that my entire face is through the mirror plane, all I can see is the back of my head. Yeah, that's right. That's the inside surface of my hat. No brain in there!


Okay, what if I draw the player model even when reflections aren't enabled? Did you ever wonder what it would look like if you had only one eye? And it was inside the center of your head rather than on the surface? And your head was empty? Well, wonder no more, here is what it would look like:

That kind of looks like the inside view of an oversized rubber Halloween mask. Except there are no eye holes cut out. Is that how people feel when inside those big mascot costumes? I tried to remove the eyes so that you can see through the eye holes, but unfortunately the face model is a single mesh using a single texture. That's a shame, it could have made a fun gameplay mode to only allow the player to see through tiny eye holes. Who needs peripheral vision, right?

2 comments:

  1. With your focus on performance and maintaining a high framerate, it seems like this would be a great engine for VR. You'd definitely end up with problems like this though. No good constraining the camera location in VR!

    ReplyDelete
    Replies
    1. If I had more time to work on this I would definitely experiment with VR. Right now I don't have a good VR headset, and the various SDKs seem difficult to work with. I also get a bit of motion sickness in VR.

      There's really no constraints on the camera in 3DWorld. If you disable collision detection you can fly to anywhere. It's designed so that everything looks correct and smoothly transitions up to airplane movement speeds. If I enabled tiled buildings you can walk for hours to the next country and enter a building. The view distance is several km and you can fly into the clouds and look down. The only case that doesn't draw correctly is when the camera is inside a wall, an object, or the terrain.

      Delete