I'm trying to understand how to use the PlanarReflections
class. I'm confused about the documentation of HlmsUnlitDatablock::setEnablePlanarReflection
, which says "UVs will be ignored for that texture unit". How is a texture going to be applied to a mesh without paying attention to UVs? To be more specific, let's say that I have a disk-shaped mesh that I want to act as a mirror. I would define a PlanarReflectionActor
whose bounding rectangle fits more or less snugly around the disk. Is the idea that the standard UV coordinates implicitly defined by the PlanarReflectionActor
rectangle are used on the disk?
PlanarReflections question
-
- Goblin
- Posts: 268
- Joined: Thu Aug 12, 2021 10:06 pm
- Location: San Diego, CA, USA
- x 19
PlanarReflections question
-
- OGRE Team Member
- Posts: 5477
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1359
Re: PlanarReflections question
Planar reflections are, like the name suggests, flat planes.
We can use an object that has the exact same shape (i.e. a rectangle with the same position & orientation) or something approximate.
The UVs are generated on the fly as they derived from screen space coordinates.
You could say we autogenerate the UVs every frame, in the pixel shader. How distorted that looks depends on whether the actual object resembles a plane, or if it looks nothing like a plane (i.e. you could use a teapot, but it likely won't look good).
Is the idea that the standard UV coordinates implicitly defined by the PlanarReflectionActor rectangle are used on the disk?
I wouldn't say "standard" UV. But yes, they are generated implicitly in real time from the screen space location of the vertex.
Explaining more than this (i.e. long version) would just basically explain everything about how planar reflections work. Since the technique is not actually complex: We use math to determine where to place an auxiliary camera to render to an RTT. That RTT is overlapped with the current screen, but it must only be shown where the mirror geometry is located.
The technique is actually ancient and predates shaders. The easiest way to understand it is to look at Star Fox 64 Corneria's water which applied planar reflections: The enemies (and the airplane + laser beams) are rendered twice: once in normal and another flipped around Y axis, and a clipping plane is used to prevent the flipped version to "surface" above the water if the enemy gets too close to the water.