Open jwwalker opened 1 year ago
@darksylinc I have what I think is a fix for this, but I'm not sure I understand enough to make a PR. My idea is that instead of using an orientation-reversing camera for the reflection, do a horizontal flip at the shader level. More specifically:
In Math::makeViewMatrix
, flip the signs in the top row:
// Deal with reflections
if( reflectMatrix )
{
viewMatrix = viewMatrix * ( *reflectMatrix );
viewMatrix[0][0] *= -1.0f;
viewMatrix[0][1] *= -1.0f;
viewMatrix[0][2] *= -1.0f;
viewMatrix[0][3] *= -1.0f;
}
(There's probably a slicker way to express that.)
And in Hlms/Unlit/Any/800.PixelShader_piece_ps.any, when handling the property diffuse_map@n_reflection
, replace
#define DiffuseUV@n gl_FragCoord.xy * passBuf.invWindowSize.xy
by
#define DiffuseUV@n float2( 1.0-gl_FragCoord.x * passBuf.invWindowSize.x, gl_FragCoord.y * passBuf.invWindowSize.y )
and replace
#define DiffuseUV@n float2( gl_FragCoord.x * passBuf.invWindowSize.x, 1.0f - gl_FragCoord.y * passBuf.invWindowSize.y )
by
#define DiffuseUV@n float2( 1.0-gl_FragCoord.x * passBuf.invWindowSize.x, 1.0f - gl_FragCoord.y * passBuf.invWindowSize.y )
An incomplete part is that in Hlms/Unlit/GLSLES/BlendModes_piece_ps.glsl, there is another reference to diffuse_map@n_reflection
, and I don't know what that's about.
I spoke too soon. The changes I outlined produce a better result for two-sided lighting, but a worse result for reflections of one-sided things.
@darksylinc My current best attempt at getting the mirror image to look right for both 2-sided and 1-sided meshes is, besides the changes outlined above, to change SceneManager:: _cullPhase01
so that it never calls setInvertVertexWinding
.
The changes I've outlined above give good results for unlit mirrors, but break reflections in lit mirrors, and I don't know why. But for my personal purposes, unlit mirrors probably suffice.
System Information
Detailed description
When the PlanarRelections library mirrors objects with a Pbs data blocks set to use two-sided lighting, the reflections look wrong. This is especially obvious when using unlit mirrors.
Steps to reproduce:
HlmsPbs::createDatablockImpl
in OgreHlmsPbs.cpp to say:Sample_PlanarReflections
.Ogre.log
-->