- fix software renderer dynamic lights not working properly in mirrors

This commit is contained in:
Magnus Norddahl 2018-06-05 20:09:02 +02:00
parent b74a9965b8
commit f5386a706f
2 changed files with 15 additions and 2 deletions

View file

@ -189,7 +189,12 @@ namespace swrenderer
{ {
auto viewport = Thread->Viewport.get(); auto viewport = Thread->Viewport.get();
drawerargs.dc_viewpos.X = (float)((x + 0.5 - viewport->CenterX) / viewport->CenterX * zcol); int tx = x;
bool mirror = !!(Thread->Portal->MirrorFlags & RF_XFLIP);
if (mirror)
tx = viewwidth - tx - 1;
drawerargs.dc_viewpos.X = (float)((tx + 0.5 - viewport->CenterX) / viewport->CenterX * zcol);
drawerargs.dc_viewpos.Y = zcol; drawerargs.dc_viewpos.Y = zcol;
drawerargs.dc_viewpos.Z = (float)((viewport->CenterY - y1 - 0.5) / viewport->InvZtoScale * zcol); drawerargs.dc_viewpos.Z = (float)((viewport->CenterY - y1 - 0.5) / viewport->InvZtoScale * zcol);
drawerargs.dc_viewpos_step.Z = (float)(-zcol / viewport->InvZtoScale); drawerargs.dc_viewpos_step.Z = (float)(-zcol / viewport->InvZtoScale);

View file

@ -205,13 +205,21 @@ namespace swrenderer
if (r_dynlights) if (r_dynlights)
{ {
int tx = x1;
bool mirror = !!(Thread->Portal->MirrorFlags & RF_XFLIP);
if (mirror)
tx = viewwidth - tx - 1;
// Find row position in view space // Find row position in view space
float zspan = (float)(planeheight / (fabs(y + 0.5 - viewport->CenterY) / viewport->InvZtoScale)); float zspan = (float)(planeheight / (fabs(y + 0.5 - viewport->CenterY) / viewport->InvZtoScale));
drawerargs.dc_viewpos.X = (float)((x1 + 0.5 - viewport->CenterX) / viewport->CenterX * zspan); drawerargs.dc_viewpos.X = (float)((tx + 0.5 - viewport->CenterX) / viewport->CenterX * zspan);
drawerargs.dc_viewpos.Y = zspan; drawerargs.dc_viewpos.Y = zspan;
drawerargs.dc_viewpos.Z = (float)((viewport->CenterY - y - 0.5) / viewport->InvZtoScale * zspan); drawerargs.dc_viewpos.Z = (float)((viewport->CenterY - y - 0.5) / viewport->InvZtoScale * zspan);
drawerargs.dc_viewpos_step.X = (float)(zspan / viewport->CenterX); drawerargs.dc_viewpos_step.X = (float)(zspan / viewport->CenterX);
if (mirror)
drawerargs.dc_viewpos_step.X = -drawerargs.dc_viewpos_step.X;
// Plane normal // Plane normal
drawerargs.dc_normal.X = 0.0f; drawerargs.dc_normal.X = 0.0f;
drawerargs.dc_normal.Y = 0.0f; drawerargs.dc_normal.Y = 0.0f;