diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index 2ff7ff5695..b92b832a8f 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -50,7 +50,7 @@ CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE) VSMatrix FGLModelRenderer::GetViewToWorldMatrix() { VSMatrix objectToWorldMatrix; - gl_RenderState.mViewMatrix.inverseMatrix(objectToWorldMatrix); + di->VPUniforms.mViewMatrix.inverseMatrix(objectToWorldMatrix); return objectToWorldMatrix; } diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index 9cab5ecfca..fb044c49f5 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -29,12 +29,14 @@ #include "r_data/models/models.h" class GLSprite; +struct FDrawInfo; class FGLModelRenderer : public FModelRenderer { int modellightindex = -1; + FDrawInfo *di; public: - FGLModelRenderer(int mli) : modellightindex(mli) + FGLModelRenderer(FDrawInfo *d, int mli) : modellightindex(mli), di(d) {} ModelRendererType GetType() const override { return GLModelRendererType; } void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override; diff --git a/src/gl/renderer/gl_lightdata.h b/src/gl/renderer/gl_lightdata.h index db7a87e19d..8fcd9809fb 100644 --- a/src/gl/renderer/gl_lightdata.h +++ b/src/gl/renderer/gl_lightdata.h @@ -2,7 +2,7 @@ #define __GL_LIGHTDATA #include "v_palette.h" -#include "p_3dfloors.h" +#include "r_defs.h" #include "r_data/renderstyle.h" #include "hwrenderer/utility/hw_lighting.h" #include "r_data/colormaps.h" diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index ba9e605cb7..61e69f2d74 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -81,7 +81,7 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function &aft // //----------------------------------------------------------------------------- -void FGLRenderer::AmbientOccludeScene() +void FGLRenderer::AmbientOccludeScene(float m5) { FGLDebug::PushGroup("AmbientOccludeScene"); @@ -94,7 +94,7 @@ void FGLRenderer::AmbientOccludeScene() float aoStrength = gl_ssao_strength; //float tanHalfFovy = tan(fovy * (M_PI / 360.0f)); - float tanHalfFovy = 1.0f / gl_RenderState.mProjectionMatrix.get()[5]; + float tanHalfFovy = 1.0f / m5; float invFocalLenX = tanHalfFovy * (mBuffers->GetSceneWidth() / (float)mBuffers->GetSceneHeight()); float invFocalLenY = tanHalfFovy; float nDotVBias = clamp(bias, 0.0f, 1.0f); diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 6029c5139a..6bd2a61887 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -467,9 +467,11 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) const auto &mScreenViewport = screen->mScreenViewport; glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); - gl_RenderState.mViewMatrix.loadIdentity(); - gl_RenderState.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); - gl_RenderState.ApplyMatrices(); + HWViewpointUniforms matrices; + matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); + matrices.mViewMatrix.loadIdentity(); + matrices.CalcDependencies(); + GLRenderer->mShaderManager->ApplyMatrices(&matrices.mProjectionMatrix, &matrices.mViewMatrix, &matrices.mNormalViewMatrix, NORMAL_PASS); glDisable(GL_DEPTH_TEST); diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 71368e6441..4cd28c730a 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -128,7 +128,7 @@ public: void RenderScreenQuad(); void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D); - void AmbientOccludeScene(); + void AmbientOccludeScene(float m5); void UpdateCameraExposure(); void BloomScene(int fixedcm); void TonemapScene(); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 69ada9f306..0d891efc8a 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -107,8 +107,6 @@ void FRenderState::Reset() mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f); mEffectState = 0; activeShader = nullptr; - mProjectionMatrix.loadIdentity(); - mViewMatrix.loadIdentity(); mModelMatrix.loadIdentity(); mTextureMatrix.loadIdentity(); mPassType = NORMAL_PASS; @@ -304,17 +302,6 @@ void FRenderState::ApplyColorMask() } } -void FRenderState::ApplyMatrices() -{ - if (GLRenderer->mShaderManager != NULL) - { - VSMatrix norm; - norm.computeNormalMatrix(mViewMatrix); - - GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix, &norm, mPassType); - } -} - void FRenderState::ApplyLightIndex(int index) { if (index > -1 && GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER) diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index b188b42d23..21d0f22657 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -131,11 +131,8 @@ class FRenderState public: - VSMatrix mProjectionMatrix; - VSMatrix mViewMatrix; VSMatrix mModelMatrix; VSMatrix mTextureMatrix; - VSMatrix mNormalViewMatrix; FRenderState() { @@ -162,7 +159,6 @@ public: void Apply(); void ApplyColorMask(); - void ApplyMatrices(); void ApplyLightIndex(int index); void SetVertexBuffer(FVertexBuffer *vb) diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 20d8160234..da5c5fa38e 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -190,12 +190,14 @@ FDrawInfo::~FDrawInfo() // OpenGL has no use for multiple clippers so use the same one for all DrawInfos. static Clipper staticClipper; -FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp) +FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) { FDrawInfo *di=di_list.GetNew(); di->mVBO = GLRenderer->mVBO; di->mClipper = &staticClipper; di->Viewpoint = parentvp; + if (uniforms) di->VPUniforms = *uniforms; + else di->VPUniforms.SetDefaults(); di->mClipper->SetViewpoint(di->Viewpoint); staticClipper.Clear(); di->StartScene(); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index ec84e711d1..988e5b9393 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -4,6 +4,7 @@ #include "gl/renderer/gl_lightdata.h" #include "hwrenderer/scene/hw_drawlist.h" #include "hwrenderer/scene/hw_weapon.h" +#include "hwrenderer/scene/hw_viewpointuniforms.h" #ifdef _MSC_VER #pragma warning(disable:4244) @@ -42,6 +43,8 @@ struct FDrawInfo : public HWDrawInfo FDrawInfo(); ~FDrawInfo(); + void ApplyVPUniforms() override; + void AddWall(GLWall *wall) override; void AddMirrorSurface(GLWall *w) override; GLDecal *AddDecal(bool onmirror) override; @@ -110,12 +113,11 @@ struct FDrawInfo : public HWDrawInfo void DrawEndScene2D(sector_t * viewsector); // These should go into hwrenderer later. - void SetProjection(VSMatrix matrix); void SetViewMatrix(const FRotator &angles, float vx, float vy, float vz, bool mirror, bool planemirror); void SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror); - static FDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp); + static FDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); FDrawInfo *EndDrawInfo(); gl_subsectorrendernode * GetOtherFloorPlanes(unsigned int sector) diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index c531ca308c..d516e37eee 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -93,15 +93,13 @@ void GLPortal::BeginScene() // // //========================================================================== -void GLPortal::ClearScreen() +void GLPortal::ClearScreen(FDrawInfo *di) { bool multi = !!glIsEnabled(GL_MULTISAMPLE); - gl_MatrixStack.Push(gl_RenderState.mViewMatrix); - gl_MatrixStack.Push(gl_RenderState.mProjectionMatrix); - gl_RenderState.mViewMatrix.loadIdentity(); - gl_RenderState.mProjectionMatrix.ortho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1.0f, 1.0f); - gl_RenderState.ApplyMatrices(); + di->VPUniforms.mViewMatrix.loadIdentity(); + di->VPUniforms.mProjectionMatrix.ortho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1.0f, 1.0f); + di->ApplyVPUniforms(); gl_RenderState.SetColor(0, 0, 0); gl_RenderState.Apply(); @@ -111,9 +109,6 @@ void GLPortal::ClearScreen() glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::FULLSCREEN_INDEX, 4); glEnable(GL_DEPTH_TEST); - gl_MatrixStack.Pop(gl_RenderState.mProjectionMatrix); - gl_MatrixStack.Pop(gl_RenderState.mViewMatrix); - gl_RenderState.ApplyMatrices(); if (multi) glEnable(GL_MULTISAMPLE); } @@ -162,6 +157,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn *pDi = nullptr; rendered_portals++; Clocker c(PortalAll); + + *pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint, &outer_di->VPUniforms); if (usestencil) { if (!gl_portals) @@ -226,7 +223,6 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn return false; } } - *pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint); } else { @@ -244,7 +240,6 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn gl_RenderState.SetEffect(EFF_NONE); glDisable(GL_DEPTH_TEST); glDepthMask(false); // don't write to Z-buffer! - *pDi = outer_di; } } recursion++; @@ -253,15 +248,10 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn } else { - if (NeedDepthBuffer()) - { - *pDi = FDrawInfo::StartDrawInfo(outer_di->Viewpoint); - } - else + if (!NeedDepthBuffer()) { glDepthMask(false); glDisable(GL_DEPTH_TEST); - *pDi = outer_di; } } @@ -318,9 +308,10 @@ void GLPortal::End(FDrawInfo *di, bool usestencil) if (PrevPortal != nullptr) PrevPortal->PopState(); GLRenderer->mCurrentPortal = PrevPortal; + di = di->EndDrawInfo(); + di->ApplyVPUniforms(); if (usestencil) { - if (needdepth) di = di->EndDrawInfo(); auto &vp = di->Viewpoint; // Restore the old view @@ -368,7 +359,6 @@ void GLPortal::End(FDrawInfo *di, bool usestencil) { if (needdepth) { - di = di->EndDrawInfo(); glClear(GL_DEPTH_BUFFER_BIT); } else @@ -561,7 +551,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di) if (skyboxrecursion >= 3) { - ClearScreen(); + ClearScreen(di); return; } auto &vp = di->Viewpoint; @@ -732,7 +722,7 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) { if (renderdepth > r_mirror_recursions) { - ClearScreen(); + ClearScreen(di); return; } // A plane mirror needs to flip the portal exclusion logic because inside the mirror, up is down and down is up. @@ -856,7 +846,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) { if (renderdepth>r_mirror_recursions) { - ClearScreen(); + ClearScreen(di); return; } @@ -958,7 +948,7 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di) // TODO: Handle recursion more intelligently if (renderdepth>r_mirror_recursions) { - ClearScreen(); + ClearScreen(di); return; } auto &vp = di->Viewpoint; @@ -1111,7 +1101,7 @@ void GLHorizonPortal::DrawContents(FDrawInfo *di) gltexture=FMaterial::ValidateTexture(sp->texture, false, true); if (!gltexture) { - ClearScreen(); + ClearScreen(di); return; } gl_RenderState.SetCameraPos(vp.Pos.X, vp.Pos.Y, vp.Pos.Z); diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index cb05fb3795..a6d153aa7a 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -88,7 +88,7 @@ protected: virtual bool IsSky() { return false; } virtual bool NeedCap() { return true; } virtual bool NeedDepthBuffer() { return true; } - void ClearScreen(); + void ClearScreen(FDrawInfo *di); virtual const char *GetName() = 0; virtual void PushState() {} virtual void PopState() {} diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 27d5172263..75874aafe9 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -71,17 +71,11 @@ EXTERN_CVAR (Bool, r_deathcamera) EXTERN_CVAR (Float, r_visibility) EXTERN_CVAR (Bool, r_drawvoxels) -//----------------------------------------------------------------------------- -// -// SetProjection -// sets projection matrix -// -//----------------------------------------------------------------------------- -void FDrawInfo::SetProjection(VSMatrix matrix) +void FDrawInfo::ApplyVPUniforms() { - gl_RenderState.mProjectionMatrix.loadIdentity(); - gl_RenderState.mProjectionMatrix.multMatrix(matrix); + VPUniforms.CalcDependencies(); + GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms.mProjectionMatrix, &VPUniforms.mViewMatrix, &VPUniforms.mNormalViewMatrix, NORMAL_PASS); } //----------------------------------------------------------------------------- @@ -95,12 +89,12 @@ void FDrawInfo::SetViewMatrix(const FRotator &angles, float vx, float vy, float float mult = mirror? -1:1; float planemult = planemirror? -level.info->pixelstretch : level.info->pixelstretch; - gl_RenderState.mViewMatrix.loadIdentity(); - gl_RenderState.mViewMatrix.rotate(angles.Roll.Degrees, 0.0f, 0.0f, 1.0f); - gl_RenderState.mViewMatrix.rotate(angles.Pitch.Degrees, 1.0f, 0.0f, 0.0f); - gl_RenderState.mViewMatrix.rotate(angles.Yaw.Degrees, 0.0f, mult, 0.0f); - gl_RenderState.mViewMatrix.translate(vx * mult, -vz * planemult , -vy); - gl_RenderState.mViewMatrix.scale(-mult, planemult, 1); + VPUniforms.mViewMatrix.loadIdentity(); + VPUniforms.mViewMatrix.rotate(angles.Roll.Degrees, 0.0f, 0.0f, 1.0f); + VPUniforms.mViewMatrix.rotate(angles.Pitch.Degrees, 1.0f, 0.0f, 0.0f); + VPUniforms.mViewMatrix.rotate(angles.Yaw.Degrees, 0.0f, mult, 0.0f); + VPUniforms.mViewMatrix.translate(vx * mult, -vz * planemult , -vy); + VPUniforms.mViewMatrix.scale(-mult, planemult, 1); } @@ -114,7 +108,7 @@ void FDrawInfo::SetupView(FRenderViewpoint &vp, float vx, float vy, float vz, DA { vp.SetViewAngle(r_viewwindow); SetViewMatrix(vp.HWAngles, vx, vy, vz, mirror, planemirror); - gl_RenderState.ApplyMatrices(); + ApplyVPUniforms(); } //----------------------------------------------------------------------------- @@ -364,11 +358,11 @@ void FDrawInfo::DrawScene(int drawmode) if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) { gl_RenderState.EnableDrawBuffers(1); - GLRenderer->AmbientOccludeScene(); + GLRenderer->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]); GLRenderer->mBuffers->BindSceneFB(true); gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); gl_RenderState.Apply(); - gl_RenderState.ApplyMatrices(); + ApplyVPUniforms(); } // Handle all portals after rendering the opaque objects but before @@ -414,9 +408,9 @@ void FDrawInfo::DrawEndScene2D(sector_t * viewsector) const bool renderHUDModel = IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); // This should be removed once all 2D stuff is really done through the 2D interface. - gl_RenderState.mViewMatrix.loadIdentity(); - gl_RenderState.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); - gl_RenderState.ApplyMatrices(); + VPUniforms.mViewMatrix.loadIdentity(); + VPUniforms.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); + ApplyVPUniforms(); glDisable(GL_DEPTH_TEST); glDisable(GL_MULTISAMPLE); @@ -510,20 +504,20 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came screen->SetViewportRects(bounds); Set3DViewport(mainview); - FDrawInfo *di = FDrawInfo::StartDrawInfo(mainvp); + FDrawInfo *di = FDrawInfo::StartDrawInfo(mainvp, nullptr); auto vp = di->Viewpoint; di->SetViewArea(); 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) // Stereo mode specific perspective projection - di->SetProjection( eye->GetProjection(fov, ratio, fovratio) ); + di->VPUniforms.mProjectionMatrix = eye->GetProjection(fov, ratio, fovratio); vp.SetViewAngle(r_viewwindow); // Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos eye->GetViewShift(vp.HWAngles.Yaw.Degrees, viewShift); ScopedViewShifter viewShifter(vp.Pos, viewShift); di->SetViewMatrix(vp.HWAngles, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - gl_RenderState.ApplyMatrices(); + di->ApplyVPUniforms(); di->ProcessScene(toscreen); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 59165ae317..1ca523705a 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -230,7 +230,6 @@ void GLSkyPortal::DrawContents(FDrawInfo *di) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); bool oldClamp = gl_RenderState.SetDepthClamp(true); - gl_MatrixStack.Push(gl_RenderState.mViewMatrix); di->SetupView(vp, 0, 0, 0, vp.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO); @@ -270,8 +269,7 @@ void GLSkyPortal::DrawContents(FDrawInfo *di) } } gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); - gl_MatrixStack.Pop(gl_RenderState.mViewMatrix); - gl_RenderState.ApplyMatrices(); + di->ApplyVPUniforms(); ::level.lightmode = oldlightmode; gl_RenderState.SetDepthClamp(oldClamp); } diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 68765d91d9..a17241142a 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -277,7 +277,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) } else { - FGLModelRenderer renderer(sprite->dynlightindex); + FGLModelRenderer renderer(this, sprite->dynlightindex); renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, vp.TicFrac); } } diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 83f9aa2df1..8c989313bb 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -93,7 +93,6 @@ void FDrawInfo::RenderMirrorSurface(GLWall *wall) // we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is. gl_RenderState.EnableTextureMatrix(true); - gl_RenderState.mTextureMatrix.computeNormalMatrix(gl_RenderState.mViewMatrix); // Use sphere mapping for this gl_RenderState.SetEffect(EFF_SPHEREMAP); diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 5f44bf363c..fdc10ef19c 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -65,7 +65,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds) if (huds->mframe) { gl_RenderState.AlphaFunc(GL_GEQUAL, 0); - FGLModelRenderer renderer(huds->lightindex); + FGLModelRenderer renderer(this, huds->lightindex); renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); } else @@ -91,7 +91,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds) void FDrawInfo::DrawPlayerSprites(bool hudModelStep) { - s3d::Stereo3DMode::getCurrentMode().AdjustPlayerSprites(); + s3d::Stereo3DMode::getCurrentMode().AdjustPlayerSprites(this); int oldlightmode = level.lightmode; if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that. diff --git a/src/gl/stereo3d/gl_sidebyside3d.cpp b/src/gl/stereo3d/gl_sidebyside3d.cpp index a8a216dd85..4f18033e15 100644 --- a/src/gl/stereo3d/gl_sidebyside3d.cpp +++ b/src/gl/stereo3d/gl_sidebyside3d.cpp @@ -33,6 +33,7 @@ ** */ +#include "gl/scene/gl_drawinfo.h" #include "gl_sidebyside3d.h" #include "gl/renderer/gl_renderbuffers.h" @@ -98,13 +99,13 @@ SideBySideFull::SideBySideFull(double ipdMeters) } /* virtual */ -void SideBySideFull::AdjustPlayerSprites() const /* override */ +void SideBySideFull::AdjustPlayerSprites(FDrawInfo *di) const /* override */ { // Show weapon at double width, so it would appear normal width after rescaling int w = screen->mScreenViewport.width; int h = screen->mScreenViewport.height; - gl_RenderState.mProjectionMatrix.ortho(w/2, w + w/2, h, 0, -1.0f, 1.0f); - gl_RenderState.ApplyMatrices(); + di->VPUniforms.mProjectionMatrix.ortho(w/2, w + w/2, h, 0, -1.0f, 1.0f); + di->ApplyVPUniforms(); } /* static */ diff --git a/src/gl/stereo3d/gl_sidebyside3d.h b/src/gl/stereo3d/gl_sidebyside3d.h index 78c07d0adb..071474c46e 100644 --- a/src/gl/stereo3d/gl_sidebyside3d.h +++ b/src/gl/stereo3d/gl_sidebyside3d.h @@ -82,7 +82,7 @@ class SideBySideFull : public SideBySideBase public: static const SideBySideFull& getInstance(float ipd); SideBySideFull(double ipdMeters); - virtual void AdjustPlayerSprites() const override; + virtual void AdjustPlayerSprites(FDrawInfo *di) const override; private: SBSFLeftEyePose leftEye; SBSFRightEyePose rightEye; diff --git a/src/gl/stereo3d/gl_stereo3d.h b/src/gl/stereo3d/gl_stereo3d.h index b7c4ef1414..542d45551f 100644 --- a/src/gl/stereo3d/gl_stereo3d.h +++ b/src/gl/stereo3d/gl_stereo3d.h @@ -78,7 +78,7 @@ public: virtual bool IsMono() const { return false; } virtual void AdjustViewports() const {}; - virtual void AdjustPlayerSprites() const {}; + virtual void AdjustPlayerSprites(FDrawInfo *di) const {}; virtual void Present() const = 0; protected: diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index da71df30c1..37e5f9f454 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -342,7 +342,7 @@ IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex) FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli) { - return new FGLModelRenderer(mli); + return new FGLModelRenderer(nullptr, mli); } IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticuse) diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 317fea51d0..11c3c8e5f4 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -3,6 +3,7 @@ #include #include "r_defs.h" #include "r_utility.h" +#include "hw_viewpointuniforms.h" struct FSectorPortalGroup; @@ -19,6 +20,7 @@ struct HUDSprite; class Clipper; class IPortal; class FFlatVertexGenerator; +class IRenderQueue; //========================================================================== // @@ -99,6 +101,7 @@ struct HWDrawInfo IShadowMap *mShadowMap; Clipper *mClipper; FRenderViewpoint Viewpoint; + HWViewpointUniforms VPUniforms; // per-viewpoint uniform state TArray MissingUpperTextures; TArray MissingLowerTextures; @@ -207,6 +210,7 @@ public: virtual void AddHUDSprite(HUDSprite *huds) = 0; virtual int UploadLights(FDynLightData &data) = 0; + virtual void ApplyVPUniforms() = 0; virtual GLDecal *AddDecal(bool onmirror) = 0; virtual std::pair AllocVertices(unsigned int count) = 0; diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h index 5d0a888b83..1fdbcc4d17 100644 --- a/src/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -12,4 +12,12 @@ struct HWViewpointUniforms { mNormalViewMatrix.computeNormalMatrix(mViewMatrix); } + + void SetDefaults() + { + mProjectionMatrix.loadIdentity(); + mViewMatrix.loadIdentity(); + mNormalViewMatrix.loadIdentity(); + } + }; diff --git a/src/hwrenderer/scene/hw_weapon.h b/src/hwrenderer/scene/hw_weapon.h index 935aabb759..62c5a70a04 100644 --- a/src/hwrenderer/scene/hw_weapon.h +++ b/src/hwrenderer/scene/hw_weapon.h @@ -8,6 +8,7 @@ class AActor; enum area_t : int; struct FSpriteModelFrame; struct HWDrawInfo; +class FMaterial; struct WeaponPosition diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 02188cad33..8de8727f1c 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -1032,7 +1032,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor double alen = sqrt(angx*angx + angy*angy); viewpoint.HWAngles.Pitch = RAD2DEG((float)asin(angy / alen)); - viewpoint.HWAngles.Roll.Degrees = viewpoint.Angles.Roll.Degrees; // copied for convenience. + viewpoint.HWAngles.Roll.Degrees = (float)viewpoint.Angles.Roll.Degrees; // copied for convenience. // ViewActor only gets set, if the camera actor should not be rendered if (actor->player && actor->player - players == consoleplayer && diff --git a/src/swrenderer/scene/r_3dfloors.h b/src/swrenderer/scene/r_3dfloors.h index 0237ca95eb..a74e1fc53a 100644 --- a/src/swrenderer/scene/r_3dfloors.h +++ b/src/swrenderer/scene/r_3dfloors.h @@ -1,7 +1,7 @@ #pragma once -#include "p_3dfloors.h" +#include "r_defs.h" #include EXTERN_CVAR(Int, r_3dfloors); diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index db57c67a4b..1089cadcb2 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -68,7 +68,7 @@ void main() #ifdef SPHEREMAP vec3 u = normalize(eyeCoordPos.xyz); - vec4 n = normalize(TextureMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.0)); // use texture matrix and coordinates for our normal. Since this is only used on walls, the normal's y coordinate is always 0. + vec4 n = normalize(NormalViewMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.0)); vec3 r = reflect(u, n.xyz); float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) ); vec2 sst = vec2(r.x/m + 0.5, r.y/m + 0.5);