2016-09-14 20:01:13 +02: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 09:49:34 +02:00
|
|
|
/*
|
|
|
|
** gl_scene.cpp
|
|
|
|
** manages the rendering of the player's view
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2018-05-16 23:34:52 +02:00
|
|
|
#include "gl_load/gl_system.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
#include "gi.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "r_data/r_interpolate.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "p_effect.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "po_man.h"
|
|
|
|
#include "p_local.h"
|
2016-09-24 01:47:44 +02:00
|
|
|
#include "serializer.h"
|
2017-01-08 18:45:30 +01:00
|
|
|
#include "g_levellocals.h"
|
2018-10-27 22:04:13 +02:00
|
|
|
#include "r_data/models/models.h"
|
2018-04-16 09:02:48 +02:00
|
|
|
#include "hwrenderer/dynlights/hw_dynlightdata.h"
|
2018-10-27 22:04:13 +02:00
|
|
|
#include "hwrenderer/utility/hw_clock.h"
|
|
|
|
#include "hwrenderer/data/flatvertices.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2018-10-28 15:09:33 +01:00
|
|
|
#include "hwrenderer/dynlights/hw_lightbuffer.h"
|
2018-05-16 23:21:21 +02:00
|
|
|
#include "gl_load/gl_interface.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
#include "gl/system/gl_framebuffer.h"
|
2018-06-30 15:24:13 +02:00
|
|
|
#include "gl/system/gl_debug.h"
|
2018-04-25 20:33:55 +02:00
|
|
|
#include "hwrenderer/utility/hw_cvars.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
#include "gl/renderer/gl_renderstate.h"
|
2016-07-26 21:27:02 +02:00
|
|
|
#include "gl/renderer/gl_renderbuffers.h"
|
2018-10-28 13:26:47 +01:00
|
|
|
#include "hwrenderer/data/hw_viewpointbuffer.h"
|
2018-04-23 22:18:13 +02:00
|
|
|
#include "hwrenderer/scene/hw_clipper.h"
|
2018-06-23 13:25:23 +02:00
|
|
|
#include "hwrenderer/scene/hw_portal.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
#include "gl/scene/gl_drawinfo.h"
|
2018-06-24 13:39:14 +02:00
|
|
|
#include "hwrenderer/utility/hw_vrmodes.h"
|
2018-10-25 00:25:55 +02:00
|
|
|
#include "gl/renderer/gl_renderer.h"
|
2013-06-23 09:49:34 +02:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CVARs
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
CVAR(Bool, gl_texture, true, 0)
|
|
|
|
CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
|
|
|
|
EXTERN_CVAR (Bool, cl_capfps)
|
|
|
|
EXTERN_CVAR (Bool, r_deathcamera)
|
2017-07-09 19:01:34 +02:00
|
|
|
EXTERN_CVAR (Float, r_visibility)
|
2017-07-30 10:44:49 -04:00
|
|
|
EXTERN_CVAR (Bool, r_drawvoxels)
|
2013-06-23 09:49:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// gl_drawscene - this function renders the scene from the current
|
2018-04-01 22:26:57 +02:00
|
|
|
// viewpoint, including mirrors and skyboxes and other portals
|
2018-10-24 07:49:06 +02:00
|
|
|
// It is assumed that the HWPortal::EndFrame returns with the
|
2013-06-23 09:49:34 +02:00
|
|
|
// stencil, z-buffer and the projection matrix intact!
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
void FDrawInfo::DrawScene(int drawmode)
|
2013-06-23 09:49:34 +02:00
|
|
|
{
|
|
|
|
static int recursion=0;
|
2016-09-24 20:09:40 +02:00
|
|
|
static int ssao_portals_available = 0;
|
2018-06-20 11:38:45 +02:00
|
|
|
const auto &vp = Viewpoint;
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2016-10-22 21:35:49 +02:00
|
|
|
bool applySSAO = false;
|
2016-10-22 00:09:06 +02:00
|
|
|
if (drawmode == DM_MAINVIEW)
|
2016-10-22 21:35:49 +02:00
|
|
|
{
|
|
|
|
ssao_portals_available = gl_ssao_portals;
|
|
|
|
applySSAO = true;
|
|
|
|
}
|
2016-10-22 00:09:06 +02:00
|
|
|
else if (drawmode == DM_OFFSCREEN)
|
2016-10-22 21:35:49 +02:00
|
|
|
{
|
2016-10-22 00:09:06 +02:00
|
|
|
ssao_portals_available = 0;
|
2016-10-22 21:35:49 +02:00
|
|
|
}
|
2017-03-11 17:20:06 +01:00
|
|
|
else if (drawmode == DM_PORTAL && ssao_portals_available > 0)
|
2016-10-22 21:35:49 +02:00
|
|
|
{
|
|
|
|
applySSAO = true;
|
|
|
|
ssao_portals_available--;
|
|
|
|
}
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2018-06-19 23:16:22 +02:00
|
|
|
if (vp.camera != nullptr)
|
2016-06-18 12:14:20 +02:00
|
|
|
{
|
2018-06-19 23:16:22 +02:00
|
|
|
ActorRenderFlags savedflags = vp.camera->renderflags;
|
2018-06-20 11:38:45 +02:00
|
|
|
CreateScene();
|
2018-06-19 23:16:22 +02:00
|
|
|
vp.camera->renderflags = savedflags;
|
2016-06-18 12:14:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-20 11:38:45 +02:00
|
|
|
CreateScene();
|
2016-06-18 12:14:20 +02:00
|
|
|
}
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2018-10-28 22:58:35 +01:00
|
|
|
glDepthMask(true);
|
2018-10-28 23:18:19 +01:00
|
|
|
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, gl_RenderState);
|
2018-10-28 22:58:35 +01:00
|
|
|
|
|
|
|
RenderScene(gl_RenderState);
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2016-10-22 21:35:49 +02:00
|
|
|
if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS)
|
2016-09-21 02:04:56 +02:00
|
|
|
{
|
2016-10-22 00:09:06 +02:00
|
|
|
gl_RenderState.EnableDrawBuffers(1);
|
2018-06-21 20:54:34 +02:00
|
|
|
GLRenderer->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]);
|
2018-07-28 19:01:04 +02:00
|
|
|
glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height);
|
2017-03-12 12:03:54 +01:00
|
|
|
GLRenderer->mBuffers->BindSceneFB(true);
|
2016-10-22 00:09:06 +02:00
|
|
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
2016-09-21 02:04:56 +02:00
|
|
|
gl_RenderState.Apply();
|
2018-10-28 22:20:51 +01:00
|
|
|
screen->mViewpoints->Bind(gl_RenderState, vpIndex);
|
2016-09-21 02:04:56 +02:00
|
|
|
}
|
2016-09-03 04:29:50 +02:00
|
|
|
|
2018-04-01 22:26:57 +02:00
|
|
|
// Handle all portals after rendering the opaque objects but before
|
2013-06-23 09:49:34 +02:00
|
|
|
// doing all translucent stuff
|
|
|
|
recursion++;
|
2018-10-28 23:18:19 +01:00
|
|
|
screen->mPortalState->EndFrame(this, gl_RenderState);
|
2013-06-23 09:49:34 +02:00
|
|
|
recursion--;
|
2018-10-28 22:58:35 +01:00
|
|
|
RenderTranslucent(gl_RenderState);
|
2013-06-23 09:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Draws player sprites and color blend
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
void FDrawInfo::EndDrawScene(sector_t * viewsector)
|
2013-06-23 09:49:34 +02:00
|
|
|
{
|
2014-07-26 22:26:17 +02:00
|
|
|
gl_RenderState.EnableFog(false);
|
|
|
|
|
2018-05-04 23:11:37 +02:00
|
|
|
// [BB] HUD models need to be rendered here.
|
2018-05-21 17:52:03 +02:00
|
|
|
const bool renderHUDModel = IsHUDModelForPlayerAvailable( players[consoleplayer].camera->player );
|
2013-06-23 09:49:34 +02:00
|
|
|
if ( renderHUDModel )
|
|
|
|
{
|
|
|
|
// [BB] The HUD model should be drawn over everything else already drawn.
|
2013-09-03 14:05:41 +02:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2018-10-22 23:40:44 +02:00
|
|
|
DrawPlayerSprites(true, gl_RenderState);
|
2013-06-23 09:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:05:41 +02:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
2018-06-20 11:38:45 +02:00
|
|
|
glViewport(screen->mScreenViewport.left, screen->mScreenViewport.top, screen->mScreenViewport.width, screen->mScreenViewport.height);
|
2016-09-19 20:06:52 -04:00
|
|
|
|
2018-06-16 13:47:24 +02:00
|
|
|
// Restore standard rendering state
|
2018-10-21 14:26:14 +02:00
|
|
|
gl_RenderState.SetRenderStyle(STYLE_Translucent);
|
2018-06-16 13:47:24 +02:00
|
|
|
gl_RenderState.ResetColor();
|
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2018-01-06 05:11:12 +01:00
|
|
|
}
|
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
void FDrawInfo::DrawEndScene2D(sector_t * viewsector)
|
2018-01-06 05:11:12 +01:00
|
|
|
{
|
2018-05-21 17:52:03 +02:00
|
|
|
const bool renderHUDModel = IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player);
|
2018-06-24 13:39:14 +02:00
|
|
|
auto vrmode = VRMode::GetVRMode(true);
|
2018-01-06 05:11:12 +01:00
|
|
|
|
2018-08-11 18:25:15 +02:00
|
|
|
HWViewpointUniforms vp = VPUniforms;
|
|
|
|
vp.mViewMatrix.loadIdentity();
|
|
|
|
vp.mProjectionMatrix = vrmode->GetHUDSpriteProjection();
|
2018-10-28 22:20:51 +01:00
|
|
|
screen->mViewpoints->SetViewpoint(gl_RenderState, &vp);
|
2018-04-30 21:42:36 +02:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
|
|
|
|
2018-04-29 22:30:52 +02:00
|
|
|
|
2018-10-22 23:40:44 +02:00
|
|
|
DrawPlayerSprites(false, gl_RenderState);
|
2018-05-04 23:11:37 +02:00
|
|
|
|
2016-09-01 17:14:51 +02:00
|
|
|
gl_RenderState.SetSoftLightLevel(-1);
|
2013-06-23 09:49:34 +02:00
|
|
|
|
|
|
|
// Restore standard rendering state
|
2018-10-21 14:26:14 +02:00
|
|
|
gl_RenderState.SetRenderStyle(STYLE_Translucent);
|
2014-05-11 22:57:42 +02:00
|
|
|
gl_RenderState.ResetColor();
|
2013-06-23 09:49:34 +02:00
|
|
|
gl_RenderState.EnableTexture(true);
|
2013-09-03 14:05:41 +02:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2013-06-23 09:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// R_RenderView - renders one view - either the screen or a camera texture
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
void FDrawInfo::ProcessScene(bool toscreen)
|
2013-06-23 09:49:34 +02:00
|
|
|
{
|
|
|
|
iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0;
|
2018-10-25 00:49:39 +02:00
|
|
|
screen->mPortalState->BeginScene();
|
2013-06-23 09:49:34 +02:00
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection;
|
|
|
|
CurrentMapSections.Set(mapsection);
|
|
|
|
DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
|
2013-06-23 09:49:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:57:41 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// sets 3D viewport and initial state
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-06-30 15:24:13 +02:00
|
|
|
void FGLRenderer::Set3DViewport()
|
2018-06-20 12:57:41 +02:00
|
|
|
{
|
|
|
|
// Always clear all buffers with scissor test disabled.
|
|
|
|
// This is faster on newer hardware because it allows the GPU to skip
|
|
|
|
// reading from slower memory where the full buffers are stored.
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2018-10-29 09:34:30 +01:00
|
|
|
glClearColor(screen->mSceneClearColor[0], screen->mSceneClearColor[1], screen->mSceneClearColor[2], screen->mSceneClearColor[3]);
|
2018-06-20 12:57:41 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
|
|
|
|
const auto &bounds = screen->mSceneViewport;
|
|
|
|
glViewport(bounds.left, bounds.top, bounds.width, bounds.height);
|
|
|
|
glScissor(bounds.left, bounds.top, bounds.width, bounds.height);
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
glEnable(GL_MULTISAMPLE);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
glStencilFunc(GL_ALWAYS,0,~0); // default stencil
|
|
|
|
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
|
|
|
|
}
|
|
|
|
|
2013-06-23 09:49:34 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Renders one viewpoint in a scene
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-06-20 12:57:41 +02:00
|
|
|
sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen)
|
2018-06-20 10:47:03 +02:00
|
|
|
{
|
2018-06-19 23:16:22 +02:00
|
|
|
R_SetupFrame (mainvp, r_viewwindow, camera);
|
2014-12-31 12:04:55 +01:00
|
|
|
|
2018-06-20 10:47:03 +02:00
|
|
|
// Render (potentially) multiple views for stereo 3d
|
2018-06-24 13:39:14 +02: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);
|
|
|
|
for (int eye_ix = 0; eye_ix < vrmode->mEyeCount; ++eye_ix)
|
2015-10-30 20:51:35 -04:00
|
|
|
{
|
2018-06-24 13:39:14 +02:00
|
|
|
const auto &eye = vrmode->mEyes[eye_ix];
|
2018-06-03 13:59:40 +02:00
|
|
|
screen->SetViewportRects(bounds);
|
2018-06-30 15:24:13 +02:00
|
|
|
|
|
|
|
if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao
|
|
|
|
{
|
|
|
|
FGLDebug::PushGroup("MainView");
|
|
|
|
|
|
|
|
bool useSSAO = (gl_ssao != 0);
|
|
|
|
mBuffers->BindSceneFB(useSSAO);
|
|
|
|
gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
|
|
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
Set3DViewport();
|
2018-05-21 22:04:29 +02:00
|
|
|
|
2018-10-28 19:39:31 +01:00
|
|
|
FDrawInfo *di = static_cast<FDrawInfo*>(HWDrawInfo::StartDrawInfo(mainvp, nullptr));
|
2018-06-24 13:39:14 +02:00
|
|
|
auto &vp = di->Viewpoint;
|
2018-05-21 22:04:29 +02:00
|
|
|
di->SetViewArea();
|
2018-06-19 23:16:22 +02:00
|
|
|
auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr);
|
|
|
|
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 22:04:29 +02:00
|
|
|
|
2015-10-30 20:51:35 -04:00
|
|
|
// Stereo mode specific perspective projection
|
2018-06-24 13:39:14 +02:00
|
|
|
di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio);
|
|
|
|
// Stereo mode specific viewpoint adjustment
|
|
|
|
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees);
|
2018-10-28 22:20:51 +01:00
|
|
|
di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);
|
2018-06-22 21:44:53 +02:00
|
|
|
|
2018-06-20 11:38:45 +02:00
|
|
|
di->ProcessScene(toscreen);
|
2018-04-29 11:00:34 +02:00
|
|
|
|
2018-06-16 09:37:01 +02:00
|
|
|
if (mainview)
|
2016-07-29 21:31:20 +02:00
|
|
|
{
|
2018-09-02 11:34:18 +02:00
|
|
|
PostProcess.Clock();
|
2018-06-20 11:38:45 +02:00
|
|
|
if (toscreen) di->EndDrawScene(mainvp.sector); // do not call this for camera textures.
|
2018-06-30 15:24:13 +02:00
|
|
|
|
|
|
|
if (gl_RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers
|
|
|
|
{
|
|
|
|
gl_RenderState.SetPassType(NORMAL_PASS);
|
|
|
|
gl_RenderState.EnableDrawBuffers(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture
|
|
|
|
|
|
|
|
FGLDebug::PopGroup(); // MainView
|
|
|
|
|
2018-06-20 12:57:41 +02:00
|
|
|
PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector); });
|
2018-09-02 11:34:18 +02:00
|
|
|
PostProcess.Unclock();
|
2016-07-29 21:31:20 +02:00
|
|
|
}
|
2018-06-19 23:16:22 +02:00
|
|
|
di->EndDrawInfo();
|
2018-06-24 13:39:14 +02:00
|
|
|
if (vrmode->mEyeCount > 1)
|
2018-06-20 12:57:41 +02:00
|
|
|
mBuffers->BlitToEyeTexture(eye_ix);
|
2015-10-30 20:51:35 -04:00
|
|
|
}
|
2013-06-23 09:49:34 +02:00
|
|
|
|
|
|
|
interpolator.RestoreInterpolations ();
|
2018-06-20 10:47:03 +02:00
|
|
|
return mainvp.sector;
|
2013-06-23 09:49:34 +02:00
|
|
|
}
|
|
|
|
|