mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
Merge pull request #10853 from samcake/brown
Fix projection & lighting issues identified with 2nd rendering pipeline In Master
This commit is contained in:
commit
0f9c917965
12 changed files with 49 additions and 8 deletions
|
@ -79,6 +79,7 @@ public:
|
||||||
|
|
||||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
batch.disableContextStereo();
|
batch.disableContextStereo();
|
||||||
|
batch.disableContextViewCorrection();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto srcViewFrustum = args->getViewFrustum();
|
auto srcViewFrustum = args->getViewFrustum();
|
||||||
|
@ -112,6 +113,7 @@ public:
|
||||||
|
|
||||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
batch.restoreContextStereo();
|
batch.restoreContextStereo();
|
||||||
|
batch.restoreContextViewCorrection();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,7 +114,9 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
(&::gpu::gl::GLBackend::do_getQuery),
|
(&::gpu::gl::GLBackend::do_getQuery),
|
||||||
|
|
||||||
(&::gpu::gl::GLBackend::do_resetStages),
|
(&::gpu::gl::GLBackend::do_resetStages),
|
||||||
|
|
||||||
|
(&::gpu::gl::GLBackend::do_disableContextViewCorrection),
|
||||||
|
(&::gpu::gl::GLBackend::do_restoreContextViewCorrection),
|
||||||
(&::gpu::gl::GLBackend::do_disableContextStereo),
|
(&::gpu::gl::GLBackend::do_disableContextStereo),
|
||||||
(&::gpu::gl::GLBackend::do_restoreContextStereo),
|
(&::gpu::gl::GLBackend::do_restoreContextStereo),
|
||||||
|
|
||||||
|
@ -374,6 +376,13 @@ void GLBackend::do_resetStages(const Batch& batch, size_t paramOffset) {
|
||||||
resetStages();
|
resetStages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLBackend::do_disableContextViewCorrection(const Batch& batch, size_t paramOffset) {
|
||||||
|
_transform._viewCorrectionEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLBackend::do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) {
|
||||||
|
_transform._viewCorrectionEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
void GLBackend::do_disableContextStereo(const Batch& batch, size_t paramOffset) {
|
void GLBackend::do_disableContextStereo(const Batch& batch, size_t paramOffset) {
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,10 @@ public:
|
||||||
// Reset stages
|
// Reset stages
|
||||||
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final;
|
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
|
|
||||||
|
virtual void do_disableContextViewCorrection(const Batch& batch, size_t paramOffset) final;
|
||||||
|
virtual void do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
virtual void do_disableContextStereo(const Batch& batch, size_t paramOffset) final;
|
virtual void do_disableContextStereo(const Batch& batch, size_t paramOffset) final;
|
||||||
virtual void do_restoreContextStereo(const Batch& batch, size_t paramOffset) final;
|
virtual void do_restoreContextStereo(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
|
@ -333,6 +337,8 @@ protected:
|
||||||
bool _skybox { false };
|
bool _skybox { false };
|
||||||
Transform _view;
|
Transform _view;
|
||||||
CameraCorrection _correction;
|
CameraCorrection _correction;
|
||||||
|
bool _viewCorrectionEnabled{ true };
|
||||||
|
|
||||||
|
|
||||||
Mat4 _projection;
|
Mat4 _projection;
|
||||||
Vec4i _viewport { 0, 0, 1, 1 };
|
Vec4i _viewport { 0, 0, 1, 1 };
|
||||||
|
@ -400,6 +406,7 @@ protected:
|
||||||
bool _invalidProgram { false };
|
bool _invalidProgram { false };
|
||||||
|
|
||||||
BufferView _cameraCorrectionBuffer { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
|
BufferView _cameraCorrectionBuffer { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
|
||||||
|
BufferView _cameraCorrectionBufferIdentity { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
|
||||||
|
|
||||||
State::Data _stateCache{ State::DEFAULT };
|
State::Data _stateCache{ State::DEFAULT };
|
||||||
State::Signature _stateSignatureCache { 0 };
|
State::Signature _stateSignatureCache { 0 };
|
||||||
|
@ -409,6 +416,8 @@ protected:
|
||||||
|
|
||||||
PipelineStageState() {
|
PipelineStageState() {
|
||||||
_cameraCorrectionBuffer.edit<CameraCorrection>() = CameraCorrection();
|
_cameraCorrectionBuffer.edit<CameraCorrection>() = CameraCorrection();
|
||||||
|
_cameraCorrectionBufferIdentity.edit<CameraCorrection>() = CameraCorrection();
|
||||||
|
_cameraCorrectionBufferIdentity._buffer->flush();
|
||||||
}
|
}
|
||||||
} _pipeline;
|
} _pipeline;
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,14 @@ void GLBackend::do_setPipeline(const Batch& batch, size_t paramOffset) {
|
||||||
if (_pipeline._invalidProgram) {
|
if (_pipeline._invalidProgram) {
|
||||||
glUseProgram(_pipeline._program);
|
glUseProgram(_pipeline._program);
|
||||||
if (_pipeline._cameraCorrectionLocation != -1) {
|
if (_pipeline._cameraCorrectionLocation != -1) {
|
||||||
auto cameraCorrectionBuffer = syncGPUObject(*_pipeline._cameraCorrectionBuffer._buffer);
|
gl::GLBuffer* cameraCorrectionBuffer = nullptr;
|
||||||
|
if (_transform._viewCorrectionEnabled) {
|
||||||
|
cameraCorrectionBuffer = syncGPUObject(*_pipeline._cameraCorrectionBuffer._buffer);
|
||||||
|
} else {
|
||||||
|
cameraCorrectionBuffer = syncGPUObject(*_pipeline._cameraCorrectionBufferIdentity._buffer);
|
||||||
|
}
|
||||||
glBindBufferRange(GL_UNIFORM_BUFFER, _pipeline._cameraCorrectionLocation, cameraCorrectionBuffer->_id, 0, sizeof(CameraCorrection));
|
glBindBufferRange(GL_UNIFORM_BUFFER, _pipeline._cameraCorrectionLocation, cameraCorrectionBuffer->_id, 0, sizeof(CameraCorrection));
|
||||||
|
|
||||||
}
|
}
|
||||||
(void) CHECK_GL_ERROR();
|
(void) CHECK_GL_ERROR();
|
||||||
_pipeline._invalidProgram = false;
|
_pipeline._invalidProgram = false;
|
||||||
|
|
|
@ -102,7 +102,7 @@ void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const Stereo
|
||||||
|
|
||||||
if (_invalidView) {
|
if (_invalidView) {
|
||||||
// Apply the correction
|
// Apply the correction
|
||||||
if (_viewIsCamera && _correction.correction != glm::mat4()) {
|
if (_viewIsCamera && (_viewCorrectionEnabled && _correction.correction != glm::mat4())) {
|
||||||
// FIXME should I switch to using the camera correction buffer in Transform.slf and leave this out?
|
// FIXME should I switch to using the camera correction buffer in Transform.slf and leave this out?
|
||||||
Transform result;
|
Transform result;
|
||||||
_view.mult(result, _view, _correction.correction);
|
_view.mult(result, _view, _correction.correction);
|
||||||
|
|
|
@ -390,6 +390,13 @@ void Batch::resetStages() {
|
||||||
ADD_COMMAND(resetStages);
|
ADD_COMMAND(resetStages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Batch::disableContextViewCorrection() {
|
||||||
|
ADD_COMMAND(disableContextViewCorrection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::restoreContextViewCorrection() {
|
||||||
|
ADD_COMMAND(restoreContextViewCorrection);
|
||||||
|
}
|
||||||
|
|
||||||
void Batch::disableContextStereo() {
|
void Batch::disableContextStereo() {
|
||||||
ADD_COMMAND(disableContextStereo);
|
ADD_COMMAND(disableContextStereo);
|
||||||
|
|
|
@ -217,6 +217,9 @@ public:
|
||||||
// Reset the stage caches and states
|
// Reset the stage caches and states
|
||||||
void resetStages();
|
void resetStages();
|
||||||
|
|
||||||
|
void disableContextViewCorrection();
|
||||||
|
void restoreContextViewCorrection();
|
||||||
|
|
||||||
void disableContextStereo();
|
void disableContextStereo();
|
||||||
void restoreContextStereo();
|
void restoreContextStereo();
|
||||||
|
|
||||||
|
@ -304,6 +307,9 @@ public:
|
||||||
|
|
||||||
COMMAND_resetStages,
|
COMMAND_resetStages,
|
||||||
|
|
||||||
|
COMMAND_disableContextViewCorrection,
|
||||||
|
COMMAND_restoreContextViewCorrection,
|
||||||
|
|
||||||
COMMAND_disableContextStereo,
|
COMMAND_disableContextStereo,
|
||||||
COMMAND_restoreContextStereo,
|
COMMAND_restoreContextStereo,
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ void DeferredFrameTransform::update(RenderArgs* args) {
|
||||||
args->getViewFrustum().evalProjectionMatrix(frameTransformBuffer.projectionMono);
|
args->getViewFrustum().evalProjectionMatrix(frameTransformBuffer.projectionMono);
|
||||||
|
|
||||||
// Running in stero ?
|
// Running in stero ?
|
||||||
bool isStereo = args->_context->isStereo();
|
bool isStereo = args->isStereo();
|
||||||
if (!isStereo) {
|
if (!isStereo) {
|
||||||
frameTransformBuffer.projection[0] = frameTransformBuffer.projectionMono;
|
frameTransformBuffer.projection[0] = frameTransformBuffer.projectionMono;
|
||||||
frameTransformBuffer.stereoInfo = glm::vec4(0.0f, (float)args->_viewport.z, 0.0f, 0.0f);
|
frameTransformBuffer.stereoInfo = glm::vec4(0.0f, (float)args->_viewport.z, 0.0f, 0.0f);
|
||||||
|
|
|
@ -406,7 +406,7 @@ void Blit::run(const RenderContextPointer& renderContext, const gpu::Framebuffer
|
||||||
batch.setFramebuffer(blitFbo);
|
batch.setFramebuffer(blitFbo);
|
||||||
|
|
||||||
if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) {
|
if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) {
|
||||||
if (renderArgs->_context->isStereo()) {
|
if (renderArgs->isStereo()) {
|
||||||
gpu::Vec4i srcRectLeft;
|
gpu::Vec4i srcRectLeft;
|
||||||
srcRectLeft.z = width / 2;
|
srcRectLeft.z = width / 2;
|
||||||
srcRectLeft.w = height;
|
srcRectLeft.w = height;
|
||||||
|
|
|
@ -459,7 +459,7 @@ void SurfaceGeometryPass::run(const render::RenderContextPointer& renderContext,
|
||||||
auto diffuseVPipeline = _diffusePass.getBlurVPipeline();
|
auto diffuseVPipeline = _diffusePass.getBlurVPipeline();
|
||||||
auto diffuseHPipeline = _diffusePass.getBlurHPipeline();
|
auto diffuseHPipeline = _diffusePass.getBlurHPipeline();
|
||||||
|
|
||||||
_diffusePass.getParameters()->setWidthHeight(curvatureViewport.z, curvatureViewport.w, args->_context->isStereo());
|
_diffusePass.getParameters()->setWidthHeight(curvatureViewport.z, curvatureViewport.w, args->isStereo());
|
||||||
glm::ivec2 textureSize(curvatureTexture->getDimensions());
|
glm::ivec2 textureSize(curvatureTexture->getDimensions());
|
||||||
_diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport));
|
_diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport));
|
||||||
_diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
_diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
||||||
|
|
|
@ -99,6 +99,8 @@ namespace render {
|
||||||
void pushViewFrustum(const ViewFrustum& viewFrustum) { _viewFrustums.push(viewFrustum); }
|
void pushViewFrustum(const ViewFrustum& viewFrustum) { _viewFrustums.push(viewFrustum); }
|
||||||
void popViewFrustum() { _viewFrustums.pop(); }
|
void popViewFrustum() { _viewFrustums.pop(); }
|
||||||
|
|
||||||
|
bool isStereo() const { return _displayMode != MONO; }
|
||||||
|
|
||||||
std::shared_ptr<gpu::Context> _context;
|
std::shared_ptr<gpu::Context> _context;
|
||||||
std::shared_ptr<gpu::Framebuffer> _blitFramebuffer;
|
std::shared_ptr<gpu::Framebuffer> _blitFramebuffer;
|
||||||
std::shared_ptr<render::ShapePipeline> _pipeline;
|
std::shared_ptr<render::ShapePipeline> _pipeline;
|
||||||
|
|
|
@ -217,7 +217,7 @@ void BlurGaussian::run(const RenderContextPointer& renderContext, const gpu::Fra
|
||||||
auto blurVPipeline = getBlurVPipeline();
|
auto blurVPipeline = getBlurVPipeline();
|
||||||
auto blurHPipeline = getBlurHPipeline();
|
auto blurHPipeline = getBlurHPipeline();
|
||||||
|
|
||||||
_parameters->setWidthHeight(args->_viewport.z, args->_viewport.w, args->_context->isStereo());
|
_parameters->setWidthHeight(args->_viewport.z, args->_viewport.w, args->isStereo());
|
||||||
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
||||||
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ void BlurGaussianDepthAware::run(const RenderContextPointer& renderContext, cons
|
||||||
|
|
||||||
auto sourceViewport = args->_viewport;
|
auto sourceViewport = args->_viewport;
|
||||||
|
|
||||||
_parameters->setWidthHeight(sourceViewport.z, sourceViewport.w, args->_context->isStereo());
|
_parameters->setWidthHeight(sourceViewport.z, sourceViewport.w, args->isStereo());
|
||||||
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
||||||
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, sourceViewport));
|
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, sourceViewport));
|
||||||
_parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
_parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
||||||
|
|
Loading…
Reference in a new issue