Problem with Planar Mirror Reflection

Hey everyone! I’m trying to implement a mirror in my project based on this example
https://playcanvas.com/project/717166/overview/planar-mirror-reflection

It works, but only if reflection is parallel to the ground. If I’m trying to place the mirror vertically, the reflection either freezes (with 0, 0, 0 plane rotation) or the reflection is misaligned (other orientations).
Here is an example:

And the project:
https://playcanvas.com/project/808188/overview/ref-test

As I understand the example is based on this project
https://playcanvas.com/project/529572/overview/after-the-flood
and there the mirror surface is vertical, but this level of code is beyond my skills so my attempts to figure out what’s going on were unsuccessful.

Can someone help me figure it out?

Hi @bezrodnyigor ,

I’ve played a bit with the demo, indeed I can reproduce that behavior. At any angle except being fully horizontal seems to have issues. Also changing the default quad model asset provided with a simple plane breaks reflections (maybe some normals are missing there, not sure).

@LeXXik may be able to help on this.

1 Like

Howdy!

Yeah, that was a while, when I made that example. Hmm, to be honest, I am not sure about the viewing angle. Probably something to do with the normal of the reflection quad. Could be my porting from After the Flood. I would have to look into when I have time (which is not in the near future, I’m afraid :frowning: ). Because of the way the camera projection is built, you can probably work around the issue by not having a completely vertical wall/mirror. Try setting it to 2 degrees or something. I know, its a workaround, but it will take time till I get my hands on this. In all honesty, we should make a “user friendly” example, using modern API ^^

As for the offset, that should be caused by the shader:
image

That 1.2 is your offset. I don’t remember now why I needed it that way at the time.
You can try to swizzle it to vec2(1.0);. That should get rid of the offset.

3 Likes

Thank you for the information! Having a slight tilt to the mirror is not a problem. Besides, the issue is only with (0, 0, 0) rotation, having it vertical but facing a different direction seems to work.

Changing offset did help, although with (1.0) There was still a horizontal offset (that seem to depend on the angle of the plane). I ended up with vec2(0.8, 1.0):

Thank you!

3 Likes