2016-09-14 18:01:13 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright(C) 2004-2016 Christoph Oelckers
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_scene.cpp
|
|
|
|
** manages the rendering of the player's view
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2020-04-10 20:10:49 +00:00
|
|
|
#include "gl_system.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gi.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_data/r_interpolate.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "d_player.h"
|
2018-04-16 07:02:48 +00:00
|
|
|
#include "hwrenderer/dynlights/hw_dynlightdata.h"
|
2018-10-27 20:04:13 +00:00
|
|
|
#include "hwrenderer/utility/hw_clock.h"
|
|
|
|
#include "hwrenderer/data/flatvertices.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-10-28 14:09:33 +00:00
|
|
|
#include "hwrenderer/dynlights/hw_lightbuffer.h"
|
2018-04-25 18:33:55 +00:00
|
|
|
#include "hwrenderer/utility/hw_cvars.h"
|
2018-10-28 12:26:47 +00:00
|
|
|
#include "hwrenderer/data/hw_viewpointbuffer.h"
|
2018-04-23 20:18:13 +00:00
|
|
|
#include "hwrenderer/scene/hw_clipper.h"
|
2018-06-23 11:25:23 +00:00
|
|
|
#include "hwrenderer/scene/hw_portal.h"
|
2018-06-24 11:39:14 +00:00
|
|
|
#include "hwrenderer/utility/hw_vrmodes.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-10-29 12:56:17 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Renders one viewpoint in a scene
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-04-25 08:51:45 +00:00
|
|
|
sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen)
|
2018-06-20 08:47:03 +00:00
|
|
|
{
|
2020-04-25 08:51:45 +00:00
|
|
|
auto& RenderState = *screen->RenderState();
|
|
|
|
|
|
|
|
R_SetupFrame(mainvp, r_viewwindow, camera);
|
2014-12-31 11:04:55 +00:00
|
|
|
|
2019-01-11 18:53:30 +00:00
|
|
|
if (mainview && toscreen)
|
2020-04-25 08:51:45 +00:00
|
|
|
screen->UpdateShadowMap();
|
2019-01-04 14:51:59 +00:00
|
|
|
|
2019-01-29 19:09:06 +00:00
|
|
|
// Update the attenuation flag of all light defaults for each viewpoint.
|
|
|
|
// This function will only do something if the setting differs.
|
|
|
|
FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE));
|
|
|
|
|
2020-04-25 08:51:45 +00:00
|
|
|
// Render (potentially) multiple views for stereo 3d
|
2018-06-24 11:39:14 +00:00
|
|
|
// Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode.
|
|
|
|
auto vrmode = VRMode::GetVRMode(mainview && toscreen);
|
2019-03-03 17:35:38 +00:00
|
|
|
const int eyeCount = vrmode->mEyeCount;
|
2020-04-25 08:51:45 +00:00
|
|
|
screen->FirstEye();
|
2019-03-03 17:35:38 +00:00
|
|
|
for (int eye_ix = 0; eye_ix < eyeCount; ++eye_ix)
|
2015-10-31 00:51:35 +00:00
|
|
|
{
|
2020-04-25 08:51:45 +00:00
|
|
|
const auto& eye = vrmode->mEyes[eye_ix];
|
2018-06-03 11:59:40 +00:00
|
|
|
screen->SetViewportRects(bounds);
|
2018-06-30 13:24:13 +00:00
|
|
|
|
|
|
|
if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao
|
|
|
|
{
|
|
|
|
bool useSSAO = (gl_ssao != 0);
|
2020-04-25 08:51:45 +00:00
|
|
|
screen->SetSceneRenderTarget(useSSAO);
|
|
|
|
RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
|
|
|
RenderState.EnableDrawBuffers(RenderState.GetPassDrawBufferCount(), true);
|
2018-06-30 13:24:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 00:26:16 +00:00
|
|
|
auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr);
|
2020-04-25 08:51:45 +00:00
|
|
|
auto& vp = di->Viewpoint;
|
2018-10-29 09:21:52 +00:00
|
|
|
|
2020-04-25 08:51:45 +00:00
|
|
|
di->Set3DViewport(RenderState);
|
2018-05-21 20:04:29 +00:00
|
|
|
di->SetViewArea();
|
2020-04-25 08:51:45 +00:00
|
|
|
auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr);
|
2018-06-19 21:16:22 +00:00
|
|
|
di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint)
|
2018-05-21 20:04:29 +00:00
|
|
|
|
2015-10-31 00:51:35 +00:00
|
|
|
// Stereo mode specific perspective projection
|
2018-06-24 11:39:14 +00:00
|
|
|
di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio);
|
|
|
|
// Stereo mode specific viewpoint adjustment
|
|
|
|
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees);
|
2020-04-25 08:51:45 +00:00
|
|
|
di->SetupView(RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);
|
2018-06-22 19:44:53 +00:00
|
|
|
|
2020-04-24 19:47:18 +00:00
|
|
|
di->ProcessScene(toscreen);
|
2018-04-29 09:00:34 +00:00
|
|
|
|
2018-06-16 07:37:01 +00:00
|
|
|
if (mainview)
|
2016-07-29 19:31:20 +00:00
|
|
|
{
|
2018-09-02 09:34:18 +00:00
|
|
|
PostProcess.Clock();
|
2020-04-25 08:51:45 +00:00
|
|
|
if (toscreen) di->EndDrawScene(mainvp.sector, RenderState); // do not call this for camera textures.
|
2018-06-30 13:24:13 +00:00
|
|
|
|
2020-04-25 08:51:45 +00:00
|
|
|
if (RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers
|
2018-06-30 13:24:13 +00:00
|
|
|
{
|
2020-04-25 08:51:45 +00:00
|
|
|
RenderState.SetPassType(NORMAL_PASS);
|
|
|
|
RenderState.EnableDrawBuffers(1);
|
2018-06-30 13:24:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 08:51:45 +00:00
|
|
|
screen->PostProcessScene(false, cm, [&]() { di->DrawEndScene2D(mainvp.sector, RenderState); });
|
2018-09-02 09:34:18 +00:00
|
|
|
PostProcess.Unclock();
|
2016-07-29 19:31:20 +00:00
|
|
|
}
|
2018-06-19 21:16:22 +00:00
|
|
|
di->EndDrawInfo();
|
2019-03-03 17:35:38 +00:00
|
|
|
if (eyeCount - eye_ix > 1)
|
2020-04-25 08:51:45 +00:00
|
|
|
screen->NextEye(eyeCount);
|
2015-10-31 00:51:35 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-06-20 08:47:03 +00:00
|
|
|
return mainvp.sector;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|