- made the scene scale and offset calculations inline functions of DFrameBuffer.

These got repeated quite often.
This commit is contained in:
Christoph Oelckers 2018-06-17 12:23:29 +02:00
parent 1fdf6a20d1
commit e9e1911fa5
2 changed files with 28 additions and 24 deletions

View file

@ -102,13 +102,8 @@ void FGLRenderer::AmbientOccludeScene()
float blurSharpness = 1.0f / blurAmount; float blurSharpness = 1.0f / blurAmount;
const auto &mSceneViewport = screen->mSceneViewport; auto sceneScale = screen->SceneScale();
const auto &mScreenViewport = screen->mScreenViewport; auto sceneOffset = screen->SceneOffset();
float sceneScaleX = mSceneViewport.width / (float)mScreenViewport.width;
float sceneScaleY = mSceneViewport.height / (float)mScreenViewport.height;
float sceneOffsetX = mSceneViewport.left / (float)mScreenViewport.width;
float sceneOffsetY = mSceneViewport.top / (float)mScreenViewport.height;
int randomTexture = clamp(gl_ssao - 1, 0, FGLRenderBuffers::NumAmbientRandomTextures - 1); int randomTexture = clamp(gl_ssao - 1, 0, FGLRenderBuffers::NumAmbientRandomTextures - 1);
@ -123,8 +118,8 @@ void FGLRenderer::AmbientOccludeScene()
mLinearDepthShader->Uniforms->LinearizeDepthB = MAX(1.0f / GetZNear(), 1.e-8f); mLinearDepthShader->Uniforms->LinearizeDepthB = MAX(1.0f / GetZNear(), 1.e-8f);
mLinearDepthShader->Uniforms->InverseDepthRangeA = 1.0f; mLinearDepthShader->Uniforms->InverseDepthRangeA = 1.0f;
mLinearDepthShader->Uniforms->InverseDepthRangeB = 0.0f; mLinearDepthShader->Uniforms->InverseDepthRangeB = 0.0f;
mLinearDepthShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mLinearDepthShader->Uniforms->Scale = sceneScale;
mLinearDepthShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; mLinearDepthShader->Uniforms->Offset = sceneOffset;
mLinearDepthShader->Uniforms.Set(); mLinearDepthShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
@ -143,8 +138,8 @@ void FGLRenderer::AmbientOccludeScene()
mSSAOShader->Uniforms->RadiusToScreen = aoRadius * 0.5 / tanHalfFovy * mBuffers->AmbientHeight; mSSAOShader->Uniforms->RadiusToScreen = aoRadius * 0.5 / tanHalfFovy * mBuffers->AmbientHeight;
mSSAOShader->Uniforms->AOMultiplier = 1.0f / (1.0f - nDotVBias); mSSAOShader->Uniforms->AOMultiplier = 1.0f / (1.0f - nDotVBias);
mSSAOShader->Uniforms->AOStrength = aoStrength; mSSAOShader->Uniforms->AOStrength = aoStrength;
mSSAOShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mSSAOShader->Uniforms->Scale = sceneScale;
mSSAOShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; mSSAOShader->Uniforms->Offset = sceneOffset;
mSSAOShader->Uniforms.Set(); mSSAOShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
@ -184,8 +179,8 @@ void FGLRenderer::AmbientOccludeScene()
mBuffers->BindSceneFogTexture(1); mBuffers->BindSceneFogTexture(1);
mSSAOCombineShader->Bind(NOQUEUE); mSSAOCombineShader->Bind(NOQUEUE);
if (gl_multisample > 1) mSSAOCombineShader->Uniforms->SampleCount = gl_multisample; if (gl_multisample > 1) mSSAOCombineShader->Uniforms->SampleCount = gl_multisample;
mSSAOCombineShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mSSAOCombineShader->Uniforms->Scale = screen->SceneScale();
mSSAOCombineShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; mSSAOCombineShader->Uniforms->Offset = screen->SceneOffset();
mSSAOCombineShader->Uniforms.Set(); mSSAOCombineShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
@ -208,17 +203,14 @@ void FGLRenderer::UpdateCameraExposure()
FGLPostProcessState savedState; FGLPostProcessState savedState;
savedState.SaveTextureBindings(2); savedState.SaveTextureBindings(2);
const auto &mSceneViewport = screen->mSceneViewport;
const auto &mScreenViewport = screen->mScreenViewport;
// Extract light level from scene texture: // Extract light level from scene texture:
auto &level0 = mBuffers->ExposureLevels[0]; auto &level0 = mBuffers->ExposureLevels[0];
level0.Framebuffer.Bind(); level0.Framebuffer.Bind();
glViewport(0, 0, level0.Width, level0.Height); glViewport(0, 0, level0.Width, level0.Height);
mBuffers->BindCurrentTexture(0, GL_LINEAR); mBuffers->BindCurrentTexture(0, GL_LINEAR);
mExposureExtractShader->Bind(NOQUEUE); mExposureExtractShader->Bind(NOQUEUE);
mExposureExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height }; mExposureExtractShader->Uniforms->Scale = screen->SceneScale();
mExposureExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height }; mExposureExtractShader->Uniforms->Offset = screen->SceneOffset();
mExposureExtractShader->Uniforms.Set(); mExposureExtractShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
@ -256,6 +248,8 @@ void FGLRenderer::UpdateCameraExposure()
mExposureCombineShader->Uniforms->ExposureSpeed = gl_exposure_speed; mExposureCombineShader->Uniforms->ExposureSpeed = gl_exposure_speed;
mExposureCombineShader->Uniforms.Set(); mExposureCombineShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
const auto &mScreenViewport = screen->mScreenViewport;
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
FGLDebug::PopGroup(); FGLDebug::PopGroup();
@ -323,17 +317,14 @@ void FGLRenderer::BloomScene(int fixedcm)
auto &level0 = mBuffers->BloomLevels[0]; auto &level0 = mBuffers->BloomLevels[0];
const auto &mSceneViewport = screen->mSceneViewport;
const auto &mScreenViewport = screen->mScreenViewport;
// Extract blooming pixels from scene texture: // Extract blooming pixels from scene texture:
level0.VFramebuffer.Bind(); level0.VFramebuffer.Bind();
glViewport(0, 0, level0.Width, level0.Height); glViewport(0, 0, level0.Width, level0.Height);
mBuffers->BindCurrentTexture(0, GL_LINEAR); mBuffers->BindCurrentTexture(0, GL_LINEAR);
mBuffers->ExposureTexture.Bind(1); mBuffers->ExposureTexture.Bind(1);
mBloomExtractShader->Bind(NOQUEUE); mBloomExtractShader->Bind(NOQUEUE);
mBloomExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height }; mBloomExtractShader->Uniforms->Scale = screen->SceneScale();
mBloomExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height }; mBloomExtractShader->Uniforms->Offset = screen->SceneOffset();
mBloomExtractShader->Uniforms.Set(); mBloomExtractShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
@ -366,6 +357,9 @@ void FGLRenderer::BloomScene(int fixedcm)
RenderBlur(this, blurAmount, level0.VTexture, level0.HFramebuffer, level0.Width, level0.Height, false); RenderBlur(this, blurAmount, level0.VTexture, level0.HFramebuffer, level0.Width, level0.Height, false);
RenderBlur(this, blurAmount, level0.HTexture, level0.VFramebuffer, level0.Width, level0.Height, true); RenderBlur(this, blurAmount, level0.HTexture, level0.VFramebuffer, level0.Width, level0.Height, true);
const auto &mSceneViewport = screen->mSceneViewport;
const auto &mScreenViewport = screen->mScreenViewport;
// Add bloom back to scene texture: // Add bloom back to scene texture:
mBuffers->BindCurrentFB(); mBuffers->BindCurrentFB();
glViewport(mSceneViewport.left, mSceneViewport.top, mSceneViewport.width, mSceneViewport.height); glViewport(mSceneViewport.left, mSceneViewport.top, mSceneViewport.width, mSceneViewport.height);
@ -754,7 +748,7 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
mPresentShader->Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.f); mPresentShader->Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.f);
mPresentShader->Uniforms->GrayFormula = static_cast<int>(gl_satformula); mPresentShader->Uniforms->GrayFormula = static_cast<int>(gl_satformula);
} }
mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() }; mPresentShader->Uniforms->Scale = screen->SceneScale();
mPresentShader->Uniforms.Set(); mPresentShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
} }

View file

@ -364,6 +364,16 @@ public:
inline int GetWidth() const { return Width; } inline int GetWidth() const { return Width; }
inline int GetHeight() const { return Height; } inline int GetHeight() const { return Height; }
FVector2 SceneScale() const
{
return { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height };
}
FVector2 SceneOffset() const
{
return { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height };
}
// Make the surface visible. // Make the surface visible.
virtual void Update () = 0; virtual void Update () = 0;