From 77beb4c3afde5232b3a2454a1518cdeb9da44ba0 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 14 Sep 2022 14:36:33 +0200 Subject: [PATCH 01/68] WIP First attempt at a solution --- modules/base/rendering/renderablemodel.cpp | 268 +++++++++++++++++- modules/base/rendering/renderablemodel.h | 19 +- .../base/rendering/screenspaceframebuffer.cpp | 2 +- modules/base/shaders/modelOpacity_fs.glsl | 59 ++++ modules/base/shaders/modelOpacity_vs.glsl | 35 +++ modules/base/shaders/model_fs.glsl | 23 +- modules/base/shaders/model_vs.glsl | 2 +- 7 files changed, 375 insertions(+), 33 deletions(-) create mode 100644 modules/base/shaders/modelOpacity_fs.glsl create mode 100644 modules/base/shaders/modelOpacity_vs.glsl diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 1a6fa4ffdd..c50f092ddf 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,11 +41,15 @@ #include #include #include +#include #include #include +#include #include #include +#include + namespace { constexpr std::string_view _loggerCat = "RenderableModel"; constexpr std::string_view ProgramName = "ModelProgram"; @@ -62,17 +68,30 @@ namespace { { "Color Adding", ColorAddingBlending } }; + constexpr glm::vec4 PosBufferClearVal = { 1e32, 1e32, 1e32, 1.f }; + + const GLenum ColorAttachmentArray[3] = { + GL_COLOR_ATTACHMENT0, + GL_COLOR_ATTACHMENT1, + GL_COLOR_ATTACHMENT2 + }; + constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { "EnableAnimation", "Enable Animation", "Enable or disable the animation for the model if it has any" }; - constexpr std::array UniformNames = { - "opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities", + constexpr std::array UniformNames = { + "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", - "specularIntensity", "opacityBlending" + "specularIntensity" + }; + + constexpr std::array UniformOpacityNames = { + "opacity", "opacityBlending", "colorTexture", "depthTexture", "positionTexture", + "normalTexture" }; constexpr openspace::properties::Property::PropertyInfo AmbientIntensityInfo = { @@ -486,7 +505,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) } bool RenderableModel::isReady() const { - return _program; + return _program && _screenShader; } void RenderableModel::initialize() { @@ -539,14 +558,198 @@ void RenderableModel::initializeGL() { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); + _screenShader = BaseModule::ProgramObjectManager.request( + "ModelOpacityProgram", + [&]() -> std::unique_ptr { + std::filesystem::path vs = + absPath("${MODULE_BASE}/shaders/modelOpacity_vs.glsl"); + std::filesystem::path fs = + absPath("${MODULE_BASE}/shaders/modelOpacity_fs.glsl"); + + return global::renderEngine->buildRenderProgram("ModelOpacityProgram", vs, fs); + } + ); + ghoul::opengl::updateUniformLocations( + *_screenShader, + _uniformOpacityCache, + UniformOpacityNames + ); + + // Screen quad VAO + const GLfloat quadVertices[] = { + // x y + -1.f, -1.f, + 1.f, 1.f, + -1.f, 1.f, + -1.f, -1.f, + 1.f, -1.f, + 1.f, 1.f, + }; + + glGenVertexArrays(1, &_quadVao); + glBindVertexArray(_quadVao); + + glGenBuffers(1, &_quadVbo); + glBindBuffer(GL_ARRAY_BUFFER, _quadVbo); + + glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr); + glEnableVertexAttribArray(0); + + createFramebuffers(); + _geometry->initialize(); _geometry->calculateBoundingRadius(); } +void RenderableModel::createFramebuffers() { + glm::vec2 resolution = global::windowDelegate->currentDrawBufferResolution(); + + // Generate textures and the frame buffer + glGenTextures(1, &_colorTexture); + glGenTextures(1, &_positionTexture); + glGenTextures(1, &_normalTexture); + glGenTextures(1, &_depthTexture); + glGenFramebuffers(1, &_framebuffer); + + // Create the textures + // Color + glBindTexture(GL_TEXTURE_2D, _colorTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(resolution.x), + static_cast(resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _colorTexture, -1, "RenderableModel Color"); + } + + + // Position + glBindTexture(GL_TEXTURE_2D, _positionTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(resolution.x), + static_cast(resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _positionTexture, -1, "RenderableModel Position"); + } + + // Normal + glBindTexture(GL_TEXTURE_2D, _normalTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(resolution.x), + static_cast(resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _normalTexture, -1, "RenderableModel Normal"); + } + + // Depth + glBindTexture(GL_TEXTURE_2D, _depthTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_DEPTH_COMPONENT32F, + static_cast(resolution.x), + static_cast(resolution.y), + 0, + GL_DEPTH_COMPONENT, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _depthTexture, -1, "RenderableModel Depth"); + } + + // Create buffers + glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); + glFramebufferTexture( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + _colorTexture, + 0 + ); + glFramebufferTexture( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT1, + _positionTexture, + 0 + ); + glFramebufferTexture( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT2, + _normalTexture, + 0 + ); + glFramebufferTexture( + GL_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + _depthTexture, + 0 + ); + + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_FRAMEBUFFER, _framebuffer, -1, "RenderableModel Opacity"); + } + + // Check status + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + LERROR("Framebuffer is not complete!"); + } + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + void RenderableModel::deinitializeGL() { _geometry->deinitialize(); _geometry.reset(); + glDeleteFramebuffers(1, &_framebuffer); + glDeleteTextures(1, &_colorTexture); + glDeleteTextures(1, &_depthTexture); + glDeleteTextures(1, &_positionTexture); + glDeleteTextures(1, &_normalTexture); + + glDeleteBuffers(1, &_quadVbo); + glDeleteVertexArrays(1, &_quadVao); + std::string program = std::string(ProgramName); if (!_vertexShaderPath.empty()) { program += "|vs=" + _vertexShaderPath; @@ -561,6 +764,8 @@ void RenderableModel::deinitializeGL() { } ); _program = nullptr; + _screenShader = nullptr; + ghoul::opengl::FramebufferObject::deactivate(); } void RenderableModel::render(const RenderData& data, RendererTasks&) { @@ -579,7 +784,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { if (distanceToCamera < maxDistance) { _program->activate(); - _program->setUniform(_uniformCache.opacity, opacity()); + // Model transform and view transform needs to be in double precision const glm::dmat4 modelTransform = @@ -636,7 +841,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity); _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); - _program->setUniform(_uniformCache.opacityBlending, _enableOpacityBlending); + if (_disableFaceCulling) { glDisable(GL_CULL_FACE); @@ -665,18 +870,63 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glDisable(GL_DEPTH_TEST); } + // Frame buffer stuff + GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); + glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); + glDrawBuffers(3, ColorAttachmentArray); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearBufferfv(GL_COLOR, 1, glm::value_ptr(PosBufferClearVal)); + + // Render Pass 1 _geometry->render(*_program); if (_disableFaceCulling) { glEnable(GL_CULL_FACE); } - - global::renderEngine->openglStateCache().resetBlendState(); + _program->deactivate(); if (_disableDepthTest) { glEnable(GL_DEPTH_TEST); } - _program->deactivate(); + // Render pass 2 + glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); + glDisable(GL_DEPTH_TEST); // disable depth test so screen-space quad isn't discarded due to depth test. + + _screenShader->activate(); + + _program->setUniform(_uniformOpacityCache.opacity, opacity()); + _program->setUniform(_uniformOpacityCache.opacityBlending, _enableOpacityBlending); + + // Bind textures + ghoul::opengl::TextureUnit colorTextureUnit; + colorTextureUnit.activate(); + glBindTexture(GL_TEXTURE_2D, _colorTexture); + _program->setUniform(_uniformOpacityCache.modelColorTexture, colorTextureUnit); + /* + ghoul::opengl::TextureUnit positionTextureUnit; + positionTextureUnit.activate(); + glBindTexture(GL_TEXTURE_2D, _positionTexture); + _program->setUniform(_uniformOpacityCache.moedlPositionTexture, positionTextureUnit); + + ghoul::opengl::TextureUnit normalTextureUnit; + normalTextureUnit.activate(); + glBindTexture(GL_TEXTURE_2D, _normalTexture); + _program->setUniform(_uniformOpacityCache.modelNormalTexture, normalTextureUnit); + + ghoul::opengl::TextureUnit depthTextureUnit; + depthTextureUnit.activate(); + glBindTexture(GL_TEXTURE_2D, _depthTexture); + _program->setUniform(_uniformOpacityCache.modelDepthTexture, depthTextureUnit); + + // Draw + glBindVertexArray(_quadVao); + glDrawArrays(GL_TRIANGLES, 0, 6); + _screenShader->deactivate(); + */ + // End + global::renderEngine->openglStateCache().resetBlendState(); + glEnable(GL_DEPTH_TEST); + glActiveTexture(GL_TEXTURE0); } } diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 4662690245..d883eef06c 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -40,6 +40,7 @@ #include namespace ghoul::opengl { + class FramebufferObject; class ProgramObject; class Texture; } // namespace ghoul::opengl @@ -104,10 +105,10 @@ private: std::string _vertexShaderPath; std::string _fragmentShaderPath; ghoul::opengl::ProgramObject* _program = nullptr; - UniformCache(opacity, nLightSources, lightDirectionsViewSpace, lightIntensities, + UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, - specularIntensity, opacityBlending) _uniformCache; + specularIntensity) _uniformCache; std::vector> _lightSources; @@ -116,6 +117,20 @@ private: std::vector _lightDirectionsViewSpaceBuffer; properties::PropertyOwner _lightSourcePropertyOwner; + + // Frame buffer stuff + GLuint _framebuffer; + GLuint _colorTexture; + GLuint _depthTexture; + GLuint _positionTexture; + GLuint _normalTexture; + GLuint _quadVao; + GLuint _quadVbo; + void createFramebuffers(); + ghoul::opengl::ProgramObject* _screenShader = nullptr; + + UniformCache(opacity, opacityBlending, modelColorTexture, modelDepthTexture, + modelPositionTexture, modelNormalTexture) _uniformOpacityCache; }; } // namespace openspace diff --git a/modules/base/rendering/screenspaceframebuffer.cpp b/modules/base/rendering/screenspaceframebuffer.cpp index 17b7f0d869..0913f877e9 100644 --- a/modules/base/rendering/screenspaceframebuffer.cpp +++ b/modules/base/rendering/screenspaceframebuffer.cpp @@ -108,7 +108,7 @@ void ScreenSpaceFramebuffer::render() { const glm::vec4& size = _size.value(); const float xratio = resolution.x / (size.z - size.x); - const float yratio = resolution.y / (size.w - size.y);; + const float yratio = resolution.y / (size.w - size.y); if (!_renderFunctions.empty()) { GLint viewport[4]; diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl new file mode 100644 index 0000000000..b45665d31f --- /dev/null +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -0,0 +1,59 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "fragment.glsl" +#include "floatoperations.glsl" + +in vec2 vs_st; + +uniform float opacity = 1.0; +uniform bool opacityBlending = false; + +uniform sampler2D colorTexture; +uniform sampler2D depthTexture; +uniform sampler2D positionTexture; +uniform sampler2D normalTexture; + +Fragment getFragment() { + Fragment frag; + + if (opacity == 0.0) { + discard; + } + + if (opacityBlending) { + // frag.color.a = opacity * (frag.color.r + frag.color.g + frag.color.b)/3.0; + frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); + } + else { + frag.color.a = opacity; + } + + frag.color.rgb = texture(colorTexture, vs_st).rgb; + frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); + frag.gPosition = texture(positionTexture, vs_st); + frag.gNormal = vec4(texture(normalTexture, vs_st).rgb, 0.0); + + return frag; +} diff --git a/modules/base/shaders/modelOpacity_vs.glsl b/modules/base/shaders/modelOpacity_vs.glsl new file mode 100644 index 0000000000..efd3a16703 --- /dev/null +++ b/modules/base/shaders/modelOpacity_vs.glsl @@ -0,0 +1,35 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +layout(location = 0) in vec2 in_position; +layout(location = 1) in vec2 in_st; + +out vec2 vs_st; + +void main() { + vs_st = in_st; + gl_Position = vec4(in_position.x, in_position.y, 0.0, 1.0); +} diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 76ad9653c3..1cd48498b9 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -39,7 +39,6 @@ uniform bool has_texture_diffuse; uniform bool has_texture_normal; uniform bool has_texture_specular; uniform bool has_color_specular; -uniform bool opacityBlending = false; uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; @@ -48,7 +47,6 @@ uniform vec3 color_specular; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; -uniform float opacity = 1.0; Fragment getFragment() { @@ -63,7 +61,7 @@ Fragment getFragment() { // Pink and complementary green in a chessboard pattern frag.color.rgb = mix(vec3(1.0, 0.0, 0.8), vec3(0.0, 1.0, 0.2), chessboard); - frag.color.a = opacity; + frag.color.a = 1.0; frag.depth = vs_screenSpaceDepth; frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); @@ -80,10 +78,6 @@ Fragment getFragment() { diffuseAlbedo = color_diffuse; } - if (opacity == 0.0) { - discard; - } - Fragment frag; if (performShading) { @@ -103,7 +97,7 @@ Fragment getFragment() { // Some of these values could be passed in as uniforms const vec3 lightColorAmbient = vec3(1.0); const vec3 lightColor = vec3(1.0); - + vec3 n; if (has_texture_normal) { vec3 normalAlbedo = texture(texture_normal, vs_st).rgb; @@ -141,18 +135,7 @@ Fragment getFragment() { frag.color.rgb = diffuseAlbedo; } - if (opacityBlending) { - // frag.color.a = opacity * (frag.color.r + frag.color.g + frag.color.b)/3.0; - frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); - } - else { - frag.color.a = opacity; - } - - if (frag.color.a < 0.1) { - discard; - } - + frag.color.a = 1.0; frag.depth = vs_screenSpaceDepth; frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); diff --git a/modules/base/shaders/model_vs.glsl b/modules/base/shaders/model_vs.glsl index 4451a169b8..b73c5c8c79 100644 --- a/modules/base/shaders/model_vs.glsl +++ b/modules/base/shaders/model_vs.glsl @@ -52,7 +52,7 @@ void main() { gl_Position = positionScreenSpace; vs_st = in_st; vs_screenSpaceDepth = positionScreenSpace.w; - + vs_normalViewSpace = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); // TBN matrix for normal mapping From 3b5c3c51d608acc617b3cb98716618379c54e07d Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 14 Sep 2022 16:52:58 +0200 Subject: [PATCH 02/68] Fix OpenGL error for model opacity shader program --- modules/base/rendering/renderablemodel.cpp | 25 ++++++++++++++-------- modules/base/rendering/renderablemodel.h | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index c50f092ddf..745ddf3d35 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -890,39 +890,46 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render pass 2 glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); - glDisable(GL_DEPTH_TEST); // disable depth test so screen-space quad isn't discarded due to depth test. + // Screen-space quad should not be discarded due to depth test + glDisable(GL_DEPTH_TEST); _screenShader->activate(); - _program->setUniform(_uniformOpacityCache.opacity, opacity()); - _program->setUniform(_uniformOpacityCache.opacityBlending, _enableOpacityBlending); + _screenShader->setUniform(_uniformOpacityCache.opacity, opacity()); + _screenShader->setUniform( + _uniformOpacityCache.opacityBlending, + _enableOpacityBlending + ); // Bind textures ghoul::opengl::TextureUnit colorTextureUnit; colorTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _colorTexture); - _program->setUniform(_uniformOpacityCache.modelColorTexture, colorTextureUnit); - /* + _screenShader->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); + ghoul::opengl::TextureUnit positionTextureUnit; positionTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _positionTexture); - _program->setUniform(_uniformOpacityCache.moedlPositionTexture, positionTextureUnit); + _screenShader->setUniform( + _uniformOpacityCache.positionTexture, + positionTextureUnit + ); ghoul::opengl::TextureUnit normalTextureUnit; normalTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _normalTexture); - _program->setUniform(_uniformOpacityCache.modelNormalTexture, normalTextureUnit); + _screenShader->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); ghoul::opengl::TextureUnit depthTextureUnit; depthTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _depthTexture); - _program->setUniform(_uniformOpacityCache.modelDepthTexture, depthTextureUnit); + _screenShader->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); // Draw glBindVertexArray(_quadVao); glDrawArrays(GL_TRIANGLES, 0, 6); _screenShader->deactivate(); - */ + // End global::renderEngine->openglStateCache().resetBlendState(); glEnable(GL_DEPTH_TEST); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index d883eef06c..e02c5b2e7e 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -129,8 +129,8 @@ private: void createFramebuffers(); ghoul::opengl::ProgramObject* _screenShader = nullptr; - UniformCache(opacity, opacityBlending, modelColorTexture, modelDepthTexture, - modelPositionTexture, modelNormalTexture) _uniformOpacityCache; + UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, + normalTexture) _uniformOpacityCache; }; } // namespace openspace From 5c3838f33513e9a2a44f29958940969298d8874a Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 27 Sep 2022 14:45:22 +0200 Subject: [PATCH 03/68] WIP Model is visible * Opacity issues * "Clearing" issues --- modules/base/rendering/renderablemodel.cpp | 37 ++++++++++++++-------- modules/base/shaders/modelOpacity_fs.glsl | 1 + 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 745ddf3d35..28029a3627 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -68,12 +68,13 @@ namespace { { "Color Adding", ColorAddingBlending } }; - constexpr glm::vec4 PosBufferClearVal = { 1e32, 1e32, 1e32, 1.f }; + constexpr glm::vec4 PosBufferClearVal = { 0.f, 0.f, 0.f, 0.f }; - const GLenum ColorAttachmentArray[3] = { + const GLenum ColorAttachmentArray[4] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, - GL_COLOR_ATTACHMENT2 + GL_COLOR_ATTACHMENT2, + GL_COLOR_ATTACHMENT3 }; constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { @@ -577,13 +578,13 @@ void RenderableModel::initializeGL() { // Screen quad VAO const GLfloat quadVertices[] = { - // x y - -1.f, -1.f, - 1.f, 1.f, - -1.f, 1.f, - -1.f, -1.f, - 1.f, -1.f, - 1.f, 1.f, + // x y s t + -1.f, -1.f, 0.f, 0.f, + 1.f, 1.f, 1.f, 1.f, + -1.f, 1.f, 0.f, 1.f, + -1.f, -1.f, 0.f, 0.f, + 1.f, -1.f, 1.f, 0.f, + 1.f, 1.f, 1.f, 1.f }; glGenVertexArrays(1, &_quadVao); @@ -593,8 +594,18 @@ void RenderableModel::initializeGL() { glBindBuffer(GL_ARRAY_BUFFER, _quadVbo); glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr); glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), nullptr); + glEnableVertexAttribArray(1); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + 4 * sizeof(GLfloat), + (void*)(2 * sizeof(GLfloat)) + ); + createFramebuffers(); @@ -873,7 +884,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Frame buffer stuff GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); - glDrawBuffers(3, ColorAttachmentArray); + glDrawBuffers(4, ColorAttachmentArray); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearBufferfv(GL_COLOR, 1, glm::value_ptr(PosBufferClearVal)); @@ -932,7 +943,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // End global::renderEngine->openglStateCache().resetBlendState(); - glEnable(GL_DEPTH_TEST); + global::renderEngine->openglStateCache().resetDepthState(); glActiveTexture(GL_TEXTURE0); } } diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index b45665d31f..4de385cc89 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -54,6 +54,7 @@ Fragment getFragment() { frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); frag.gPosition = texture(positionTexture, vs_st); frag.gNormal = vec4(texture(normalTexture, vs_st).rgb, 0.0); + frag.disableLDR2HDR = true; return frag; } From 115d4f4f8119efff72038741a1639f3d9ba86341 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 27 Sep 2022 15:08:53 +0200 Subject: [PATCH 04/68] Fix issue with starts dissapearing --- modules/base/shaders/modelOpacity_fs.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 4de385cc89..66657c0861 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -38,7 +38,8 @@ uniform sampler2D normalTexture; Fragment getFragment() { Fragment frag; - if (opacity == 0.0) { + vec4 textureColor = texture(colorTexture, vs_st); + if (textureColor.a == 0.0 || opacity == 0.0) { discard; } @@ -50,7 +51,7 @@ Fragment getFragment() { frag.color.a = opacity; } - frag.color.rgb = texture(colorTexture, vs_st).rgb; + frag.color.rgb = textureColor.rgb; frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); frag.gPosition = texture(positionTexture, vs_st); frag.gNormal = vec4(texture(normalTexture, vs_st).rgb, 0.0); From c5f6f72b77456cd89ec23e62b372406d8d21da5f Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 4 Oct 2022 14:34:36 +0200 Subject: [PATCH 05/68] Fix depth issues --- modules/base/rendering/renderablemodel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 28029a3627..8a668e1c51 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -901,8 +901,10 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render pass 2 glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); - // Screen-space quad should not be discarded due to depth test - glDisable(GL_DEPTH_TEST); + // Screen-space quad should not be discarded due to depth test, + // but we still want to be able to write to the depth buffer -> GL_ALWAYS + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); _screenShader->activate(); From 11981138f89d0b63421e3c983321dcd2a763ea4c Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Oct 2022 09:53:25 +0200 Subject: [PATCH 06/68] Move Model to render bin Post deffered if transparent --- modules/base/rendering/renderablemodel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 8a668e1c51..ccc6185dd0 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -889,6 +889,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glClearBufferfv(GL_COLOR, 1, glm::value_ptr(PosBufferClearVal)); // Render Pass 1 + bool isTransparent = false; + if (_renderBin != Renderable::RenderBin::Opaque) { + isTransparent = true; + _renderBin = Renderable::RenderBin::Opaque; + } _geometry->render(*_program); if (_disableFaceCulling) { glEnable(GL_CULL_FACE); @@ -900,6 +905,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { } // Render pass 2 + if (isTransparent) { + isTransparent = true; + _renderBin = Renderable::RenderBin::PostDeferredTransparent; + } + glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); // Screen-space quad should not be discarded due to depth test, // but we still want to be able to write to the depth buffer -> GL_ALWAYS From 202cf4b5b62824843410241941ed1eae55bb830b Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Oct 2022 11:41:15 +0200 Subject: [PATCH 07/68] Fix opacity issue with model vs trails + small clean up --- modules/base/rendering/renderablemodel.cpp | 57 +++++++++++++--------- modules/base/rendering/renderablemodel.h | 2 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index ccc6185dd0..80c8a3a655 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -506,7 +506,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) } bool RenderableModel::isReady() const { - return _program && _screenShader; + return _program && _quadProgram; } void RenderableModel::initialize() { @@ -559,7 +559,7 @@ void RenderableModel::initializeGL() { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); - _screenShader = BaseModule::ProgramObjectManager.request( + _quadProgram = BaseModule::ProgramObjectManager.request( "ModelOpacityProgram", [&]() -> std::unique_ptr { std::filesystem::path vs = @@ -571,7 +571,7 @@ void RenderableModel::initializeGL() { } ); ghoul::opengl::updateUniformLocations( - *_screenShader, + *_quadProgram, _uniformOpacityCache, UniformOpacityNames ); @@ -774,8 +774,16 @@ void RenderableModel::deinitializeGL() { global::renderEngine->removeRenderProgram(p); } ); + + BaseModule::ProgramObjectManager.release( + "ModelOpacityProgram", + [](ghoul::opengl::ProgramObject* p) { + global::renderEngine->removeRenderProgram(p); + } + ); + _program = nullptr; - _screenShader = nullptr; + _quadProgram = nullptr; ghoul::opengl::FramebufferObject::deactivate(); } @@ -795,8 +803,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { if (distanceToCamera < maxDistance) { _program->activate(); - - // Model transform and view transform needs to be in double precision const glm::dmat4 modelTransform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * @@ -853,7 +859,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); - if (_disableFaceCulling) { glDisable(GL_CULL_FACE); } @@ -881,7 +886,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glDisable(GL_DEPTH_TEST); } - // Frame buffer stuff + // Prepare framebuffer GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); glDrawBuffers(4, ColorAttachmentArray); @@ -889,11 +894,17 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glClearBufferfv(GL_COLOR, 1, glm::value_ptr(PosBufferClearVal)); // Render Pass 1 + // Render all parts of the model into the new framebuffer without opacity bool isTransparent = false; - if (_renderBin != Renderable::RenderBin::Opaque) { + const float o = opacity(); + if (o >= 0.f && o < 1.f) { isTransparent = true; - _renderBin = Renderable::RenderBin::Opaque; + setRenderBin(Renderable::RenderBin::Overlay); } + else { + setRenderBin(Renderable::RenderBin::Opaque); + } + _geometry->render(*_program); if (_disableFaceCulling) { glEnable(GL_CULL_FACE); @@ -905,21 +916,19 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { } // Render pass 2 - if (isTransparent) { - isTransparent = true; - _renderBin = Renderable::RenderBin::PostDeferredTransparent; - } - + // Render the whole model into the G-buffer with the correct opacity glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); + + // Screen-space quad should not be discarded due to depth test, // but we still want to be able to write to the depth buffer -> GL_ALWAYS glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); - _screenShader->activate(); + _quadProgram->activate(); - _screenShader->setUniform(_uniformOpacityCache.opacity, opacity()); - _screenShader->setUniform( + _quadProgram->setUniform(_uniformOpacityCache.opacity, opacity()); + _quadProgram->setUniform( _uniformOpacityCache.opacityBlending, _enableOpacityBlending ); @@ -928,12 +937,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ghoul::opengl::TextureUnit colorTextureUnit; colorTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _colorTexture); - _screenShader->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); + _quadProgram->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); ghoul::opengl::TextureUnit positionTextureUnit; positionTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _positionTexture); - _screenShader->setUniform( + _quadProgram->setUniform( _uniformOpacityCache.positionTexture, positionTextureUnit ); @@ -941,19 +950,19 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ghoul::opengl::TextureUnit normalTextureUnit; normalTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _normalTexture); - _screenShader->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); + _quadProgram->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); ghoul::opengl::TextureUnit depthTextureUnit; depthTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D, _depthTexture); - _screenShader->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); + _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); // Draw glBindVertexArray(_quadVao); glDrawArrays(GL_TRIANGLES, 0, 6); - _screenShader->deactivate(); + _quadProgram->deactivate(); - // End + // Reset global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetDepthState(); glActiveTexture(GL_TEXTURE0); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index e02c5b2e7e..895dd2fdfe 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -127,7 +127,7 @@ private: GLuint _quadVao; GLuint _quadVbo; void createFramebuffers(); - ghoul::opengl::ProgramObject* _screenShader = nullptr; + ghoul::opengl::ProgramObject* _quadProgram = nullptr; UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, normalTexture) _uniformOpacityCache; From 4adaea5b76f7fffe4744534ff7b99cd3fd254211 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Oct 2022 12:04:22 +0200 Subject: [PATCH 08/68] Resize textures when window resizes --- modules/base/rendering/renderablemodel.cpp | 202 +++++++++++---------- modules/base/rendering/renderablemodel.h | 5 +- 2 files changed, 108 insertions(+), 99 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 80c8a3a655..af68455cc3 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -606,16 +606,6 @@ void RenderableModel::initializeGL() { (void*)(2 * sizeof(GLfloat)) ); - - createFramebuffers(); - - _geometry->initialize(); - _geometry->calculateBoundingRadius(); -} - -void RenderableModel::createFramebuffers() { - glm::vec2 resolution = global::windowDelegate->currentDrawBufferResolution(); - // Generate textures and the frame buffer glGenTextures(1, &_colorTexture); glGenTextures(1, &_positionTexture); @@ -623,93 +613,11 @@ void RenderableModel::createFramebuffers() { glGenTextures(1, &_depthTexture); glGenFramebuffers(1, &_framebuffer); - // Create the textures - // Color - glBindTexture(GL_TEXTURE_2D, _colorTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(resolution.x), - static_cast(resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _colorTexture, -1, "RenderableModel Color"); - } + // Create Textures + _resolution = global::windowDelegate->currentDrawBufferResolution(); + updateResolution(); - - // Position - glBindTexture(GL_TEXTURE_2D, _positionTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(resolution.x), - static_cast(resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _positionTexture, -1, "RenderableModel Position"); - } - - // Normal - glBindTexture(GL_TEXTURE_2D, _normalTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(resolution.x), - static_cast(resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _normalTexture, -1, "RenderableModel Normal"); - } - - // Depth - glBindTexture(GL_TEXTURE_2D, _depthTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_DEPTH_COMPONENT32F, - static_cast(resolution.x), - static_cast(resolution.y), - 0, - GL_DEPTH_COMPONENT, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _depthTexture, -1, "RenderableModel Depth"); - } - - // Create buffers + // Bind textures to the framebuffer glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); glFramebufferTexture( GL_FRAMEBUFFER, @@ -742,10 +650,104 @@ void RenderableModel::createFramebuffers() { // Check status GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { + if (status != GL_FRAMEBUFFER_COMPLETE) { LERROR("Framebuffer is not complete!"); } glBindFramebuffer(GL_FRAMEBUFFER, 0); + + // Initialize geometry + _geometry->initialize(); + _geometry->calculateBoundingRadius(); +} + +void RenderableModel::updateResolution() { + ZoneScoped + + // Create the textures + // Color + glBindTexture(GL_TEXTURE_2D, _colorTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(_resolution.x), + static_cast(_resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _colorTexture, -1, "RenderableModel Color"); + } + + + // Position + glBindTexture(GL_TEXTURE_2D, _positionTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(_resolution.x), + static_cast(_resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _positionTexture, -1, "RenderableModel Position"); + } + + // Normal + glBindTexture(GL_TEXTURE_2D, _normalTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + static_cast(_resolution.x), + static_cast(_resolution.y), + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _normalTexture, -1, "RenderableModel Normal"); + } + + // Depth + glBindTexture(GL_TEXTURE_2D, _depthTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_DEPTH_COMPONENT32F, + static_cast(_resolution.x), + static_cast(_resolution.y), + 0, + GL_DEPTH_COMPONENT, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (glbinding::Binding::ObjectLabel.isResolved()) { + glObjectLabel(GL_TEXTURE, _depthTexture, -1, "RenderableModel Depth"); + } } void RenderableModel::deinitializeGL() { @@ -975,6 +977,12 @@ void RenderableModel::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } + glm::ivec2 resolution = global::windowDelegate->currentDrawBufferResolution(); + if (resolution != _resolution) { + _resolution = resolution; + updateResolution(); + } + setBoundingSphere(_geometry->boundingRadius() * _modelScale * glm::compMax(data.modelTransform.scale) ); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 895dd2fdfe..7a24ad73c3 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -118,7 +118,7 @@ private: properties::PropertyOwner _lightSourcePropertyOwner; - // Frame buffer stuff + // Framebuffer and its textures GLuint _framebuffer; GLuint _colorTexture; GLuint _depthTexture; @@ -126,7 +126,8 @@ private: GLuint _normalTexture; GLuint _quadVao; GLuint _quadVbo; - void createFramebuffers(); + glm::ivec2 _resolution = glm::ivec2(0); + void updateResolution(); ghoul::opengl::ProgramObject* _quadProgram = nullptr; UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, From eeebfdb2c6f5ae80743095fad1b7c82ad09f0b7e Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Oct 2022 13:48:16 +0200 Subject: [PATCH 09/68] Some small clean up --- modules/base/rendering/renderablemodel.cpp | 17 ++++------------- modules/base/rendering/renderablemodel.h | 1 - modules/base/shaders/modelOpacity_fs.glsl | 1 - modules/base/shaders/modelOpacity_vs.glsl | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index af68455cc3..b2711aeae1 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -48,8 +48,6 @@ #include #include -#include - namespace { constexpr std::string_view _loggerCat = "RenderableModel"; constexpr std::string_view ProgramName = "ModelProgram"; @@ -68,13 +66,10 @@ namespace { { "Color Adding", ColorAddingBlending } }; - constexpr glm::vec4 PosBufferClearVal = { 0.f, 0.f, 0.f, 0.f }; - - const GLenum ColorAttachmentArray[4] = { + const GLenum ColorAttachmentArray[3] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, - GL_COLOR_ATTACHMENT3 }; constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { @@ -645,7 +640,7 @@ void RenderableModel::initializeGL() { ); if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_FRAMEBUFFER, _framebuffer, -1, "RenderableModel Opacity"); + glObjectLabel(GL_FRAMEBUFFER, _framebuffer, -1, "RenderableModel Framebuffer"); } // Check status @@ -685,7 +680,6 @@ void RenderableModel::updateResolution() { glObjectLabel(GL_TEXTURE, _colorTexture, -1, "RenderableModel Color"); } - // Position glBindTexture(GL_TEXTURE_2D, _positionTexture); glTexImage2D( @@ -891,16 +885,14 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Prepare framebuffer GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); - glDrawBuffers(4, ColorAttachmentArray); + glDrawBuffers(3, ColorAttachmentArray); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearBufferfv(GL_COLOR, 1, glm::value_ptr(PosBufferClearVal)); + glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f))); // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity - bool isTransparent = false; const float o = opacity(); if (o >= 0.f && o < 1.f) { - isTransparent = true; setRenderBin(Renderable::RenderBin::Overlay); } else { @@ -921,7 +913,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render the whole model into the G-buffer with the correct opacity glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); - // Screen-space quad should not be discarded due to depth test, // but we still want to be able to write to the depth buffer -> GL_ALWAYS glEnable(GL_DEPTH_TEST); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 7a24ad73c3..c7705b7c2b 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -40,7 +40,6 @@ #include namespace ghoul::opengl { - class FramebufferObject; class ProgramObject; class Texture; } // namespace ghoul::opengl diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 66657c0861..483acf2ad2 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -44,7 +44,6 @@ Fragment getFragment() { } if (opacityBlending) { - // frag.color.a = opacity * (frag.color.r + frag.color.g + frag.color.b)/3.0; frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); } else { diff --git a/modules/base/shaders/modelOpacity_vs.glsl b/modules/base/shaders/modelOpacity_vs.glsl index efd3a16703..8ac1fac67e 100644 --- a/modules/base/shaders/modelOpacity_vs.glsl +++ b/modules/base/shaders/modelOpacity_vs.glsl @@ -30,6 +30,6 @@ layout(location = 1) in vec2 in_st; out vec2 vs_st; void main() { - vs_st = in_st; + vs_st = in_st; gl_Position = vec4(in_position.x, in_position.y, 0.0, 1.0); } From 466fd3257f999836c0b6ba8d0d4369d4d37869c5 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Oct 2022 14:34:39 +0200 Subject: [PATCH 10/68] Rename Iss nodes, fixes #2245 --- .../planets/earth/satellites/misc/iss.asset | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 1e1b41dea0..65cef39143 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -17,10 +17,9 @@ local omm = asset.syncedResource({ Override = true }) -local iss = { - Identifier = "ISS", +local issPosition = { + Identifier = "ISSPosition", Parent = transforms.EarthInertial.Identifier, - BoundingSphere = 54.5, -- half the width InteractionSphere = 30, Transform = { Translation = { @@ -37,18 +36,19 @@ local iss = { }, Tag = { "earth_satellite", "ISS" }, GUI = { - Name = "ISS", - Path = "/Solar System/Planets/Earth/Satellites/ISS" + Name = "ISS Position", + Path = "/Solar System/Planets/Earth/Satellites/ISS", + Hidden = true } } -local parentNode = { - Identifier = "ISSModel", - Parent = iss.Identifier, +local issModel = { + Identifier = "ISS", + Parent = issPosition.Identifier, Transform = { Rotation = { Type = "FixedRotation", - Attached = "ISSModel", + Attached = "ISS", XAxis = { 0.01, -1.0, 0.56 }, XAxisOrthogonal = true, YAxis = transforms.EarthInertial.Identifier @@ -64,8 +64,9 @@ local parentNode = { PerformShading = true, DisableFaceCulling = true }, + Tag = { "earth_satellite", "ISS" }, GUI = { - Name = "ISS Model", + Name = "ISS", Path = "/Solar System/Planets/Earth/Satellites/ISS" } } @@ -96,7 +97,7 @@ local issTrail = { -- @TODO (emmbr, 2021-05-27) add to scene when label rendering issues have been fixed local IssLabel = { Identifier = "IssLabel", - Parent = iss.Identifier, + Parent = issPosition.Identifier, Renderable = { Enabled = false, Type = "RenderableLabels", @@ -110,7 +111,7 @@ local IssLabel = { FadeDistances = { 0.15, 15.0 }, FadeWidths = { 1.0, 25.0 } }, - Tag = { "solarsystem_labels" }, + Tag = { "solarsystem_labels", "earth_satellite", "ISS" }, GUI = { Name = "ISS Label", Path = "/Solar System/Planets/Earth/Satellites" @@ -121,29 +122,28 @@ asset.onInitialize(function () local i = openspace.space.readKeplerFile(omm .. "ISS.txt", "OMM") issTrail.Renderable.Period = i[0].Period / (60 * 60 * 24) - openspace.addSceneGraphNode(iss) - openspace.addSceneGraphNode(parentNode) - openspace.setPropertyValueSingle("Scene.ISSModel.Rotation.yAxisInvertObject", true) + openspace.addSceneGraphNode(issPosition) + openspace.addSceneGraphNode(issModel) openspace.addSceneGraphNode(issTrail) + openspace.setPropertyValueSingle("Scene.ISS.Rotation.yAxisInvertObject", true) end) asset.onDeinitialize(function () openspace.removeSceneGraphNode(issTrail) - openspace.removeSceneGraphNode(parentNode) - openspace.removeSceneGraphNode(iss) + openspace.removeSceneGraphNode(issModel) + openspace.removeSceneGraphNode(issPosition) end) asset.export(issTrail) -asset.export(parentNode) -asset.export(iss) - +asset.export(issModel) +asset.export(issPosition) asset.meta = { Name = "ISS", Version = "1.0", Description = [[Model and Trail for ISS. Model from NASA 3D models, trail from - Celestrak]], + Celestrak.]], Author = "OpenSpace Team", URL = "https://celestrak.com/", License = "NASA" From 93a8b3af8a514ad3fe172e632d80c74908e66260 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 10 Oct 2022 09:31:35 +0200 Subject: [PATCH 11/68] Small clean up --- .../scene/solarsystem/planets/earth/satellites/misc/iss.asset | 1 - modules/base/rendering/renderablemodel.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 65cef39143..3e63f2237b 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -20,7 +20,6 @@ local omm = asset.syncedResource({ local issPosition = { Identifier = "ISSPosition", Parent = transforms.EarthInertial.Identifier, - InteractionSphere = 30, Transform = { Translation = { Type = "GPTranslation", diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index b2711aeae1..46f38edb19 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include From a77e227430e8861174e8e3b517ac13753c1fb191 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 28 Oct 2022 10:12:56 +0200 Subject: [PATCH 12/68] Re-use textures in the FramebufferRenderer for model opacity rendering --- .../openspace/rendering/framebufferrenderer.h | 7 + include/openspace/rendering/renderengine.h | 2 + modules/base/rendering/renderablemodel.cpp | 136 +++--------------- modules/base/rendering/renderablemodel.h | 6 - src/rendering/framebufferrenderer.cpp | 16 +++ 5 files changed, 46 insertions(+), 121 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 432b513ef2..761d28d120 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -59,6 +59,13 @@ class FramebufferRenderer final : public RaycasterListener, public Deferredcaste public: virtual ~FramebufferRenderer() override = default; + // Get functions for Model Opacity rendering + // TODO: Add a REALLY good documentation here + GLuint* additionalColorTexture(); + GLuint* additionalPositionTexture(); + GLuint* additionalNormalTexture(); + GLuint* additionalDepthTexture(); + void initialize(); void deinitialize(); diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index dfc751a3f3..eddc53ce76 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -68,6 +68,8 @@ public: RenderEngine(); virtual ~RenderEngine() override; + FramebufferRenderer* renderer(); + void initialize(); void initializeGL(); void deinitializeGL(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 46f38edb19..1d237fd867 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -601,40 +602,32 @@ void RenderableModel::initializeGL() { ); // Generate textures and the frame buffer - glGenTextures(1, &_colorTexture); - glGenTextures(1, &_positionTexture); - glGenTextures(1, &_normalTexture); - glGenTextures(1, &_depthTexture); glGenFramebuffers(1, &_framebuffer); - // Create Textures - _resolution = global::windowDelegate->currentDrawBufferResolution(); - updateResolution(); - // Bind textures to the framebuffer glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - _colorTexture, + *(global::renderEngine->renderer()->additionalColorTexture()), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, - _positionTexture, + *(global::renderEngine->renderer()->additionalPositionTexture()), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, - _normalTexture, + *(global::renderEngine->renderer()->additionalNormalTexture()), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - _depthTexture, + *(global::renderEngine->renderer()->additionalDepthTexture()), 0 ); @@ -654,104 +647,11 @@ void RenderableModel::initializeGL() { _geometry->calculateBoundingRadius(); } -void RenderableModel::updateResolution() { - ZoneScoped - - // Create the textures - // Color - glBindTexture(GL_TEXTURE_2D, _colorTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(_resolution.x), - static_cast(_resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _colorTexture, -1, "RenderableModel Color"); - } - - // Position - glBindTexture(GL_TEXTURE_2D, _positionTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(_resolution.x), - static_cast(_resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _positionTexture, -1, "RenderableModel Position"); - } - - // Normal - glBindTexture(GL_TEXTURE_2D, _normalTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - static_cast(_resolution.x), - static_cast(_resolution.y), - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _normalTexture, -1, "RenderableModel Normal"); - } - - // Depth - glBindTexture(GL_TEXTURE_2D, _depthTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_DEPTH_COMPONENT32F, - static_cast(_resolution.x), - static_cast(_resolution.y), - 0, - GL_DEPTH_COMPONENT, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _depthTexture, -1, "RenderableModel Depth"); - } -} - void RenderableModel::deinitializeGL() { _geometry->deinitialize(); _geometry.reset(); glDeleteFramebuffers(1, &_framebuffer); - glDeleteTextures(1, &_colorTexture); - glDeleteTextures(1, &_depthTexture); - glDeleteTextures(1, &_positionTexture); - glDeleteTextures(1, &_normalTexture); glDeleteBuffers(1, &_quadVbo); glDeleteVertexArrays(1, &_quadVao); @@ -928,12 +828,18 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Bind textures ghoul::opengl::TextureUnit colorTextureUnit; colorTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D, _colorTexture); + glBindTexture( + GL_TEXTURE_2D, + *(global::renderEngine->renderer()->additionalColorTexture()) + ); _quadProgram->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); ghoul::opengl::TextureUnit positionTextureUnit; positionTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D, _positionTexture); + glBindTexture( + GL_TEXTURE_2D, + *(global::renderEngine->renderer()->additionalPositionTexture()) + ); _quadProgram->setUniform( _uniformOpacityCache.positionTexture, positionTextureUnit @@ -941,12 +847,18 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ghoul::opengl::TextureUnit normalTextureUnit; normalTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D, _normalTexture); + glBindTexture( + GL_TEXTURE_2D, + *(global::renderEngine->renderer()->additionalNormalTexture()) + ); _quadProgram->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); ghoul::opengl::TextureUnit depthTextureUnit; depthTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D, _depthTexture); + glBindTexture( + GL_TEXTURE_2D, + *(global::renderEngine->renderer()->additionalDepthTexture()) + ); _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); // Draw @@ -967,12 +879,6 @@ void RenderableModel::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } - glm::ivec2 resolution = global::windowDelegate->currentDrawBufferResolution(); - if (resolution != _resolution) { - _resolution = resolution; - updateResolution(); - } - setBoundingSphere(_geometry->boundingRadius() * _modelScale * glm::compMax(data.modelTransform.scale) ); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index c7705b7c2b..190c09476a 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -119,14 +119,8 @@ private: // Framebuffer and its textures GLuint _framebuffer; - GLuint _colorTexture; - GLuint _depthTexture; - GLuint _positionTexture; - GLuint _normalTexture; GLuint _quadVao; GLuint _quadVbo; - glm::ivec2 _resolution = glm::ivec2(0); - void updateResolution(); ghoul::opengl::ProgramObject* _quadProgram = nullptr; UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 527e741c0b..ffa8676be4 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -87,6 +87,22 @@ namespace { namespace openspace { +GLuint* FramebufferRenderer::additionalColorTexture() { + return &_hdrBuffers.hdrFilteringTexture; +} + +GLuint* FramebufferRenderer::additionalPositionTexture() { + return &_exitColorTexture; +} + +GLuint* FramebufferRenderer::additionalNormalTexture() { + return &_fxaaBuffers.fxaaTexture; +} + +GLuint* FramebufferRenderer::additionalDepthTexture() { + return &_exitDepthTexture; +} + void FramebufferRenderer::initialize() { ZoneScoped TracyGpuZone("Rendering initialize"); From 3cca0fb229daefa858fe9c91214581cb6782cc97 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 28 Oct 2022 10:14:35 +0200 Subject: [PATCH 13/68] Add function in RenderEngine that gives access to FramebufferRenderer --- src/rendering/renderengine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 19ab3b5ae9..acdae788b5 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -413,6 +413,10 @@ RenderEngine::RenderEngine() RenderEngine::~RenderEngine() {} // NOLINT +FramebufferRenderer* RenderEngine::renderer() { + return &_renderer; +} + void RenderEngine::initialize() { ZoneScoped From 8e2f5450f4731faa0ff0cc1a8f8a7c7528a9c0ea Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 2 Nov 2022 17:34:00 +0100 Subject: [PATCH 14/68] Add documentation for texture access functions --- .../openspace/rendering/framebufferrenderer.h | 43 ++++++++++++++++--- modules/base/rendering/renderablemodel.cpp | 16 +++---- src/rendering/framebufferrenderer.cpp | 21 +++++---- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 761d28d120..ea843ecfae 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -59,12 +59,43 @@ class FramebufferRenderer final : public RaycasterListener, public Deferredcaste public: virtual ~FramebufferRenderer() override = default; - // Get functions for Model Opacity rendering - // TODO: Add a REALLY good documentation here - GLuint* additionalColorTexture(); - GLuint* additionalPositionTexture(); - GLuint* additionalNormalTexture(); - GLuint* additionalDepthTexture(); + // Functions to access and reuse some of the existing textures + /** + * Gives access to the currently NOT used pingPongTexture. This texture is available + * for all RenderBins. However, it cannot be used at the same time as the Deferred + * Caster Tasks. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the currently NOT used pingPongTexture + */ + GLuint additionalColorTexture1(); + + /** + * Gives access to the exitColorTexture. This texture is available for all RenderBins. + * However, it cannot be used at the same time as the Raycaster Tasks. The size of the + * texture is the resolution of the viewport. + * + * \return GLuint identifier of the exitColorTexture + */ + GLuint additionalColorTexture2(); + + /** + * Gives access to the fxaaTexture. This texture is available for all RenderBins. + * However, it cannot be used at the same time as the FXAA Task. The size of the + * texture is the resolution of the viewport. + * + * \return GLuint identifier of the fxaaTexture + */ + GLuint additionalColorTexture3(); + + /** + * Gives access to the exitDepthTexture. This texture is available for all RenderBins. + * However, it cannot be used at the same time as the Raycaster Tasks. The size of the + * texture is the resolution of the viewport. + * + * \return GLuint identifier of the exitDepthTexture + */ + GLuint additionalDepthTexture(); + void initialize(); void deinitialize(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 1d237fd867..142a09aa40 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -609,25 +609,25 @@ void RenderableModel::initializeGL() { glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - *(global::renderEngine->renderer()->additionalColorTexture()), + global::renderEngine->renderer()->additionalColorTexture1(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, - *(global::renderEngine->renderer()->additionalPositionTexture()), + global::renderEngine->renderer()->additionalColorTexture2(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, - *(global::renderEngine->renderer()->additionalNormalTexture()), + global::renderEngine->renderer()->additionalColorTexture3(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - *(global::renderEngine->renderer()->additionalDepthTexture()), + global::renderEngine->renderer()->additionalDepthTexture(), 0 ); @@ -830,7 +830,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { colorTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - *(global::renderEngine->renderer()->additionalColorTexture()) + global::renderEngine->renderer()->additionalColorTexture1() ); _quadProgram->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); @@ -838,7 +838,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { positionTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - *(global::renderEngine->renderer()->additionalPositionTexture()) + global::renderEngine->renderer()->additionalColorTexture2() ); _quadProgram->setUniform( _uniformOpacityCache.positionTexture, @@ -849,7 +849,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { normalTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - *(global::renderEngine->renderer()->additionalNormalTexture()) + global::renderEngine->renderer()->additionalColorTexture3() ); _quadProgram->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); @@ -857,7 +857,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { depthTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - *(global::renderEngine->renderer()->additionalDepthTexture()) + global::renderEngine->renderer()->additionalDepthTexture() ); _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index ffa8676be4..397c930047 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -87,20 +87,25 @@ namespace { namespace openspace { -GLuint* FramebufferRenderer::additionalColorTexture() { - return &_hdrBuffers.hdrFilteringTexture; +// Gives access to the currently NOT used pingPongTexture +GLuint FramebufferRenderer::additionalColorTexture1() { + int unusedPingPongIndex = _pingPongIndex == 0 ? 1 : 0; + return _pingPongBuffers.colorTexture[unusedPingPongIndex]; } -GLuint* FramebufferRenderer::additionalPositionTexture() { - return &_exitColorTexture; +// Gives access to the exitColorTexture +GLuint FramebufferRenderer::additionalColorTexture2() { + return _exitColorTexture; } -GLuint* FramebufferRenderer::additionalNormalTexture() { - return &_fxaaBuffers.fxaaTexture; +// Gives access to the fxaaTexture +GLuint FramebufferRenderer::additionalColorTexture3() { + return _fxaaBuffers.fxaaTexture; } -GLuint* FramebufferRenderer::additionalDepthTexture() { - return &_exitDepthTexture; +// Gives access to the exitDepthTexture +GLuint FramebufferRenderer::additionalDepthTexture() { + return _exitDepthTexture; } void FramebufferRenderer::initialize() { From e749be21a51364f8bdbf330dee631f5a297b8dd4 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 2 Nov 2022 17:46:20 +0100 Subject: [PATCH 15/68] Move Overlay RenderBin to before postDeffredTransparent --- modules/base/rendering/renderablemodel.cpp | 2 +- src/rendering/framebufferrenderer.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 142a09aa40..7470d3265e 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -792,7 +792,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); if (o >= 0.f && o < 1.f) { - setRenderBin(Renderable::RenderBin::Overlay); + setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { setRenderBin(Renderable::RenderBin::Opaque); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 397c930047..87f971715b 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -1207,6 +1207,13 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac glDrawBuffers(1, &ColorAttachmentArray[_pingPongIndex]); glEnablei(GL_BLEND, 0); + { + TracyGpuZone("Overlay") + ghoul::GLDebugGroup group("Overlay"); + data.renderBinMask = static_cast(Renderable::RenderBin::Overlay); + scene->render(data, tasks); + } + { TracyGpuZone("PostDeferredTransparent") ghoul::GLDebugGroup group("PostDeferredTransparent"); @@ -1216,13 +1223,6 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac scene->render(data, tasks); } - { - TracyGpuZone("Overlay") - ghoul::GLDebugGroup group("Overlay"); - data.renderBinMask = static_cast(Renderable::RenderBin::Overlay); - scene->render(data, tasks); - } - glDrawBuffer(GL_COLOR_ATTACHMENT0); // Disabling depth test for filtering and hdr From 0bb6d25e2edfc76c8afab958deacb34bf38b6135 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 3 Nov 2022 10:29:53 +0100 Subject: [PATCH 16/68] Add a new bin in the end of the pipeline --- include/openspace/rendering/renderable.h | 5 +++-- src/rendering/framebufferrenderer.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index c29305ed08..401257047d 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -57,8 +57,9 @@ public: Background = 1, Opaque = 2, PreDeferredTransparent = 4, - PostDeferredTransparent = 8, - Overlay = 16 + Overlay = 8, + PostDeferredTransparent = 16, + Sticker = 32 }; static ghoul::mm_unique_ptr createFromDictionary( diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 87f971715b..b30d00e7d9 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -964,7 +964,7 @@ void FramebufferRenderer::updateResolution() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _exitColorTexture, -1, "Exit depth"); + glObjectLabel(GL_TEXTURE, _exitDepthTexture, -1, "Exit depth"); } _dirtyResolution = false; From 6c223cd8ae9a635c8de56d6fb9a32ae977767c18 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 3 Nov 2022 11:15:21 +0100 Subject: [PATCH 17/68] Some clean up --- .../planets/earth/satellites/misc/iss.asset | 2 +- .../openspace/rendering/framebufferrenderer.h | 1 - modules/base/rendering/renderablemodel.cpp | 21 +++++++------------ modules/base/rendering/renderablemodel.h | 5 +++-- src/rendering/framebufferrenderer.cpp | 9 ++++++++ 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 9b30e45790..dfaece1cf8 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -110,7 +110,7 @@ local IssLabel = { FadeDistances = { 0.15, 15.0 }, FadeWidths = { 1.0, 25.0 } }, - Tag = { "solarsystem_labels", "earth_satellite", "ISS" }, + Tag = { "solarsystem_labels" }, GUI = { Name = "ISS Label", Path = "/Solar System/Planets/Earth/Satellites" diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index ea843ecfae..754b7603c9 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -96,7 +96,6 @@ public: */ GLuint additionalDepthTexture(); - void initialize(); void deinitialize(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 7470d3265e..376d4ba703 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -573,13 +572,13 @@ void RenderableModel::initializeGL() { // Screen quad VAO const GLfloat quadVertices[] = { - // x y s t - -1.f, -1.f, 0.f, 0.f, - 1.f, 1.f, 1.f, 1.f, - -1.f, 1.f, 0.f, 1.f, - -1.f, -1.f, 0.f, 0.f, - 1.f, -1.f, 1.f, 0.f, - 1.f, 1.f, 1.f, 1.f + // x y s t + -1.f, -1.f, 0.f, 0.f, + 1.f, 1.f, 1.f, 1.f, + -1.f, 1.f, 0.f, 1.f, + -1.f, -1.f, 0.f, 0.f, + 1.f, -1.f, 1.f, 0.f, + 1.f, 1.f, 1.f, 1.f }; glGenVertexArrays(1, &_quadVao); @@ -791,7 +790,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); - if (o >= 0.f && o < 1.f) { + if ((o >= 0.f && o < 1.f) || _disableDepthTest) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { @@ -804,10 +803,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { } _program->deactivate(); - if (_disableDepthTest) { - glEnable(GL_DEPTH_TEST); - } - // Render pass 2 // Render the whole model into the G-buffer with the correct opacity glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 190c09476a..88604f2fb6 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -117,12 +117,13 @@ private: properties::PropertyOwner _lightSourcePropertyOwner; - // Framebuffer and its textures + // Framebuffer and screen space quad GLuint _framebuffer; GLuint _quadVao; GLuint _quadVbo; - ghoul::opengl::ProgramObject* _quadProgram = nullptr; + // Opacity program + ghoul::opengl::ProgramObject* _quadProgram = nullptr; UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, normalTexture) _uniformOpacityCache; }; diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index b30d00e7d9..0b8a916c05 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -1223,6 +1223,15 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac scene->render(data, tasks); } + { + TracyGpuZone("Sticker") + ghoul::GLDebugGroup group("Sticker"); + data.renderBinMask = static_cast( + Renderable::RenderBin::Sticker + ); + scene->render(data, tasks); + } + glDrawBuffer(GL_COLOR_ATTACHMENT0); // Disabling depth test for filtering and hdr From 8dbdba117499fee2b5ba542f5c280aeb8483b854 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 3 Nov 2022 13:14:08 +0100 Subject: [PATCH 18/68] Fix opacity blending --- modules/base/rendering/renderablemodel.cpp | 2 +- modules/base/shaders/modelOpacity_fs.glsl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 376d4ba703..20601d884d 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -790,7 +790,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); - if ((o >= 0.f && o < 1.f) || _disableDepthTest) { + if ((o >= 0.f && o < 1.f) || _disableDepthTest || _enableOpacityBlending) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 483acf2ad2..2b147b0921 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -43,6 +43,8 @@ Fragment getFragment() { discard; } + frag.color.rgb = textureColor.rgb; + if (opacityBlending) { frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); } @@ -50,7 +52,6 @@ Fragment getFragment() { frag.color.a = opacity; } - frag.color.rgb = textureColor.rgb; frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); frag.gPosition = texture(positionTexture, vs_st); frag.gNormal = vec4(texture(normalTexture, vs_st).rgb, 0.0); From d81a242bfc8b8dd37e1517a52808fb8e4e8d357d Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 9 Nov 2022 11:37:12 +0100 Subject: [PATCH 19/68] Sync tracy function with new RenderBin order --- src/scene/scene.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 3ebe8edf34..f5cdcc7793 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -75,10 +75,13 @@ namespace { return "PreDeferredTransparent"; } else if (renderBin == 8) { - return "PostDeferredTransparent"; + return "Overlay"; } else if (renderBin == 16) { - return "Overlay"; + return "PostDeferredTransparent"; + } + else if (renderBin == 32) { + return "Sticker"; } else { throw ghoul::MissingCaseException(); From 2cd09de2fad20633d7758724fbff1fd9dd939c51 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 14 Nov 2022 10:27:20 +0100 Subject: [PATCH 20/68] Fix support for transparent models --- ext/ghoul | 2 +- modules/base/rendering/renderablemodel.cpp | 4 +++- modules/base/rendering/renderablemodel.h | 3 +++ modules/base/shaders/modelOpacity_fs.glsl | 2 +- modules/base/shaders/model_fs.glsl | 18 +++++++++--------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index df84293686..538b0aef98 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit df84293686f270d40be22725e6b11a4e020b8bf3 +Subproject commit 538b0aef98a62705bf9b83d4299ce11a85d0be64 diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 20601d884d..67333f808f 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -497,6 +497,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _enableOpacityBlending = p.enableOpacityBlending.value_or(_enableOpacityBlending); addProperty(_enableOpacityBlending); + + _originalRenderBin = renderBin(); } bool RenderableModel::isReady() const { @@ -794,7 +796,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { - setRenderBin(Renderable::RenderBin::Opaque); + setRenderBin(_originalRenderBin); } _geometry->render(*_program); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 88604f2fb6..9c193c05f8 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -126,6 +126,9 @@ private: ghoul::opengl::ProgramObject* _quadProgram = nullptr; UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, normalTexture) _uniformOpacityCache; + + // Store the original RenderBin + Renderable::RenderBin _originalRenderBin; }; } // namespace openspace diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 2b147b0921..e5af586447 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -49,7 +49,7 @@ Fragment getFragment() { frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); } else { - frag.color.a = opacity; + frag.color.a = opacity * textureColor.a; } frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 1cd48498b9..b01219f0b6 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -42,8 +42,8 @@ uniform bool has_color_specular; uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; -uniform vec3 color_diffuse; -uniform vec3 color_specular; +uniform vec4 color_diffuse; +uniform vec4 color_specular; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; @@ -70,9 +70,9 @@ Fragment getFragment() { return frag; } - vec3 diffuseAlbedo; + vec4 diffuseAlbedo; if (has_texture_diffuse) { - diffuseAlbedo = texture(texture_diffuse, vs_st).rgb; + diffuseAlbedo = texture(texture_diffuse, vs_st); } else { diffuseAlbedo = color_diffuse; @@ -87,7 +87,7 @@ Fragment getFragment() { } else { if (has_color_specular) { - specularAlbedo = color_specular; + specularAlbedo = color_specular.rgb ; } else { specularAlbedo = vec3(1.0); @@ -110,7 +110,7 @@ Fragment getFragment() { vec3 c = normalize(vs_positionCameraSpace.xyz); - vec3 color = ambientIntensity * lightColorAmbient * diffuseAlbedo; + vec3 color = ambientIntensity * lightColorAmbient * diffuseAlbedo.rgb; for (int i = 0; i < nLightSources; ++i) { vec3 l = lightDirectionsViewSpace[i]; @@ -121,7 +121,7 @@ Fragment getFragment() { const float specularPower = 100.0; vec3 diffuseColor = - diffuseIntensity * lightColor * diffuseAlbedo * max(diffuseCosineFactor, 0); + diffuseIntensity * lightColor * diffuseAlbedo.rgb * max(diffuseCosineFactor, 0); vec3 specularColor = specularIntensity * lightColor * specularAlbedo * @@ -132,10 +132,10 @@ Fragment getFragment() { frag.color.rgb = color; } else { - frag.color.rgb = diffuseAlbedo; + frag.color.rgb = diffuseAlbedo.rgb; } - frag.color.a = 1.0; + frag.color.a = diffuseAlbedo.a; frag.depth = vs_screenSpaceDepth; frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); From 433c2cd3a904011f2eb55c3e4d58c3c34b361a04 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 15 Nov 2022 15:57:25 +0100 Subject: [PATCH 21/68] Remove unused hdr framebuffer and texture --- .../openspace/rendering/framebufferrenderer.h | 5 -- src/rendering/framebufferrenderer.cpp | 51 ------------------- 2 files changed, 56 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 754b7603c9..c55eabdb81 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -191,11 +191,6 @@ private: GLuint colorTexture[2]; } _pingPongBuffers; - struct { - GLuint hdrFilteringFramebuffer; - GLuint hdrFilteringTexture; - } _hdrBuffers; - struct { GLuint fxaaFramebuffer; GLuint fxaaTexture; diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 0b8a916c05..d7c9305823 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -155,10 +155,6 @@ void FramebufferRenderer::initialize() { glGenTextures(1, &_exitDepthTexture); glGenFramebuffers(1, &_exitFramebuffer); - // HDR / Filtering Buffers - glGenFramebuffers(1, &_hdrBuffers.hdrFilteringFramebuffer); - glGenTextures(1, &_hdrBuffers.hdrFilteringTexture); - // FXAA Buffers glGenFramebuffers(1, &_fxaaBuffers.fxaaFramebuffer); glGenTextures(1, &_fxaaBuffers.fxaaTexture); @@ -273,30 +269,6 @@ void FramebufferRenderer::initialize() { LERROR("Exit framebuffer is not complete"); } - //===================================// - //===== HDR/Filtering Buffers =====// - //===================================// - glBindFramebuffer(GL_FRAMEBUFFER, _hdrBuffers.hdrFilteringFramebuffer); - glFramebufferTexture( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - _hdrBuffers.hdrFilteringTexture, - 0 - ); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel( - GL_FRAMEBUFFER, - _hdrBuffers.hdrFilteringFramebuffer, - -1, - "HDR filtering" - ); - } - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - LERROR("HDR/Filtering framebuffer is not complete"); - } - //===================================// //========== FXAA Buffers =========// //===================================// @@ -405,7 +377,6 @@ void FramebufferRenderer::deinitialize() { glDeleteFramebuffers(1, &_gBuffers.framebuffer); glDeleteFramebuffers(1, &_exitFramebuffer); - glDeleteFramebuffers(1, &_hdrBuffers.hdrFilteringFramebuffer); glDeleteFramebuffers(1, &_fxaaBuffers.fxaaFramebuffer); glDeleteFramebuffers(1, &_pingPongBuffers.framebuffer); glDeleteFramebuffers(1, &_downscaleVolumeRendering.framebuffer); @@ -413,7 +384,6 @@ void FramebufferRenderer::deinitialize() { glDeleteTextures(1, &_gBuffers.colorTexture); glDeleteTextures(1, &_gBuffers.depthTexture); - glDeleteTextures(1, &_hdrBuffers.hdrFilteringTexture); glDeleteTextures(1, &_fxaaBuffers.fxaaTexture); glDeleteTextures(1, &_gBuffers.positionTexture); glDeleteTextures(1, &_gBuffers.normalTexture); @@ -822,27 +792,6 @@ void FramebufferRenderer::updateResolution() { ); } - // HDR / Filtering - glBindTexture(GL_TEXTURE_2D, _hdrBuffers.hdrFilteringTexture); - glTexImage2D( - GL_TEXTURE_2D, - 0, - GL_RGBA32F, - _resolution.x, - _resolution.y, - 0, - GL_RGBA, - GL_FLOAT, - nullptr - ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (glbinding::Binding::ObjectLabel.isResolved()) { - glObjectLabel(GL_TEXTURE, _hdrBuffers.hdrFilteringTexture, -1, "HDR filtering"); - } - // FXAA glBindTexture(GL_TEXTURE_2D, _fxaaBuffers.fxaaTexture); glTexImage2D( From 04f0b1281a4c032497e53dfce46d22fa4349e431 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 15 Nov 2022 16:06:05 +0100 Subject: [PATCH 22/68] Remove EnableOpacityBlending property for models (unused) --- modules/base/rendering/renderablemodel.cpp | 24 +++------------------- modules/base/rendering/renderablemodel.h | 3 +-- modules/base/shaders/modelOpacity_fs.glsl | 9 +------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 67333f808f..84ea0c8271 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -84,8 +84,8 @@ namespace { "specularIntensity" }; - constexpr std::array UniformOpacityNames = { - "opacity", "opacityBlending", "colorTexture", "depthTexture", "positionTexture", + constexpr std::array UniformOpacityNames = { + "opacity", "colorTexture", "depthTexture", "positionTexture", "normalTexture" }; @@ -152,12 +152,6 @@ namespace { "respect to the opacity" }; - constexpr openspace::properties::Property::PropertyInfo EnableOpacityBlendingInfo = { - "EnableOpacityBlending", - "Enable Opacity Blending", - "Enable Opacity Blending" - }; - struct [[codegen::Dictionary(RenderableModel)]] Parameters { // The file or files that should be loaded in this RenderableModel. The file can // contain filesystem tokens. This specifies the model that is rendered by @@ -261,9 +255,6 @@ namespace { // [[codegen::verbatim(BlendingOptionInfo.description)]] std::optional blendingOption; - // [[codegen::verbatim(EnableOpacityBlendingInfo.description)]] - std::optional enableOpacityBlending; - // The path to the vertex shader program that is used instead of the default // shader. std::optional vertexShader; @@ -297,7 +288,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) ) , _rotationVec(RotationVecInfo, glm::dvec3(0.0), glm::dvec3(0.0), glm::dvec3(360.0)) , _disableDepthTest(DisableDepthTestInfo, false) - , _enableOpacityBlending(EnableOpacityBlendingInfo, false) , _blendingFuncOption( BlendingOptionInfo, properties::OptionProperty::DisplayType::Dropdown @@ -494,10 +484,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _blendingFuncOption.set(BlendingMapping[blendingOpt]); } - _enableOpacityBlending = p.enableOpacityBlending.value_or(_enableOpacityBlending); - - addProperty(_enableOpacityBlending); - _originalRenderBin = renderBin(); } @@ -792,7 +778,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); - if ((o >= 0.f && o < 1.f) || _disableDepthTest || _enableOpacityBlending) { + if ((o >= 0.f && o < 1.f) || _disableDepthTest) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { @@ -817,10 +803,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _quadProgram->activate(); _quadProgram->setUniform(_uniformOpacityCache.opacity, opacity()); - _quadProgram->setUniform( - _uniformOpacityCache.opacityBlending, - _enableOpacityBlending - ); // Bind textures ghoul::opengl::TextureUnit colorTextureUnit; diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 9c193c05f8..ca84a6b61c 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -98,7 +98,6 @@ private: properties::Vec3Property _rotationVec; properties::BoolProperty _disableDepthTest; - properties::BoolProperty _enableOpacityBlending; properties::OptionProperty _blendingFuncOption; std::string _vertexShaderPath; @@ -124,7 +123,7 @@ private: // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; - UniformCache(opacity, opacityBlending, colorTexture, depthTexture, positionTexture, + UniformCache(opacity, colorTexture, depthTexture, positionTexture, normalTexture) _uniformOpacityCache; // Store the original RenderBin diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index e5af586447..a9a0da3281 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -28,7 +28,6 @@ in vec2 vs_st; uniform float opacity = 1.0; -uniform bool opacityBlending = false; uniform sampler2D colorTexture; uniform sampler2D depthTexture; @@ -44,13 +43,7 @@ Fragment getFragment() { } frag.color.rgb = textureColor.rgb; - - if (opacityBlending) { - frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b); - } - else { - frag.color.a = opacity * textureColor.a; - } + frag.color.a = opacity * textureColor.a; frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); frag.gPosition = texture(positionTexture, vs_st); From a0423daf301f6f3e7284580508c659aef74c64ac Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 15 Nov 2022 16:24:49 +0100 Subject: [PATCH 23/68] Render front anv back faces seperatly to fix transparency --- modules/base/rendering/renderablemodel.cpp | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 84ea0c8271..9fafe87cb9 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -741,10 +741,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); - if (_disableFaceCulling) { - glDisable(GL_CULL_FACE); - } - glEnablei(GL_BLEND, 0); switch (_blendingFuncOption) { case DefaultBlending: @@ -785,7 +781,28 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { setRenderBin(_originalRenderBin); } - _geometry->render(*_program); + bool shouldRenderTwice = !_disableFaceCulling; + int nPasses = shouldRenderTwice ? 2 : 1; + for (int i = 0; i < nPasses; ++i) { + if (shouldRenderTwice) { + glEnable(GL_CULL_FACE); + + if (i == 0) { + // First draw back faces (remove front faces) + glCullFace(GL_FRONT); + } + else { + // Then front faces (remove back faces) + glCullFace(GL_BACK); + } + } + else { + glDisable(GL_CULL_FACE); + } + + _geometry->render(*_program); + } + if (_disableFaceCulling) { glEnable(GL_CULL_FACE); } From ec625c1c4139892796b8bdc0b636d01bff229a8f Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 16 Nov 2022 16:41:16 +0100 Subject: [PATCH 24/68] Detect transparent models --- ext/ghoul | 2 +- modules/base/rendering/renderablemodel.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 538b0aef98..81cd7c79c8 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 538b0aef98a62705bf9b83d4299ce11a85d0be64 +Subproject commit 81cd7c79c886e5fa8706f0fee35e3c7dfe068548 diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 9fafe87cb9..c1943ba257 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -781,7 +781,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { setRenderBin(_originalRenderBin); } - bool shouldRenderTwice = !_disableFaceCulling; + bool shouldRenderTwice = !_disableFaceCulling && _geometry->isTransparent(); int nPasses = shouldRenderTwice ? 2 : 1; for (int i = 0; i < nPasses; ++i) { if (shouldRenderTwice) { From c6badaf8b7e7d8837b2ecf55214c0fe5fbc1026d Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 22 Nov 2022 09:41:37 +0100 Subject: [PATCH 25/68] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 81cd7c79c8..785c1bf1e8 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 81cd7c79c886e5fa8706f0fee35e3c7dfe068548 +Subproject commit 785c1bf1e855e8b7ec8d00fea6bda35ad07393c1 From 005ff102e78a8368aa751a54420acd0f1f6c1d72 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 23 Nov 2022 11:43:15 +0100 Subject: [PATCH 26/68] Decouple property for culling and transparecny 2 pass for models --- modules/base/rendering/renderablemodel.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index c1943ba257..7873386ab0 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -764,6 +764,10 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glDisable(GL_DEPTH_TEST); } + if (_disableFaceCulling) { + glDisable(GL_CULL_FACE); + } + // Prepare framebuffer GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); @@ -796,9 +800,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glCullFace(GL_BACK); } } - else { - glDisable(GL_CULL_FACE); - } _geometry->render(*_program); } From c5ddb3ce1772895ea5161ef92585c5e680e69d82 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 25 Nov 2022 09:57:20 +0100 Subject: [PATCH 27/68] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 785c1bf1e8..dab146e133 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 785c1bf1e855e8b7ec8d00fea6bda35ad07393c1 +Subproject commit dab146e133d651130b8ade6e7837ea9f898b696c From bf25e4562ac93113afa6d3c87aed194948761f69 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 25 Nov 2022 10:01:46 +0100 Subject: [PATCH 28/68] Invert the disable properties culling and depth test in models * disableFaceCulling -> enableFaceCulling * disableDepthTest -> enableDepthTest --- data/assets/examples/animation.asset | 10 ++-- data/assets/examples/approachevents.asset | 2 +- .../examples/modelshader/modelshader.asset | 6 +-- .../milkyway/objects/orionnebula/nebula.asset | 10 ++-- .../missions/apollo/15/apollo15.asset | 6 +-- .../missions/apollo/17/bouldersstation2.asset | 8 ++-- .../missions/apollo/17/bouldersstation6.asset | 8 ++-- .../missions/apollo/17/bouldersstation7.asset | 6 +-- .../missions/apollo/8/launch_model.asset | 6 +-- .../solarsystem/missions/apollo/8/model.asset | 6 +-- .../solarsystem/missions/jwst/jwst.asset | 2 +- .../planets/earth/satellites/misc/iss.asset | 2 +- .../planets/mars/moons/deimos.asset | 6 +-- .../planets/mars/moons/phobos.asset | 6 +-- .../scene/solarsystem/sssb/itokawa.asset | 2 +- data/assets/util/asset_helper.asset | 2 +- modules/base/rendering/renderablemodel.cpp | 46 +++++++++---------- modules/base/rendering/renderablemodel.h | 4 +- 18 files changed, 69 insertions(+), 69 deletions(-) diff --git a/data/assets/examples/animation.asset b/data/assets/examples/animation.asset index 69a3b14451..55af363650 100644 --- a/data/assets/examples/animation.asset +++ b/data/assets/examples/animation.asset @@ -30,7 +30,7 @@ local animationLoop = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Animated Model example (LoopFromStart)", @@ -59,7 +59,7 @@ local animationLoopInf = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Animated Model example (LoopInfinitely)", @@ -88,7 +88,7 @@ local animationOnce = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Animated Model example (Once)", @@ -117,7 +117,7 @@ local animationBounceInf = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Animated Model example (BounceInfinitely)", @@ -146,7 +146,7 @@ local animationBounce = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Animated Model example (BounceFromStart)", diff --git a/data/assets/examples/approachevents.asset b/data/assets/examples/approachevents.asset index ceac006790..248bc10875 100644 --- a/data/assets/examples/approachevents.asset +++ b/data/assets/examples/approachevents.asset @@ -37,7 +37,7 @@ local obj = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, InteractionSphere = 1000.0, OnApproach = { "os.example.generic" }, diff --git a/data/assets/examples/modelshader/modelshader.asset b/data/assets/examples/modelshader/modelshader.asset index 969d3521cb..ab747c8917 100644 --- a/data/assets/examples/modelshader/modelshader.asset +++ b/data/assets/examples/modelshader/modelshader.asset @@ -25,7 +25,7 @@ local model = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true, + EnableFaceCulling = true, VertexShader = asset.localResource("model_vs.glsl"), FragmentShader = asset.localResource("model_fs.glsl"), }, @@ -39,9 +39,9 @@ local model = { asset.onInitialize(function() openspace.addSceneGraphNode(model) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(model) end) - + asset.export(model) diff --git a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset index 43fe0fcec8..de8aae2960 100644 --- a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset +++ b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset @@ -58,7 +58,7 @@ local OrionNebulaModel = { Type = "RenderableModel", GeometryFile = sync .. "orion_nebula.obj", Opacity = 1.0, - DisableFaceCulling = false, + EnableFaceCulling = true, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, @@ -93,7 +93,7 @@ local OrionNebulaShocksModel = { Type = "RenderableModel", GeometryFile = sync .. "orishocks.obj", Opacity = 1.0, - DisableFaceCulling = false, + EnableFaceCulling = true, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, @@ -129,7 +129,7 @@ local OrionNebulaProplydsModel = { Type = "RenderableModel", GeometryFile = sync .. "proplyds.obj", Opacity = 1.0, - DisableFaceCulling = false, + EnableFaceCulling = true, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, @@ -158,14 +158,14 @@ asset.onInitialize(function() openspace.addSceneGraphNode(OrionNebulaShocksModel) openspace.addSceneGraphNode(OrionNebulaProplydsModel) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(OrionNebulaProplydsModel) openspace.removeSceneGraphNode(OrionNebulaShocksModel) openspace.removeSceneGraphNode(OrionNebulaModel) openspace.removeSceneGraphNode(NebulaHolder) end) - + asset.export(NebulaHolder) asset.export(OrionNebulaModel) asset.export(OrionNebulaShocksModel) diff --git a/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset b/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset index 4623d140ce..53614c802d 100644 --- a/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset +++ b/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset @@ -44,7 +44,7 @@ local Apollo15 = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, TimeFrame = { Type = "TimeFrameInterval", @@ -84,11 +84,11 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Apollo15) openspace.addSceneGraphNode(Apollo15Trail) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(Apollo15Trail) openspace.removeSceneGraphNode(Apollo15) end) - + asset.export(Apollo15) asset.export(Apollo15Trail) diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset index ea4b2e8cb4..27b9134e5d 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset @@ -49,7 +49,7 @@ local Station2Boulder1Model = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 2 Boulder 1 Model", @@ -98,7 +98,7 @@ local Station2Boulder2Model = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 2 Boulder 2 Model", @@ -147,7 +147,7 @@ local Station2Boulder3Model = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 2 Boulder 3 Model", @@ -166,7 +166,7 @@ asset.onInitialize(function() openspace.addSceneGraphNode(node) end end) - + asset.onDeinitialize(function() for i = #nodes, 1, -1 do local node = nodes[i] diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset index 65683ec844..310b4aca4b 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset @@ -60,7 +60,7 @@ local Station6Frag1Model = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 6 Fragment 1 Model", @@ -110,7 +110,7 @@ local Station6Frag2Model = { } }, PerformShading = false, - DisableFaceCulling = true, + EnableFaceCulling = true, }, GUI = { Name = "Station 6 Fragment 2 Model", @@ -148,7 +148,7 @@ local Station6Frag3Model = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 6 Fragment 3 Model", @@ -166,7 +166,7 @@ asset.onInitialize(function() openspace.addSceneGraphNode(node) end end) - + asset.onDeinitialize(function() for i = #nodes, 1, -1 do local node = nodes[i] diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset index f9016a794c..62bcfe0030 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset @@ -49,7 +49,7 @@ local Station7BoulderModel = { } }, PerformShading = false, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "Station 7 Boulder Model", @@ -61,11 +61,11 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Station7BoulderHolder) openspace.addSceneGraphNode(Station7BoulderModel) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(Station7BoulderModel) openspace.removeSceneGraphNode(Station7BoulderHolder) end) - + asset.export(Station7BoulderHolder) asset.export(Station7BoulderModel) diff --git a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset index c66dfd8dc4..946b72ad4f 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset @@ -56,7 +56,7 @@ local Apollo8LaunchModel = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Hidden = true, @@ -69,11 +69,11 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Apollo8Launch) openspace.addSceneGraphNode(Apollo8LaunchModel) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(Apollo8LaunchModel) openspace.removeSceneGraphNode(Apollo8Launch) end) - + asset.export(Apollo8Launch) asset.export(Apollo8LaunchModel) diff --git a/data/assets/scene/solarsystem/missions/apollo/8/model.asset b/data/assets/scene/solarsystem/missions/apollo/8/model.asset index c3ada29c00..3f941633c7 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/model.asset @@ -68,7 +68,7 @@ local Apollo8Model = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Hidden = true, @@ -98,13 +98,13 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Apollo8Model) openspace.addSceneGraphNode(Apollo8Pivot) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(Apollo8Pivot) openspace.removeSceneGraphNode(Apollo8Model) openspace.removeSceneGraphNode(Apollo8) end) - + asset.export(Apollo8) asset.export(Apollo8Model) asset.export(Apollo8Pivot) diff --git a/data/assets/scene/solarsystem/missions/jwst/jwst.asset b/data/assets/scene/solarsystem/missions/jwst/jwst.asset index cefeb1e481..77ae6df0d6 100644 --- a/data/assets/scene/solarsystem/missions/jwst/jwst.asset +++ b/data/assets/scene/solarsystem/missions/jwst/jwst.asset @@ -77,7 +77,7 @@ local JWSTModel = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Name = "James Webb Space Telescope Model", diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index dfaece1cf8..e8fc60e900 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -61,7 +61,7 @@ local issModel = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, Tag = { "earth_satellite", "ISS" }, GUI = { diff --git a/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset b/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset index 031336a8b3..fae852e832 100644 --- a/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset +++ b/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset @@ -44,7 +44,7 @@ local Deimos = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, Tag = { "moon_solarSystem", "moon_terrestrial", "moon_mars" }, GUI = { @@ -80,12 +80,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Deimos) openspace.addSceneGraphNode(DeimosTrail) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(DeimosTrail) openspace.removeSceneGraphNode(Deimos) end) - + asset.export(Deimos) asset.export(DeimosTrail) diff --git a/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset b/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset index 2749acc643..3e874ed09a 100644 --- a/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset +++ b/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset @@ -45,7 +45,7 @@ local Phobos = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true + EnableFaceCulling = true }, Tag = { "moon_solarSystem", "moon_terrestrial", "moon_mars" }, GUI = { @@ -82,12 +82,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Phobos) openspace.addSceneGraphNode(PhobosTrail) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(PhobosTrail) openspace.removeSceneGraphNode(Phobos) end) - + asset.export(Phobos) asset.export(PhobosTrail) diff --git a/data/assets/scene/solarsystem/sssb/itokawa.asset b/data/assets/scene/solarsystem/sssb/itokawa.asset index e53c6466b1..f7e59f18c0 100644 --- a/data/assets/scene/solarsystem/sssb/itokawa.asset +++ b/data/assets/scene/solarsystem/sssb/itokawa.asset @@ -68,7 +68,7 @@ local ItokawaModel = { sun.LightSource }, PerformShading = true, - DisableFaceCulling = true, + EnableFaceCulling = true, SpecularIntensity = 0.0 }, GUI = { diff --git a/data/assets/util/asset_helper.asset b/data/assets/util/asset_helper.asset index 20ada1e52a..e905aea16c 100644 --- a/data/assets/util/asset_helper.asset +++ b/data/assets/util/asset_helper.asset @@ -170,7 +170,7 @@ local createModelPart = function (parent, sunLightSourceNode, models, geometry, GeometryFile = models .. "/" .. geometry .. ".obj", LightSources = lightSources, PerformShading = performShading, - DisableFaceCulling = true + EnableFaceCulling = true }, GUI = { Hidden = true diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 7873386ab0..bc1afd2ce7 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -114,10 +114,10 @@ namespace { "of the Sun" }; - constexpr openspace::properties::Property::PropertyInfo DisableFaceCullingInfo = { - "DisableFaceCulling", - "Disable Face Culling", - "Disable OpenGL automatic face culling optimization" + constexpr openspace::properties::Property::PropertyInfo EnableFaceCullingInfo = { + "EnableFaceCulling", + "Enable Face Culling", + "Enable OpenGL automatic face culling optimization" }; constexpr openspace::properties::Property::PropertyInfo ModelTransformInfo = { @@ -139,10 +139,10 @@ namespace { "A list of light sources that this model should accept light from" }; - constexpr openspace::properties::Property::PropertyInfo DisableDepthTestInfo = { - "DisableDepthTest", - "Disable Depth Test", - "Disable Depth Testing for the Model" + constexpr openspace::properties::Property::PropertyInfo EnableDepthTestInfo = { + "EnableDepthTest", + "Enable Depth Test", + "Enable Depth Testing for the Model" }; constexpr openspace::properties::Property::PropertyInfo BlendingOptionInfo = { @@ -236,8 +236,8 @@ namespace { // [[codegen::verbatim(ShadingInfo.description)]] std::optional performShading; - // [[codegen::verbatim(DisableFaceCullingInfo.description)]] - std::optional disableFaceCulling; + // [[codegen::verbatim(EnableFaceCullingInfo.description)]] + std::optional enableFaceCulling; // [[codegen::verbatim(ModelTransformInfo.description)]] std::optional modelTransform; @@ -249,8 +249,8 @@ namespace { std::optional> lightSources [[codegen::reference("core_light_source")]]; - // [[codegen::verbatim(DisableDepthTestInfo.description)]] - std::optional disableDepthTest; + // [[codegen::verbatim(EnableDepthTestInfo.description)]] + std::optional enableDepthTest; // [[codegen::verbatim(BlendingOptionInfo.description)]] std::optional blendingOption; @@ -279,7 +279,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) , _diffuseIntensity(DiffuseIntensityInfo, 1.f, 0.f, 1.f) , _specularIntensity(SpecularIntensityInfo, 1.f, 0.f, 1.f) , _performShading(ShadingInfo, true) - , _disableFaceCulling(DisableFaceCullingInfo, false) + , _enableFaceCulling(EnableFaceCullingInfo, true) , _modelTransform( ModelTransformInfo, glm::dmat3(1.0), @@ -287,7 +287,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) glm::dmat3(1.0) ) , _rotationVec(RotationVecInfo, glm::dvec3(0.0), glm::dvec3(0.0), glm::dvec3(360.0)) - , _disableDepthTest(DisableDepthTestInfo, false) + , _enableDepthTest(EnableDepthTestInfo, true) , _blendingFuncOption( BlendingOptionInfo, properties::OptionProperty::DisplayType::Dropdown @@ -415,8 +415,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _diffuseIntensity = p.diffuseIntensity.value_or(_diffuseIntensity); _specularIntensity = p.specularIntensity.value_or(_specularIntensity); _performShading = p.performShading.value_or(_performShading); - _disableDepthTest = p.disableDepthTest.value_or(_disableDepthTest); - _disableFaceCulling = p.disableFaceCulling.value_or(_disableFaceCulling); + _enableDepthTest = p.enableDepthTest.value_or(_enableDepthTest); + _enableFaceCulling = p.enableFaceCulling.value_or(_enableFaceCulling); if (p.vertexShader.has_value()) { _vertexShaderPath = p.vertexShader->string(); @@ -445,8 +445,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) addProperty(_diffuseIntensity); addProperty(_specularIntensity); addProperty(_performShading); - addProperty(_disableFaceCulling); - addProperty(_disableDepthTest); + addProperty(_enableFaceCulling); + addProperty(_enableDepthTest); addProperty(_modelTransform); addProperty(_rotationVec); @@ -760,11 +760,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { break; }; - if (_disableDepthTest) { + if (!_enableDepthTest) { glDisable(GL_DEPTH_TEST); } - if (_disableFaceCulling) { + if (!_enableFaceCulling) { glDisable(GL_CULL_FACE); } @@ -778,14 +778,14 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); - if ((o >= 0.f && o < 1.f) || _disableDepthTest) { + if ((o >= 0.f && o < 1.f) || !_enableDepthTest) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { setRenderBin(_originalRenderBin); } - bool shouldRenderTwice = !_disableFaceCulling && _geometry->isTransparent(); + bool shouldRenderTwice = _enableFaceCulling && _geometry->isTransparent(); int nPasses = shouldRenderTwice ? 2 : 1; for (int i = 0; i < nPasses; ++i) { if (shouldRenderTwice) { @@ -804,7 +804,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _geometry->render(*_program); } - if (_disableFaceCulling) { + if (!_enableFaceCulling) { glEnable(GL_CULL_FACE); } _program->deactivate(); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index ca84a6b61c..dae6d9709e 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -93,11 +93,11 @@ private: properties::FloatProperty _specularIntensity; properties::BoolProperty _performShading; - properties::BoolProperty _disableFaceCulling; + properties::BoolProperty _enableFaceCulling; properties::DMat4Property _modelTransform; properties::Vec3Property _rotationVec; - properties::BoolProperty _disableDepthTest; + properties::BoolProperty _enableDepthTest; properties::OptionProperty _blendingFuncOption; std::string _vertexShaderPath; From 87ed8c69c809b35f42000d748399fcce3ac89fac Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 5 Dec 2022 11:19:22 +0100 Subject: [PATCH 29/68] Simplyfy model opacity rendering --- modules/base/rendering/renderablemodel.cpp | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index bc1afd2ce7..31f4da292d 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -778,31 +778,14 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity const float o = opacity(); - if ((o >= 0.f && o < 1.f) || !_enableDepthTest) { + if ((o >= 0.f && o < 1.f) || !_enableDepthTest || _geometry->isTransparent()) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); } else { setRenderBin(_originalRenderBin); } - bool shouldRenderTwice = _enableFaceCulling && _geometry->isTransparent(); - int nPasses = shouldRenderTwice ? 2 : 1; - for (int i = 0; i < nPasses; ++i) { - if (shouldRenderTwice) { - glEnable(GL_CULL_FACE); - - if (i == 0) { - // First draw back faces (remove front faces) - glCullFace(GL_FRONT); - } - else { - // Then front faces (remove back faces) - glCullFace(GL_BACK); - } - } - - _geometry->render(*_program); - } + _geometry->render(*_program); if (!_enableFaceCulling) { glEnable(GL_CULL_FACE); From ee35aee5bb4abf11d0f1d6318209cfd33adb5ffc Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 5 Dec 2022 11:20:03 +0100 Subject: [PATCH 30/68] Remove PointsAndLines blend mode for models * Duplicate of deafult blend mode --- modules/base/rendering/renderablemodel.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 31f4da292d..255081f4d9 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -473,7 +473,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _blendingFuncOption.addOption(DefaultBlending, "Default"); _blendingFuncOption.addOption(AdditiveBlending, "Additive"); - _blendingFuncOption.addOption(PointsAndLinesBlending, "Points and Lines"); _blendingFuncOption.addOption(PolygonBlending, "Polygon"); _blendingFuncOption.addOption(ColorAddingBlending, "Color Adding"); @@ -741,6 +740,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); + // Configure blending glEnablei(GL_BLEND, 0); switch (_blendingFuncOption) { case DefaultBlending: @@ -749,9 +749,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { case AdditiveBlending: glBlendFunc(GL_ONE, GL_ONE); break; - case PointsAndLinesBlending: - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; case PolygonBlending: glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); break; From eafbb89e1e32cbcdcfa4fb7528083f111b9124f9 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 7 Dec 2022 09:58:03 +0100 Subject: [PATCH 31/68] Update ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index dab146e133..98975eff7e 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit dab146e133d651130b8ade6e7837ea9f898b696c +Subproject commit 98975eff7eeeef1719775721e3e044eb359ea157 From 560c58e499e43f0771fdab1a1f39e0585329d7e8 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 7 Dec 2022 14:19:12 +0100 Subject: [PATCH 32/68] Add manual depth test between models --- .../openspace/rendering/framebufferrenderer.h | 37 +++++++++++++++++++ modules/base/rendering/renderablemodel.cpp | 16 +++++++- modules/base/rendering/renderablemodel.h | 2 +- modules/base/shaders/model_fs.glsl | 17 +++++++-- modules/base/shaders/model_vs.glsl | 9 ++++- src/rendering/framebufferrenderer.cpp | 26 +++++++++++++ 6 files changed, 99 insertions(+), 8 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index c55eabdb81..8f26e871df 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -99,6 +99,43 @@ public: void initialize(); void deinitialize(); + // Functions to access the G-buffer textures + /** + * Gives access to the color texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the color texture of the G-buffer + */ + GLuint gBufferColorTexture(); + + /** + * Gives access to the position texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the position texture of the G-buffer + */ + GLuint gBufferPositionTexture(); + + /** + * Gives access to the normal texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the normal texture of the G-buffer + */ + GLuint gBufferNormalTexture(); + + /** + * Gives access to the depth texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the depth texture of the G-buffer + */ + GLuint gBufferDepthTexture(); + void updateResolution(); void updateRaycastData(); void updateDeferredcastData(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 255081f4d9..be274de216 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -77,11 +77,11 @@ namespace { "Enable or disable the animation for the model if it has any" }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", - "specularIntensity" + "specularIntensity", "gBufferDepthTexture" }; constexpr std::array UniformOpacityNames = { @@ -740,6 +740,18 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); + // Bind the G-buffer depth texture for a manual depth test for the second pass + ghoul::opengl::TextureUnit gBufferDepthTextureUnit; + gBufferDepthTextureUnit.activate(); + glBindTexture( + GL_TEXTURE_2D, + global::renderEngine->renderer()->gBufferDepthTexture() + ); + _program->setUniform( + _uniformCache.gBufferDepthTexture, + gBufferDepthTextureUnit + ); + // Configure blending glEnablei(GL_BLEND, 0); switch (_blendingFuncOption) { diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index dae6d9709e..e2bb8269ff 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -106,7 +106,7 @@ private: UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, - specularIntensity) _uniformCache; + specularIntensity, gBufferDepthTexture) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index b01219f0b6..dc9e4fd21f 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -25,6 +25,7 @@ #include "fragment.glsl" in vec2 vs_st; +in vec2 viewportPixelCoord; in vec3 vs_normalViewSpace; in vec4 vs_positionCameraSpace; in float vs_screenSpaceDepth; @@ -47,13 +48,23 @@ uniform vec4 color_specular; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; +uniform sampler2D gBufferDepthTexture; Fragment getFragment() { + Fragment frag; + + // Manual depth test + float gBufferDepth = + denormalizeFloat(texture(gBufferDepthTexture, viewportPixelCoord).x); + if (vs_screenSpaceDepth > gBufferDepth) { + frag.color = vec4(0.f); + frag.depth = gBufferDepth; + return frag; + } + // Render invisible mesh with flashy procedural material if (use_forced_color) { - Fragment frag; - vec3 adjustedPos = floor(vs_positionCameraSpace.xyz * 3.0); float chessboard = adjustedPos.x + adjustedPos.y + adjustedPos.z; chessboard = fract(chessboard * 0.5); @@ -78,8 +89,6 @@ Fragment getFragment() { diffuseAlbedo = color_diffuse; } - Fragment frag; - if (performShading) { vec3 specularAlbedo; if (has_texture_specular) { diff --git a/modules/base/shaders/model_vs.glsl b/modules/base/shaders/model_vs.glsl index b73c5c8c79..a5991e40a3 100644 --- a/modules/base/shaders/model_vs.glsl +++ b/modules/base/shaders/model_vs.glsl @@ -32,6 +32,7 @@ layout(location = 2) in vec3 in_normal; layout(location = 3) in vec3 in_tangent; out vec2 vs_st; +out vec2 viewportPixelCoord; out vec3 vs_normalViewSpace; out float vs_screenSpaceDepth; out vec4 vs_positionCameraSpace; @@ -53,7 +54,8 @@ void main() { vs_st = in_st; vs_screenSpaceDepth = positionScreenSpace.w; - vs_normalViewSpace = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); + vs_normalViewSpace = + normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); // TBN matrix for normal mapping vec3 T = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_tangent)); @@ -66,4 +68,9 @@ void main() { vec3 B = normalize(cross(N, T)); TBN = mat3(T, B, N); + + // Figure out the fragments position in the viewport + vec3 ndc = gl_Position.xyz / gl_Position.w; //perspective divide/normalize + vec2 viewportCoord = ndc.xy * 0.5 + 0.5; //ndc is -1 to 1 in GL. scale for 0 to 1 + viewportPixelCoord = viewportCoord; } diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index d7c9305823..c17a83f50d 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -87,6 +87,9 @@ namespace { namespace openspace { +//=====================================// +//===== Reuse NOT used textures =====// +//=====================================// // Gives access to the currently NOT used pingPongTexture GLuint FramebufferRenderer::additionalColorTexture1() { int unusedPingPongIndex = _pingPongIndex == 0 ? 1 : 0; @@ -108,6 +111,29 @@ GLuint FramebufferRenderer::additionalDepthTexture() { return _exitDepthTexture; } +//=========================================// +//===== Access to G-buffer textures =====// +//=========================================// +// Gives access to the color texture of the G-buffer +GLuint FramebufferRenderer::gBufferColorTexture() { + return _gBuffers.colorTexture; +} + +// Gives access to the position texture of the G-buffer +GLuint FramebufferRenderer::gBufferPositionTexture() { + return _gBuffers.positionTexture; +} + +// Gives access to the normal texture of the G-buffer +GLuint FramebufferRenderer::gBufferNormalTexture() { + return _gBuffers.normalTexture; +} + +// Gives access to the depth texture of the G-buffer +GLuint FramebufferRenderer::gBufferDepthTexture() { + return _gBuffers.depthTexture; +} + void FramebufferRenderer::initialize() { ZoneScoped TracyGpuZone("Rendering initialize"); From 04c83f03319a36f4ed00071a0172d19e4138d5ae Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 12 Dec 2022 09:52:32 +0100 Subject: [PATCH 33/68] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 98975eff7e..8e8bfe3b9d 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 98975eff7eeeef1719775721e3e044eb359ea157 +Subproject commit 8e8bfe3b9d2e6d9354e265efd01dd263a708ccf9 From 4d9983a867418bdfe667cb8602dcede1691a32fa Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Feb 2023 14:57:31 +0100 Subject: [PATCH 34/68] Solve 1 more conflict --- modules/base/rendering/renderablemodel.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 1796b72e1f..772b7dcc9b 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -65,7 +65,6 @@ namespace { { "Color Adding", ColorAddingBlending } }; -<<<<<<< HEAD const GLenum ColorAttachmentArray[3] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, @@ -80,10 +79,6 @@ namespace { constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", -======= - constexpr std::array UniformNames = { - "opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities", ->>>>>>> master "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", "specularIntensity", "gBufferDepthTexture" From 00e80139a25e0d3f2e1fc0b6d1cc6a940f96700b Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Feb 2023 16:07:42 +0100 Subject: [PATCH 35/68] Solve one more conflict --- modules/base/rendering/renderablemodel.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 772b7dcc9b..48ea505f51 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -71,12 +71,6 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { - "EnableAnimation", - "Enable Animation", - "Enable or disable the animation for the model if it has any" - }; - constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", From 14edda9e61f2d075211ff515054b1c59b10a7485 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Feb 2023 16:25:19 +0100 Subject: [PATCH 36/68] Remove problematic manual depth test code --- .../openspace/rendering/framebufferrenderer.h | 37 ------------------- modules/base/rendering/renderablemodel.cpp | 16 +------- modules/base/rendering/renderablemodel.h | 2 +- modules/base/shaders/model_fs.glsl | 10 ----- src/rendering/framebufferrenderer.cpp | 23 ------------ 5 files changed, 3 insertions(+), 85 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 77733f4750..a00684c0f5 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -99,43 +99,6 @@ public: void initialize(); void deinitialize(); - // Functions to access the G-buffer textures - /** - * Gives access to the color texture of the G-buffer. NOTE: This texture is used for - * the majority of rendering the scene and might be already in use. Use CAUTION when - * using this function. The size of the texture is the resolution of the viewport. - * - * \return GLuint identifier of the color texture of the G-buffer - */ - GLuint gBufferColorTexture(); - - /** - * Gives access to the position texture of the G-buffer. NOTE: This texture is used for - * the majority of rendering the scene and might be already in use. Use CAUTION when - * using this function. The size of the texture is the resolution of the viewport. - * - * \return GLuint identifier of the position texture of the G-buffer - */ - GLuint gBufferPositionTexture(); - - /** - * Gives access to the normal texture of the G-buffer. NOTE: This texture is used for - * the majority of rendering the scene and might be already in use. Use CAUTION when - * using this function. The size of the texture is the resolution of the viewport. - * - * \return GLuint identifier of the normal texture of the G-buffer - */ - GLuint gBufferNormalTexture(); - - /** - * Gives access to the depth texture of the G-buffer. NOTE: This texture is used for - * the majority of rendering the scene and might be already in use. Use CAUTION when - * using this function. The size of the texture is the resolution of the viewport. - * - * \return GLuint identifier of the depth texture of the G-buffer - */ - GLuint gBufferDepthTexture(); - void updateResolution(); void updateRaycastData(); void updateDeferredcastData(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 48ea505f51..ab4b2c093e 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -71,11 +71,11 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", - "specularIntensity", "gBufferDepthTexture" + "specularIntensity" }; constexpr std::array UniformOpacityNames = { @@ -740,18 +740,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); _program->setUniform(_uniformCache.performShading, _performShading); - // Bind the G-buffer depth texture for a manual depth test for the second pass - ghoul::opengl::TextureUnit gBufferDepthTextureUnit; - gBufferDepthTextureUnit.activate(); - glBindTexture( - GL_TEXTURE_2D, - global::renderEngine->renderer()->gBufferDepthTexture() - ); - _program->setUniform( - _uniformCache.gBufferDepthTexture, - gBufferDepthTextureUnit - ); - // Configure blending glEnablei(GL_BLEND, 0); switch (_blendingFuncOption) { diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index fd3fec6940..d61d3b91e9 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -106,7 +106,7 @@ private: UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, - specularIntensity, gBufferDepthTexture) _uniformCache; + specularIntensity) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index f333cebc09..8cc198a3aa 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -48,21 +48,11 @@ uniform vec4 color_specular; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; -uniform sampler2D gBufferDepthTexture; Fragment getFragment() { Fragment frag; - // Manual depth test - float gBufferDepth = - denormalizeFloat(texture(gBufferDepthTexture, viewportPixelCoord).x); - if (vs_screenSpaceDepth > gBufferDepth) { - frag.color = vec4(0.f); - frag.depth = gBufferDepth; - return frag; - } - // Render invisible mesh with flashy procedural material if (use_forced_color) { vec3 adjustedPos = floor(vs_positionCameraSpace.xyz * 3.0); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 2897d3699c..e12e7a55b8 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -111,29 +111,6 @@ GLuint FramebufferRenderer::additionalDepthTexture() { return _exitDepthTexture; } -//=========================================// -//===== Access to G-buffer textures =====// -//=========================================// -// Gives access to the color texture of the G-buffer -GLuint FramebufferRenderer::gBufferColorTexture() { - return _gBuffers.colorTexture; -} - -// Gives access to the position texture of the G-buffer -GLuint FramebufferRenderer::gBufferPositionTexture() { - return _gBuffers.positionTexture; -} - -// Gives access to the normal texture of the G-buffer -GLuint FramebufferRenderer::gBufferNormalTexture() { - return _gBuffers.normalTexture; -} - -// Gives access to the depth texture of the G-buffer -GLuint FramebufferRenderer::gBufferDepthTexture() { - return _gBuffers.depthTexture; -} - void FramebufferRenderer::initialize() { ZoneScoped TracyGpuZone("Rendering initialize"); From 7d2f781603b8fd35e4440343228f0b3270c37a60 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 8 Feb 2023 14:14:59 +0100 Subject: [PATCH 37/68] Only render with a two pass solution if the model is not opague --- ext/ghoul | 2 +- modules/base/rendering/renderablemodel.cpp | 197 +++++++++++---------- modules/base/shaders/model_fs.glsl | 23 +-- 3 files changed, 115 insertions(+), 107 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 804a1d7612..1e5da76b8e 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 804a1d76128c61462cc22e6e325248ce9bca37db +Subproject commit 1e5da76b8e79ab1e991ff4ae01ba1c253d5c60fa diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index ab4b2c093e..3995528983 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -681,112 +681,119 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { constexpr int res = 2880; const double maxDistance = res * boundingSphere() / tfov; - if (distanceToCamera < maxDistance) { - _program->activate(); + // Don't render if model is too far away + if (distanceToCamera >= maxDistance) { + return; + } - // Model transform and view transform needs to be in double precision - const glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * - glm::dmat4(data.modelTransform.rotation) * - glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * - glm::scale(_modelTransform.value(), glm::dvec3(_modelScale)); - const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * - modelTransform; + _program->activate(); - int nLightSources = 0; - _lightIntensitiesBuffer.resize(_lightSources.size()); - _lightDirectionsViewSpaceBuffer.resize(_lightSources.size()); - for (const std::unique_ptr& lightSource : _lightSources) { - if (!lightSource->isEnabled()) { - continue; - } - _lightIntensitiesBuffer[nLightSources] = lightSource->intensity(); - _lightDirectionsViewSpaceBuffer[nLightSources] = - lightSource->directionViewSpace(data); + // Model transform and view transform needs to be in double precision + const glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * + glm::scale(_modelTransform.value(), glm::dvec3(_modelScale)); + const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * + modelTransform; - ++nLightSources; + int nLightSources = 0; + _lightIntensitiesBuffer.resize(_lightSources.size()); + _lightDirectionsViewSpaceBuffer.resize(_lightSources.size()); + for (const std::unique_ptr& lightSource : _lightSources) { + if (!lightSource->isEnabled()) { + continue; } + _lightIntensitiesBuffer[nLightSources] = lightSource->intensity(); + _lightDirectionsViewSpaceBuffer[nLightSources] = + lightSource->directionViewSpace(data); - _program->setUniform( - _uniformCache.nLightSources, - nLightSources - ); - _program->setUniform( - _uniformCache.lightIntensities, - _lightIntensitiesBuffer - ); - _program->setUniform( - _uniformCache.lightDirectionsViewSpace, - _lightDirectionsViewSpaceBuffer - ); - _program->setUniform( - _uniformCache.modelViewTransform, - glm::mat4(modelViewTransform) - ); + ++nLightSources; + } - glm::dmat4 normalTransform = glm::transpose(glm::inverse(modelViewTransform)); + _program->setUniform( + _uniformCache.nLightSources, + nLightSources + ); + _program->setUniform( + _uniformCache.lightIntensities, + _lightIntensitiesBuffer + ); + _program->setUniform( + _uniformCache.lightDirectionsViewSpace, + _lightDirectionsViewSpaceBuffer + ); + _program->setUniform( + _uniformCache.modelViewTransform, + glm::mat4(modelViewTransform) + ); - _program->setUniform( - _uniformCache.normalTransform, - glm::mat4(normalTransform) - ); + glm::dmat4 normalTransform = glm::transpose(glm::inverse(modelViewTransform)); - _program->setUniform( - _uniformCache.projectionTransform, - data.camera.projectionMatrix() - ); - _program->setUniform(_uniformCache.ambientIntensity, _ambientIntensity); - _program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity); - _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); - _program->setUniform(_uniformCache.performShading, _performShading); + _program->setUniform( + _uniformCache.normalTransform, + glm::mat4(normalTransform) + ); - // Configure blending - glEnablei(GL_BLEND, 0); - switch (_blendingFuncOption) { - case DefaultBlending: - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case AdditiveBlending: - glBlendFunc(GL_ONE, GL_ONE); - break; - case PolygonBlending: - glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); - break; - case ColorAddingBlending: - glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR); - break; - }; + _program->setUniform( + _uniformCache.projectionTransform, + data.camera.projectionMatrix() + ); + _program->setUniform(_uniformCache.ambientIntensity, _ambientIntensity); + _program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity); + _program->setUniform(_uniformCache.specularIntensity, _specularIntensity); + _program->setUniform(_uniformCache.performShading, _performShading); - if (!_enableDepthTest) { - glDisable(GL_DEPTH_TEST); - } + if (!_enableFaceCulling) { + glDisable(GL_CULL_FACE); + } - if (!_enableFaceCulling) { - glDisable(GL_CULL_FACE); - } + // Configure blending + glEnablei(GL_BLEND, 0); + switch (_blendingFuncOption) { + case DefaultBlending: + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; + case AdditiveBlending: + glBlendFunc(GL_ONE, GL_ONE); + break; + case PolygonBlending: + glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); + break; + case ColorAddingBlending: + glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR); + break; + }; + if (!_enableDepthTest) { + glDisable(GL_DEPTH_TEST); + } + + // Only render two pass if the model is in any way transparent + bool shouldRenderTwise = false; + const float o = opacity(); + if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { + setRenderBin(Renderable::RenderBin::PostDeferredTransparent); + shouldRenderTwise = true; + } + else { + setRenderBin(_originalRenderBin); + } + + if (!shouldRenderTwise) { + _geometry->render(*_program); + } + else { // Prepare framebuffer GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); glDrawBuffers(3, ColorAttachmentArray); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f))); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity - const float o = opacity(); - if ((o >= 0.f && o < 1.f) || !_enableDepthTest || _geometry->isTransparent()) { - setRenderBin(Renderable::RenderBin::PostDeferredTransparent); - } - else { - setRenderBin(_originalRenderBin); - } - _geometry->render(*_program); - - if (!_enableFaceCulling) { - glEnable(GL_CULL_FACE); - } _program->deactivate(); // Render pass 2 @@ -818,7 +825,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { global::renderEngine->renderer()->additionalColorTexture2() ); _quadProgram->setUniform( - _uniformOpacityCache.positionTexture, + _uniformOpacityCache.positionTexture, positionTextureUnit ); @@ -842,12 +849,20 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glBindVertexArray(_quadVao); glDrawArrays(GL_TRIANGLES, 0, 6); _quadProgram->deactivate(); - - // Reset - global::renderEngine->openglStateCache().resetBlendState(); - global::renderEngine->openglStateCache().resetDepthState(); - glActiveTexture(GL_TEXTURE0); } + + // Reset + if (!_enableFaceCulling) { + glEnable(GL_CULL_FACE); + } + + if (!_enableDepthTest) { + glEnable(GL_DEPTH_TEST); + } + + global::renderEngine->openglStateCache().resetBlendState(); + global::renderEngine->openglStateCache().resetDepthState(); + glActiveTexture(GL_TEXTURE0); } void RenderableModel::update(const UpdateData& data) { diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 8cc198a3aa..62655cbd5d 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -49,9 +49,12 @@ uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; - Fragment getFragment() { Fragment frag; + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionCameraSpace; + frag.gNormal = vec4(vs_normalViewSpace, 0.0); + frag.disableLDR2HDR = true; // Render invisible mesh with flashy procedural material if (use_forced_color) { @@ -59,15 +62,10 @@ Fragment getFragment() { float chessboard = adjustedPos.x + adjustedPos.y + adjustedPos.z; chessboard = fract(chessboard * 0.5); chessboard *= 2; + // Pink and complementary green in a chessboard pattern frag.color.rgb = mix(vec3(1.0, 0.0, 0.8), vec3(0.0, 1.0, 0.2), chessboard); - frag.color.a = 1.0; - frag.depth = vs_screenSpaceDepth; - frag.gPosition = vs_positionCameraSpace; - frag.gNormal = vec4(vs_normalViewSpace, 0.0); - frag.disableLDR2HDR = true; - return frag; } @@ -120,11 +118,11 @@ Fragment getFragment() { const float specularPower = 100.0; vec3 diffuseColor = - diffuseIntensity * lightColor * diffuseAlbedo.rgb * max(diffuseCosineFactor, 0); + diffuseIntensity * lightColor * diffuseAlbedo.rgb * max(diffuseCosineFactor, 0); vec3 specularColor = - specularIntensity * lightColor * specularAlbedo * - pow(max(specularCosineFactor, 0), specularPower); + specularIntensity * lightColor * specularAlbedo * + pow(max(specularCosineFactor, 0), specularPower); color += lightIntensities[i] * (diffuseColor + specularColor); } @@ -135,10 +133,5 @@ Fragment getFragment() { } frag.color.a = diffuseAlbedo.a; - frag.depth = vs_screenSpaceDepth; - frag.gPosition = vs_positionCameraSpace; - frag.gNormal = vec4(vs_normalViewSpace, 0.0); - frag.disableLDR2HDR = true; - return frag; } From 108123704b68a2996291b07cd660bc5a218216ae Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 16 Feb 2023 11:40:39 +0100 Subject: [PATCH 38/68] Update ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 1e5da76b8e..da5cd5a795 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 1e5da76b8e79ab1e991ff4ae01ba1c253d5c60fa +Subproject commit da5cd5a7958febe1d0e5a1635f130cba4f174e3d From 11cc094e7d8e1c8e40e1897888e0419c5b3e9666 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 16 Feb 2023 16:24:02 +0100 Subject: [PATCH 39/68] Update Dawn model --- .../solarsystem/missions/dawn/dawn.asset | 117 ++++++++---------- 1 file changed, 53 insertions(+), 64 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/dawn/dawn.asset b/data/assets/scene/solarsystem/missions/dawn/dawn.asset index c805757412..d7571c2c92 100644 --- a/data/assets/scene/solarsystem/missions/dawn/dawn.asset +++ b/data/assets/scene/solarsystem/missions/dawn/dawn.asset @@ -1,6 +1,6 @@ local transforms = asset.require("scene/solarsystem/sun/transforms") local sun = asset.require("scene/solarsystem/sun/sun") - +local M_PI = 3.141592657 local kernels = asset.syncedResource({ Name = "Dawn Kernels", @@ -20,7 +20,7 @@ local models = asset.syncedResource({ Name = "Dawn Models", Type = "HttpSynchronization", Identifier = "dawn_model", - Version = 1 + Version = 2 }) local KernelFiles = { @@ -75,8 +75,8 @@ local LightSources = { } } -local Dawn = { - Identifier = "Dawn", +local DawnPosition = { + Identifier = "DawnPosition", Parent = transforms.SolarSystemBarycenter.Identifier, Transform = { Translation = { @@ -85,6 +85,23 @@ local Dawn = { Observer = "SSB", Kernels = KernelFiles }, + -- Rotation for model version 2 + Rotation = { + Type = "StaticRotation", + Rotation = { M_PI/2.0, 0, M_PI/2.0 } + } + }, + GUI = { + Name = "Dawn Position", + Path = "/Solar System/Missions/Dawn", + Hidden = true + } +} + +local Dawn = { + Identifier = "Dawn", + Parent = DawnPosition.Identifier, + Transform = { Rotation = { Type = "SpiceRotation", SourceFrame = "DAWN_SPACECRAFT", @@ -94,67 +111,11 @@ local Dawn = { }, Renderable = { Type = "RenderableModel", - Body = "DAWN", - GeometryFile = models .. "mainbodydawn.obj", + GeometryFile = models .. "Dawn_19.glb", LightSources = LightSources }, GUI = { - Path = "/Solar System/Missions/Dawn" - } -} - --- Dawn Solar Array module 1 -local DawnSolarArray1 = { - Identifier = "DawnSolar1", - Parent = Dawn.Identifier, - Transform = { - -- JCC: Spice rotations are commented because spice ck files - -- are not present. - -- Rotation = { - -- Type = "SpiceRotation", - -- SourceFrame = "DAWN_SA-Y", - -- DestinationFrame = "DAWN_SPACECRAFT" - -- } - Rotation = { - Type = "StaticRotation", - Rotation = { 0.0, 4.71225, 0.0 } - } - }, - Renderable = { - Type = "RenderableModel", - Body = "DAWN", - GeometryFile = models .. "solarpanelleft.obj", - LightSources = LightSources - }, - GUI = { - Name = "Dawn Solar 1", - Path = "/Solar System/Missions/Dawn" - } -} - --- Dawn Solar Array module 2 -local DawnSolarArray2 = { - Identifier = "DawnSolar2", - Parent = Dawn.Identifier, - Transform = { - -- Rotation = { - -- Type = "SpiceRotation", - -- SourceFrame = "DAWN_SA+Y", - -- DestinationFrame = "DAWN_SPACECRAFT" - -- } - Rotation = { - Type = "StaticRotation", - Rotation = { math.pi, math.pi/2, 0.0 } - } - }, - Renderable = { - Type = "RenderableModel", - Body = "DAWN", - GeometryFile = models .. "solarpanelright.obj", - LightSources = LightSources - }, - GUI = { - Name = "Dawn Solar 2", + Name = "Dawn", Path = "/Solar System/Missions/Dawn" } } @@ -228,10 +189,38 @@ local DawnFramingCamera2 = { } } +-- To make sure the size is correct +--[[local MeassureStick = { + Identifier = "MeassureStick", + Parent = DawnPosition.Identifier, + Renderable = { + Type = "RenderablePrism", + Segments = 16, + Lines = 16, + Radius = 0.855, + LineWidth = 1.0, + Color = { 1.0, 1.0, 1.0 }, + Length = 19.7 + }, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = { -9.85, 0, 0 } + }, + Rotation = { + Type = "StaticRotation", + Rotation = { 0, M_PI/2.0, 0 } + } + }, + GUI = { + Name = "MeassureStick", + Path = "/Solar System/Missions/Dawn", + } +}]] + local nodes = { + DawnPosition, Dawn, - DawnSolarArray1, - DawnSolarArray2, DawnTrail, DawnFramingCamera1, DawnFramingCamera2 From 17c7a3af19f8705dd5f0feda61bc81fe53c923ee Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 17 Feb 2023 08:30:57 +0100 Subject: [PATCH 40/68] Update ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index da5cd5a795..ed59700dbc 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit da5cd5a7958febe1d0e5a1635f130cba4f174e3d +Subproject commit ed59700dbc6d108553fb2a159faff05f8435c55d From 7484502db9a29facae098b1d605d816df51c4975 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 21 Feb 2023 11:29:51 +0100 Subject: [PATCH 41/68] Fix model "shadow" bug --- modules/base/rendering/renderabletrail.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 608709fb9c..bf6c830e62 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -437,6 +437,10 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { const double distance = glm::distance(trailPosWorld, data.camera.eyePositionVec3()); if (distance > _boundingSphere * DISTANCE_CULLING_RADII) { + // Reset + global::renderEngine->openglStateCache().resetBlendState(); + global::renderEngine->openglStateCache().resetDepthState(); + return; } @@ -471,8 +475,9 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { glBindVertexArray(0); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthMask(true); + // Reset + global::renderEngine->openglStateCache().resetBlendState(); + global::renderEngine->openglStateCache().resetDepthState(); _programObject->deactivate(); } From a877324c95264f1bbf5c184e312602c85d3ff522 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 21 Feb 2023 11:46:16 +0100 Subject: [PATCH 42/68] Make sure model rendering works with an odd number of atmospheres --- .../openspace/rendering/framebufferrenderer.h | 4 ++++ modules/base/rendering/renderablemodel.cpp | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index a00684c0f5..d9bbba53d8 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -65,6 +65,10 @@ public: * for all RenderBins. However, it cannot be used at the same time as the Deferred * Caster Tasks. The size of the texture is the resolution of the viewport. * + * NOTE (malej 2023-FEB-21): The currently NOT used pingPongTexture might change + * depending on where in the render cycle you are. Especially after the Deferred + * Caster Tasks. + * * \return GLuint identifier of the currently NOT used pingPongTexture */ GLuint additionalColorTexture1(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index bb65c1f07e..5a2c9f2ba0 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -624,7 +624,7 @@ void RenderableModel::initializeGL() { // Check status GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - LERROR("Framebuffer is not complete!"); + LERROR("Framebuffer is not complete"); } glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -787,6 +787,21 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Prepare framebuffer GLint defaultFBO = ghoul::opengl::FramebufferObject::getActiveObject(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); + + // Re-bind first texture to use the currently not used Ping-Pong texture in the + // FramebufferRenderer + glFramebufferTexture( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + global::renderEngine->renderer()->additionalColorTexture1(), + 0 + ); + // Check status + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + LERROR("Framebuffer is not complete"); + } + glDrawBuffers(3, ColorAttachmentArray); glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f))); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); From f6eac4f0c7fe1ede7dafdc96a370ca0dbe3dfe4d Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 21 Feb 2023 18:08:38 +0100 Subject: [PATCH 43/68] Take back manual depth test for the two pass model rendering --- .../openspace/rendering/framebufferrenderer.h | 44 ++++++++++++++++++- modules/base/rendering/renderablemodel.cpp | 30 ++++++++++++- modules/base/rendering/renderablemodel.h | 2 +- modules/base/shaders/model_fs.glsl | 13 ++++++ src/rendering/framebufferrenderer.cpp | 29 ++++++++++-- 5 files changed, 111 insertions(+), 7 deletions(-) diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index d9bbba53d8..32dd262d94 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -59,7 +59,9 @@ class FramebufferRenderer final : public RaycasterListener, public Deferredcaste public: virtual ~FramebufferRenderer() override = default; - // Functions to access and reuse some of the existing textures + //============================// + //===== Reuse textures =====// + //============================// /** * Gives access to the currently NOT used pingPongTexture. This texture is available * for all RenderBins. However, it cannot be used at the same time as the Deferred @@ -100,6 +102,46 @@ public: */ GLuint additionalDepthTexture(); + //=============================// + //===== Access G-buffer =====// + //=============================// + // Functions to access the G-buffer textures + /** + * Gives access to the color texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the color texture of the G-buffer + */ + GLuint gBufferColorTexture(); + + /** + * Gives access to the position texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the position texture of the G-buffer + */ + GLuint gBufferPositionTexture(); + + /** + * Gives access to the normal texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the normal texture of the G-buffer + */ + GLuint gBufferNormalTexture(); + + /** + * Gives access to the depth texture of the G-buffer. NOTE: This texture is used for + * the majority of rendering the scene and might be already in use. Use CAUTION when + * using this function. The size of the texture is the resolution of the viewport. + * + * \return GLuint identifier of the depth texture of the G-buffer + */ + GLuint gBufferDepthTexture(); + void initialize(); void deinitialize(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 5a2c9f2ba0..e6ce87a0eb 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -71,11 +71,11 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", - "specularIntensity" + "specularIntensity", "performManualDepthTest", "gBufferDepthTexture" }; constexpr std::array UniformOpacityNames = { @@ -781,6 +781,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { } if (!shouldRenderTwise) { + // Reset manual depth test + _program->setUniform( + _uniformCache.performManualDepthTest, + false + ); + _geometry->render(*_program); } else { @@ -806,6 +812,26 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f))); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // Use a manuel depth test to make the models aware of the rest of the envierment + _program->setUniform( + _uniformCache.performManualDepthTest, + true + ); + + // Bind the G-buffer depth texture for a manual depth test towards the rest + // of the scene + ghoul::opengl::TextureUnit gBufferDepthTextureUnit; + gBufferDepthTextureUnit.activate(); + glBindTexture( + GL_TEXTURE_2D, + global::renderEngine->renderer()->gBufferDepthTexture() + ); + _program->setUniform( + _uniformCache.gBufferDepthTexture, + gBufferDepthTextureUnit + ); + + // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity _geometry->render(*_program); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index d61d3b91e9..fc715201b0 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -106,7 +106,7 @@ private: UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, - specularIntensity) _uniformCache; + specularIntensity, performManualDepthTest, gBufferDepthTexture) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 62655cbd5d..bd0ef01bd5 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -48,6 +48,8 @@ uniform vec4 color_specular; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; +uniform bool performManualDepthTest = false; +uniform sampler2D gBufferDepthTexture; Fragment getFragment() { Fragment frag; @@ -56,6 +58,17 @@ Fragment getFragment() { frag.gNormal = vec4(vs_normalViewSpace, 0.0); frag.disableLDR2HDR = true; + if (performManualDepthTest) { + // Manual depth test + float gBufferDepth = + denormalizeFloat(texture(gBufferDepthTexture, viewportPixelCoord).x); + if (vs_screenSpaceDepth > gBufferDepth) { + frag.color = vec4(0.f); + frag.depth = gBufferDepth; + return frag; + } + } + // Render invisible mesh with flashy procedural material if (use_forced_color) { vec3 adjustedPos = floor(vs_positionCameraSpace.xyz * 3.0); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index e12e7a55b8..6228ab603c 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -87,9 +87,9 @@ namespace { namespace openspace { -//=====================================// -//===== Reuse NOT used textures =====// -//=====================================// +//============================// +//===== Reuse textures =====// +//============================// // Gives access to the currently NOT used pingPongTexture GLuint FramebufferRenderer::additionalColorTexture1() { int unusedPingPongIndex = _pingPongIndex == 0 ? 1 : 0; @@ -111,6 +111,29 @@ GLuint FramebufferRenderer::additionalDepthTexture() { return _exitDepthTexture; } +//=============================// +//===== Access G-buffer =====// +//=============================// +// / Gives access to the color texture of the G-buffer +GLuint FramebufferRenderer::gBufferColorTexture() { + return _gBuffers.colorTexture; +} + +// Gives access to the position texture of the G-buffer +GLuint FramebufferRenderer::gBufferPositionTexture() { + return _gBuffers.positionTexture; +} + +// Gives access to the normal texture of the G-buffer +GLuint FramebufferRenderer::gBufferNormalTexture() { + return _gBuffers.normalTexture; +} + +// Gives access to the depth texture of the G-buffer +GLuint FramebufferRenderer::gBufferDepthTexture() { + return _gBuffers.depthTexture; +} + void FramebufferRenderer::initialize() { ZoneScoped TracyGpuZone("Rendering initialize"); From bae8bbef3a0d44c2ec1f2036e177029c8afe8422 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 22 Feb 2023 14:50:55 +0100 Subject: [PATCH 44/68] Clean up some shader code --- modules/base/shaders/model_fs.glsl | 59 ++++++++++++++++-------------- modules/base/shaders/model_vs.glsl | 14 +++---- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index bd0ef01bd5..640f74dbf2 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -25,11 +25,11 @@ #include "fragment.glsl" in vec2 vs_st; -in vec2 viewportPixelCoord; +in vec2 vs_viewportPixelCoord; in vec3 vs_normalViewSpace; in vec4 vs_positionCameraSpace; in float vs_screenSpaceDepth; -in mat3 TBN; +in mat3 vs_TBN; uniform float ambientIntensity = 0.2; uniform float diffuseIntensity = 1.0; @@ -57,13 +57,14 @@ Fragment getFragment() { frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); frag.disableLDR2HDR = true; + frag.color.a = 1.0; if (performManualDepthTest) { // Manual depth test float gBufferDepth = - denormalizeFloat(texture(gBufferDepthTexture, viewportPixelCoord).x); + denormalizeFloat(texture(gBufferDepthTexture, vs_viewportPixelCoord).x); if (vs_screenSpaceDepth > gBufferDepth) { - frag.color = vec4(0.f); + frag.color = vec4(0.0); frag.depth = gBufferDepth; return frag; } @@ -78,10 +79,10 @@ Fragment getFragment() { // Pink and complementary green in a chessboard pattern frag.color.rgb = mix(vec3(1.0, 0.0, 0.8), vec3(0.0, 1.0, 0.2), chessboard); - frag.color.a = 1.0; return frag; } + // Base color vec4 diffuseAlbedo; if (has_texture_diffuse) { diffuseAlbedo = texture(texture_diffuse, vs_st); @@ -91,55 +92,57 @@ Fragment getFragment() { } if (performShading) { + // Specular color vec3 specularAlbedo; if (has_texture_specular) { specularAlbedo = texture(texture_specular, vs_st).rgb; } else { if (has_color_specular) { - specularAlbedo = color_specular.rgb ; + specularAlbedo = color_specular.rgb; } else { - specularAlbedo = vec3(1.0); + specularAlbedo = diffuseAlbedo.rgb; } } - // Some of these values could be passed in as uniforms - const vec3 lightColorAmbient = vec3(1.0); - const vec3 lightColor = vec3(1.0); - - vec3 n; + // Bumb mapping + vec3 normal; if (has_texture_normal) { vec3 normalAlbedo = texture(texture_normal, vs_st).rgb; normalAlbedo = normalize(normalAlbedo * 2.0 - 1.0); - n = normalize(TBN * normalAlbedo); + normal = normalize(vs_TBN * normalAlbedo); } else { - n = normalize(vs_normalViewSpace); + normal = normalize(vs_normalViewSpace); } - vec3 c = normalize(vs_positionCameraSpace.xyz); + // Could be seperated into ambinet, diffuse and specular and passed in as uniforms + const vec3 lightColor = vec3(1.0); + const float specularPower = 100.0; - vec3 color = ambientIntensity * lightColorAmbient * diffuseAlbedo.rgb; + // Ambient light + vec3 totalLightColor = ambientIntensity * lightColor * diffuseAlbedo.rgb; + + vec3 viewDirection = normalize(vs_positionCameraSpace.xyz); for (int i = 0; i < nLightSources; ++i) { - vec3 l = lightDirectionsViewSpace[i]; - vec3 r = reflect(l, n); - - float diffuseCosineFactor = dot(n,l); - float specularCosineFactor = dot(c,r); - const float specularPower = 100.0; - + // Diffuse light + vec3 lightDirection = lightDirectionsViewSpace[i]; + float diffuseFactor = max(dot(normal, lightDirection), 0.0); vec3 diffuseColor = - diffuseIntensity * lightColor * diffuseAlbedo.rgb * max(diffuseCosineFactor, 0); + diffuseIntensity * lightColor * diffuseFactor * diffuseAlbedo.rgb; + // Specular light + vec3 reflectDirection = reflect(lightDirection, normal); + float specularFactor = + pow(max(dot(viewDirection, reflectDirection), 0.0), specularPower); vec3 specularColor = - specularIntensity * lightColor * specularAlbedo * - pow(max(specularCosineFactor, 0), specularPower); + specularIntensity * lightColor * specularFactor * specularAlbedo; - color += lightIntensities[i] * (diffuseColor + specularColor); + totalLightColor += lightIntensities[i] * (diffuseColor + specularColor); } - frag.color.rgb = color; + frag.color.rgb = totalLightColor; } else { frag.color.rgb = diffuseAlbedo.rgb; diff --git a/modules/base/shaders/model_vs.glsl b/modules/base/shaders/model_vs.glsl index c809cf1827..d100ed7c7d 100644 --- a/modules/base/shaders/model_vs.glsl +++ b/modules/base/shaders/model_vs.glsl @@ -32,11 +32,11 @@ layout(location = 2) in vec3 in_normal; layout(location = 3) in vec3 in_tangent; out vec2 vs_st; -out vec2 viewportPixelCoord; +out vec2 vs_viewportPixelCoord; out vec3 vs_normalViewSpace; out float vs_screenSpaceDepth; out vec4 vs_positionCameraSpace; -out mat3 TBN; +out mat3 vs_TBN; uniform mat4 modelViewTransform; uniform mat4 projectionTransform; @@ -67,10 +67,10 @@ void main() { // Retrieve perpendicular vector B with cross product of T and N vec3 B = normalize(cross(N, T)); - TBN = mat3(T, B, N); + vs_TBN = mat3(T, B, N); - // Figure out the fragments position in the viewport - vec3 ndc = gl_Position.xyz / gl_Position.w; //perspective divide/normalize - vec2 viewportCoord = ndc.xy * 0.5 + 0.5; //ndc is -1 to 1 in GL. scale for 0 to 1 - viewportPixelCoord = viewportCoord; + // Figure out the fragment's position in the viewport + vec3 ndc = gl_Position.xyz / gl_Position.w; // perspective divide/normalize + vec2 viewportCoord = ndc.xy * 0.5 + 0.5; // ndc is -1 to 1 in GL. scale for 0 to 1 + vs_viewportPixelCoord = viewportCoord; } From 74aa8a94163fc495a1699417446ec55f718da9c2 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 23 Feb 2023 10:58:12 +0100 Subject: [PATCH 45/68] Fix model projection to work with new opacity setup --- .../rendering/renderablemodelprojection.cpp | 10 +++- .../rendering/renderablemodelprojection.h | 7 ++- .../shaders/renderableModel_fs.glsl | 55 +++++++++++-------- .../shaders/renderableModel_vs.glsl | 1 - 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 7c71dbf15e..684dff630d 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -38,9 +38,11 @@ #include namespace { - constexpr std::array MainUniformNames = { - "performShading", "directionToSunViewSpace", "modelViewTransform", - "projectionTransform", "projectionFading", "baseTexture", "projectionTexture" + constexpr std::array MainUniformNames = { + "modelViewTransform", "projectionTransform", "meshTransform", + "meshNormalTransform", "has_texture_diffuse", "baseTexture", "baseColor", + "projectionTexture", "performShading", "projectionFading", + "directionToSunViewSpace" }; constexpr std::array FboUniformNames = { @@ -224,6 +226,8 @@ void RenderableModelProjection::render(const RenderData& data, RendererTasks&) { glm::dmat4(data.modelTransform.rotation) * glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * transform; + + // malej 2023-FEB-23: The light sources should probably not be hard coded const glm::vec3 directionToSun = glm::normalize(_sunPosition - bodyPos); const glm::vec3 directionToSunViewSpace = glm::normalize( glm::mat3(data.camera.combinedViewMatrix()) * directionToSun diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h index 9b6cca43d8..a9576ec13a 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h @@ -73,9 +73,10 @@ private: ProjectionComponent _projectionComponent; std::unique_ptr _programObject; - UniformCache(performShading, directionToSunViewSpace, modelViewTransform, - projectionTransform, projectionFading, baseTexture, - projectionTexture) _mainUniformCache; + UniformCache(modelViewTransform, projectionTransform, meshTransform, + meshNormalTransform, has_texture_diffuse, baseTexture, baseColor, + projectionTexture, performShading, projectionFading, + directionToSunViewSpace) _mainUniformCache; std::unique_ptr _fboProgramObject; UniformCache(projectionTexture, depthTexture, needShadowMap, ProjectorMatrix, diff --git a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl index 2a9fd56ccc..cf155e390d 100644 --- a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl +++ b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl @@ -32,7 +32,7 @@ in vec4 vs_positionCameraSpace; uniform bool has_texture_diffuse; uniform sampler2D baseTexture; -uniform vec3 baseColor; +uniform vec4 baseColor; uniform sampler2D projectionTexture; uniform bool performShading; uniform float projectionFading; @@ -47,13 +47,23 @@ const float specularPower = 100.0; Fragment getFragment() { + Fragment frag; + frag.depth = vs_depth; + frag.gPosition = vs_positionCameraSpace; + frag.gNormal = vec4(vs_normalViewSpace, 0.0); + frag.disableLDR2HDR = true; + frag.color.a = 1.0; + + // Base color vec4 textureColor; if (has_texture_diffuse) { - textureColor = texture(baseTexture, vs_st); + textureColor = texture(baseTexture, vs_st); } else { - textureColor = vec4(baseColor, 1.0); + textureColor = vec4(baseColor.rgb, 1.0); } + + // Mix base color with the projection images vec4 projectionColor = texture(projectionTexture, vs_st); if (projectionColor.a > 0.0) { textureColor.rgb = mix( @@ -62,37 +72,38 @@ Fragment getFragment() { projectionFading * projectionColor.a ); } - + vec3 diffuseAlbedo = textureColor.rgb; - Fragment frag; if (performShading) { - // Some of these values could be passed in as uniforms - const vec3 lightColorAmbient = vec3(1.0); + // Could be seperated into ambinet, diffuse and specular and passed in as uniforms const vec3 lightColor = vec3(1.0); - - vec3 n = normalize(vs_normalViewSpace); - vec3 l = directionToSunViewSpace; - vec3 c = normalize(vs_positionCameraSpace.xyz); - vec3 r = reflect(l, n); + const float specularPower = 100.0; - float diffuseCosineFactor = dot(n,l); - float specularCosineFactor = dot(c,r); + // Ambient light + vec3 ambientColor = ambientIntensity * lightColor * diffuseAlbedo; - vec3 ambientColor = ambientIntensity * lightColorAmbient * diffuseAlbedo; - vec3 diffuseColor = - diffuseIntensity * lightColor * diffuseAlbedo * max(diffuseCosineFactor, 0.0); - vec3 specularColor = specularIntensity * lightColor * specularAlbedo * - pow(max(specularCosineFactor, 0.0), specularPower); + // Diffuse light + vec3 normal = normalize(vs_normalViewSpace); + vec3 lightDirection = directionToSunViewSpace; + float diffuseFactor = max(dot(normal, lightDirection), 0.0); + vec3 diffuseColor = + diffuseIntensity * lightColor * diffuseFactor * diffuseAlbedo; + // Specular light + vec3 viewDirection = normalize(vs_positionCameraSpace.xyz); + vec3 reflectDirection = reflect(lightDirection, normal); + float specularFactor = + pow(max(dot(viewDirection, reflectDirection), 0.0), specularPower); + vec3 specularColor = + specularIntensity * lightColor * specularFactor * specularAlbedo; + + // Total light frag.color.rgb = ambientColor + diffuseColor + specularColor; } else { frag.color.rgb = diffuseAlbedo; } - frag.color.a = 1.0; - frag.depth = vs_depth; - // frag.depth = 0.0; return frag; } diff --git a/modules/spacecraftinstruments/shaders/renderableModel_vs.glsl b/modules/spacecraftinstruments/shaders/renderableModel_vs.glsl index dcf4cf3b7a..46e924c269 100644 --- a/modules/spacecraftinstruments/shaders/renderableModel_vs.glsl +++ b/modules/spacecraftinstruments/shaders/renderableModel_vs.glsl @@ -37,7 +37,6 @@ out vec4 vs_positionCameraSpace; uniform mat4 modelViewTransform; uniform mat4 projectionTransform; -uniform vec3 cameraDirectionWorldSpace; uniform mat4 meshTransform; uniform mat4 meshNormalTransform; From 06db9b3ce91ee35611c4139637b457c89414c58e Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 23 Feb 2023 11:05:44 +0100 Subject: [PATCH 46/68] Add model scale and debug invisible feature to model projection --- modules/base/rendering/renderablemodel.cpp | 1 + modules/base/rendering/renderablemodel.h | 1 - .../rendering/renderablemodelprojection.cpp | 85 ++++++++++++++++++- .../rendering/renderablemodelprojection.h | 5 ++ 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index e6ce87a0eb..02b712f622 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index fc715201b0..0ef9d8041f 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 684dff630d..5acf6ecefd 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,38 @@ namespace { // This specifies the model that is rendered by the Renderable. std::filesystem::path geometryFile; + enum class [[codegen::map(openspace::DistanceUnit)]] ScaleUnit { + Nanometer, + Micrometer, + Millimeter, + Centimeter, + Decimeter, + Meter, + Kilometer, + + // Weird units + Thou, + Inch, + Foot, + Yard, + Chain, + Furlong, + Mile + }; + + // The scale of the model. For example if the model is in centimeters + // then ModelScale = Centimeter or ModelScale = 0.01 + std::optional> modelScale; + + // By default the given ModelScale is used to scale the model down, + // by setting this setting to true the model is instead scaled up with the + // given ModelScale + std::optional invertModelScale; + + // Set if invisible parts (parts with no textures or materials) of the model + // should be forced to render or not. + std::optional forceRenderInvisible; + // Contains information about projecting onto this planet. ghoul::Dictionary projection [[codegen::reference("spacecraftinstruments_projectioncomponent")]]; @@ -97,18 +130,52 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di { const Parameters p = codegen::bake(dictionary); + if (p.forceRenderInvisible.has_value()) { + _forceRenderInvisible = *p.forceRenderInvisible; + + if (!_forceRenderInvisible) { + // Asset file have specifically said to not render invisible parts, + // do not notify in the log if invisible parts are detected and dropped + _notifyInvisibleDropped = false; + } + } + std::filesystem::path file = absPath(p.geometryFile.string()); _geometry = ghoul::io::ModelReader::ref().loadModel( file.string(), - ghoul::io::ModelReader::ForceRenderInvisible::No, - ghoul::io::ModelReader::NotifyInvisibleDropped::Yes + ghoul::io::ModelReader::ForceRenderInvisible(_forceRenderInvisible), + ghoul::io::ModelReader::NotifyInvisibleDropped(_notifyInvisibleDropped) ); + _invertModelScale = p.invertModelScale.value_or(_invertModelScale); + + if (p.modelScale.has_value()) { + if (std::holds_alternative(*p.modelScale)) { + Parameters::ScaleUnit scaleUnit = + std::get(*p.modelScale); + DistanceUnit distanceUnit = codegen::map(scaleUnit); + _modelScale = toMeter(distanceUnit); + } + else if (std::holds_alternative(*p.modelScale)) { + _modelScale = std::get(*p.modelScale); + } + else { + throw ghoul::MissingCaseException(); + } + + if (_invertModelScale) { + _modelScale = 1.0 / _modelScale; + } + } + addPropertySubOwner(_projectionComponent); _projectionComponent.initialize(identifier(), p.projection); - double boundingSphereRadius = p.boundingSphereRadius.value_or(1.0e9); - setBoundingSphere(boundingSphereRadius); + if (p.boundingSphereRadius.has_value()) { + _shouldOverrideBoundingSphere = true; + double boundingSphereRadius = p.boundingSphereRadius.value(); + setBoundingSphere(boundingSphereRadius); + } _performShading = p.performShading.value_or(_performShading); addProperty(_performShading); @@ -186,6 +253,16 @@ ghoul::opengl::Texture& RenderableModelProjection::baseTexture() const { } void RenderableModelProjection::render(const RenderData& data, RendererTasks&) { + // Update boundingsphere + if (!_shouldOverrideBoundingSphere) { + setBoundingSphere(_geometry->boundingRadius() * _modelScale * + glm::compMax(data.modelTransform.scale) + ); + + // Set Interaction sphere size to be 10% of the bounding sphere + setInteractionSphere(_boundingSphere * 0.1); + } + if (_projectionComponent.needsClearProjection()) { _projectionComponent.clearAllProjections(); } diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h index a9576ec13a..420d0eaaac 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h @@ -85,6 +85,11 @@ private: UniformCache(ProjectorMatrix, ModelTransform) _depthFboUniformCache; std::unique_ptr _geometry; + bool _shouldOverrideBoundingSphere = false; + double _modelScale = 1.0; + bool _invertModelScale = false; + bool _forceRenderInvisible = false; + bool _notifyInvisibleDropped = true; glm::dmat3 _instrumentMatrix = glm::dmat3(1.0); From d6e6f6a2562a2abd9586e2d2c630b61ed2871f3f Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 23 Feb 2023 13:42:58 +0100 Subject: [PATCH 47/68] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index ed59700dbc..0804c39f94 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit ed59700dbc6d108553fb2a159faff05f8435c55d +Subproject commit 0804c39f94bb2c3ce32979e15d08c6d9c12cfdd4 From e3a0918e7c3f7532ea5e2ae9cad33a1245ad44b4 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 27 Feb 2023 14:51:11 +0100 Subject: [PATCH 48/68] Update Rosetta model --- .../solarsystem/missions/dawn/dawn.asset | 3 +- .../missions/rosetta/rosetta.asset | 347 ++---------------- 2 files changed, 39 insertions(+), 311 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/dawn/dawn.asset b/data/assets/scene/solarsystem/missions/dawn/dawn.asset index d7571c2c92..b175fbf311 100644 --- a/data/assets/scene/solarsystem/missions/dawn/dawn.asset +++ b/data/assets/scene/solarsystem/missions/dawn/dawn.asset @@ -88,7 +88,7 @@ local DawnPosition = { -- Rotation for model version 2 Rotation = { Type = "StaticRotation", - Rotation = { M_PI/2.0, 0, M_PI/2.0 } + Rotation = { M_PI/2.0, 0.0, M_PI/2.0 } } }, GUI = { @@ -219,6 +219,7 @@ local DawnFramingCamera2 = { }]] local nodes = { + --MeassureStick, DawnPosition, Dawn, DawnTrail, diff --git a/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset b/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset index e0fa4248cf..fb015cf949 100644 --- a/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset +++ b/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset @@ -1,12 +1,13 @@ local sun = asset.require("scene/solarsystem/sun/sun") local sunTransforms = asset.require("scene/solarsystem/sun/transforms") local transforms = asset.require("./67p") +local M_PI = 3.141592657 local models = asset.syncedResource({ Name = "Rosetta Models", Type = "HttpSynchronization", Identifier = "rosetta_model", - Version = 4 + Version = 5 }) local kernels = asset.syncedResource({ @@ -71,8 +72,8 @@ local RotationMatrix = { 1, 0, 0 } -local Rosetta = { - Identifier = "Rosetta", +local RosettaPosition = { + Identifier = "RosettaPosition", Parent = sunTransforms.SolarSystemBarycenter.Identifier, Transform = { Translation = { @@ -88,33 +89,24 @@ local Rosetta = { } }, GUI = { - Path = "/Solar System/Missions/Rosetta" + Name = "Rosetta Position", + Path = "/Solar System/Missions/Rosetta", + Hidden = true } } -local RosettaModel = { - Identifier = "RosettaModel", - Parent = Rosetta.Identifier, +local Rosetta = { + Identifier = "Rosetta", + Parent = RosettaPosition.Identifier, Transform = { - Scale = { - Type = "StaticScale", - -- The scale of the model is in cm; OpenSpace is in m - Scale = 0.01 + Rotation = { + Type = "StaticRotation", + Rotation = { 0.0, M_PI/2.0, 0.0 } } }, - GUI = { - Name = "Rosetta Model", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaBlackFoil = { - Identifier = "Rosetta_black_foil", - Parent = RosettaModel.Identifier, Renderable = { Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "black_foil.obj", + GeometryFile = models .. "rosetta.glb", ModelTransform = RotationMatrix, LightSources = { sun.LightSource, @@ -126,200 +118,15 @@ local RosettaBlackFoil = { } }, GUI = { - Name = "Rosetta Model Part Black Foil", + Name = "Rosetta", Path = "/Solar System/Missions/Rosetta" } } -local RosettaBlackParts = { - Identifier = "Rosetta_black_parts", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "black_parts.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Black Parts", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaDish = { - Identifier = "Rosetta_dish", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "dish.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Dish", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaParts = { - Identifier = "Rosetta_parts", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "parts.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Parts", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaSilverFoil = { - Identifier = "Rosetta_silver_foil", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "silver_foil.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Silver Foil", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaVents = { - Identifier = "Rosetta_vents", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "vents.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Vents", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaWingA = { - Identifier = "Rosetta_wing_a", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .."wingA.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Wing A", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaWingB = { - Identifier = "Rosetta_wing_b", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "wingB.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Wing B", - Path = "/Solar System/Missions/Rosetta" - } -} - -local RosettaYellowFoil = { - Identifier = "Rosetta_yellow_foil", - Parent = RosettaModel.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "yellow_foil.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Rosetta Model Part Yellow Foil", - Path = "/Solar System/Missions/Rosetta" - } -} - -local Philae = { - Identifier = "Philae", +local PhilaePosition = { + Identifier = "PhilaePosition", Parent = transforms.Barycenter.Identifier, - -- This should need a transform, but currently the model is intrinsically - -- translated + -- This should need a transform, but currently the model containes it instead Transform = { Translation = { Type = "SpiceTranslation", @@ -331,26 +138,27 @@ local Philae = { Type = "SpiceRotation", SourceFrame = "ROS_SPACECRAFT", DestinationFrame = "GALACTIC", - }, - Scale = { - Type = "StaticScale", - -- The scale of the model is in cm; OpenSpace is in m - Scale = 0.01 } }, GUI = { - Name = "Philae Model", - Path = "/Solar System/Missions/Rosetta" + Name = "Philae Position", + Path = "/Solar System/Missions/Rosetta", + Hidden = true } } -local PhilaeFoil = { - Identifier = "Philae_foil", - Parent = Philae.Identifier, +local Philae = { + Identifier = "Philae", + Parent = PhilaePosition.Identifier, + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = { 0.0, M_PI/2.0, 0.0 } + } + }, Renderable = { Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "lander_foil.obj", + GeometryFile = models .. "lander.glb", ModelTransform = RotationMatrix, LightSources = { sun.LightSource, @@ -362,83 +170,14 @@ local PhilaeFoil = { } }, GUI = { - Name = "Philae Model Part Foil", - Path = "/Solar System/Missions/Rosetta" - } -} - -local PhilaeLids = { - Identifier = "Philae_lids", - Parent = Philae.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "lander_lids.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Philae Model Part Lids", - Path = "/Solar System/Missions/Rosetta" - } -} - -local PhilaeParts = { - Identifier = "Philae_parts", - Parent = Philae.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "lander_parts.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Philae Model Part Parts", - Path = "/Solar System/Missions/Rosetta" - } -} - -local PhilaeSolarPanels = { - Identifier = "Philae_solarp", - Parent = Philae.Identifier, - Renderable = { - Type = "RenderableModel", - Body = "ROSETTA", - GeometryFile = models .. "lander_solarp.obj", - ModelTransform = RotationMatrix, - LightSources = { - sun.LightSource, - { - Identifier = "Camera", - Type = "CameraLightSource", - Intensity = 0.5 - } - } - }, - GUI = { - Name = "Philae Model Parts Solar Panels", + Name = "Philae", Path = "/Solar System/Missions/Rosetta" } } local NavCam = { Identifier = "NAVCAM", - Parent = Rosetta.Identifier, + Parent = RosettaPosition.Identifier, GUI = { Path = "/Solar System/Missions/Rosetta/Instruments" } @@ -529,28 +268,16 @@ local PhilaeTrail = { } local nodes = { + RosettaPosition, Rosetta, - RosettaModel, - RosettaBlackFoil, - RosettaBlackParts, - RosettaDish, - RosettaParts, - RosettaSilverFoil, - RosettaVents, - RosettaWingA, - RosettaWingB, - RosettaYellowFoil, + + PhilaePosition, + Philae, NavCam, NavCamFov, ImagePlane, - Philae, - PhilaeFoil, - PhilaeLids, - PhilaeParts, - PhilaeSolarPanels, - RosettaCometTrail, PhilaeTrail } From bc647e8f23608dcb34cef04bc72c8e861afa3070 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Mar 2023 17:31:10 +0100 Subject: [PATCH 49/68] Some model asset files clean up --- data/assets/examples/approachevents.asset | 6 ++++-- data/assets/examples/globerotation.asset | 7 +++++-- data/assets/examples/globetranslation.asset | 13 +++++++++---- .../missions/apollo/8/launch_model.asset | 2 +- .../scene/solarsystem/missions/apollo/8/model.asset | 6 +++--- .../solarsystem/missions/apollo/8/trails.asset | 6 +++--- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/data/assets/examples/approachevents.asset b/data/assets/examples/approachevents.asset index 3f69a0e350..4e99e963d3 100644 --- a/data/assets/examples/approachevents.asset +++ b/data/assets/examples/approachevents.asset @@ -32,14 +32,16 @@ local obj = { Renderable = { Type = "RenderableModel", GeometryFile = model .. "BoxAnimated.glb", - ModelScale = 1.0, + ModelScale = 1000, LightSources = { sun.LightSource }, PerformShading = true, EnableFaceCulling = true }, - InteractionSphere = 1000.0, + InteractionSphere = 900, + ApproachFactor = 50.0, + ReachFactor = 5.0, OnApproach = { "os.example.generic" }, OnReach = { "os.example.generic" }, OnRecede = { "os.example.generic" }, diff --git a/data/assets/examples/globerotation.asset b/data/assets/examples/globerotation.asset index 4ada35e386..b1aaec3951 100644 --- a/data/assets/examples/globerotation.asset +++ b/data/assets/examples/globerotation.asset @@ -1,3 +1,4 @@ +local sun = asset.require("scene/solarsystem/sun/sun") local earth = asset.require("scene/solarsystem/planets/earth/earth") local sunTransforms = asset.require("scene/solarsystem/sun/transforms") @@ -35,8 +36,10 @@ local Example_GlobeRotation = { }, Renderable = { Type = "RenderableModel", - Body = "NEW HORIZONS", - GeometryFile = models .. "NewHorizonsCleanModel.obj" + GeometryFile = models .. "NewHorizonsCleanModel.obj", + LightSources = { + sun.LightSource + } }, GUI = { Path = "/Example" diff --git a/data/assets/examples/globetranslation.asset b/data/assets/examples/globetranslation.asset index 2150c723d6..9421c0e9c5 100644 --- a/data/assets/examples/globetranslation.asset +++ b/data/assets/examples/globetranslation.asset @@ -1,3 +1,4 @@ +local sun = asset.require("scene/solarsystem/sun/sun") local earth = asset.require("scene/solarsystem/planets/earth/earth") local sunTransforms = asset.require("scene/solarsystem/sun/transforms") @@ -22,8 +23,10 @@ local Example_Fixed_Height = { }, Renderable = { Type = "RenderableModel", - Body = "NEW HORIZONS", - GeometryFile = models .. "NewHorizonsCleanModel.obj" + GeometryFile = models .. "NewHorizonsCleanModel.obj", + LightSources = { + sun.LightSource + } }, GUI = { Path = "/Example" @@ -44,8 +47,10 @@ local Example_Adaptive_Height = { }, Renderable = { Type = "RenderableModel", - Body = "NEW HORIZONS", - GeometryFile = models .. "NewHorizonsCleanModel.obj" + GeometryFile = models .. "NewHorizonsCleanModel.obj", + LightSources = { + sun.LightSource + } }, GUI = { Path = "/Example" diff --git a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset index 946b72ad4f..5760d52161 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset @@ -30,7 +30,7 @@ local Apollo8Launch = { }, GUI = { Name = "Apollo 8 Launch Capsule", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } diff --git a/data/assets/scene/solarsystem/missions/apollo/8/model.asset b/data/assets/scene/solarsystem/missions/apollo/8/model.asset index 3f941633c7..740d4efb6e 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/model.asset @@ -42,7 +42,7 @@ local Apollo8 = { }, GUI = { Name = "Apollo 8", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } @@ -73,7 +73,7 @@ local Apollo8Model = { GUI = { Hidden = true, Name = "Apollo 8 Model", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } @@ -89,7 +89,7 @@ local Apollo8Pivot = { }, GUI = { Name = "Apollo 8 Pivot", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } diff --git a/data/assets/scene/solarsystem/missions/apollo/8/trails.asset b/data/assets/scene/solarsystem/missions/apollo/8/trails.asset index 6bc4398bef..d8d24ce58b 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/trails.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/trails.asset @@ -25,7 +25,7 @@ local LaunchTrail = { }, GUI = { Name = "Apollo 8 Launch Trail", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } @@ -49,7 +49,7 @@ local MoonTrail = { }, GUI = { Name = "Apollo 8 Moon Trail", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } @@ -73,7 +73,7 @@ local EarthBarycenterTrail = { }, GUI = { Name = "Apollo 8 Earth Barycenter Trail", - Path = "/Solar System/Missions/Apollo" + Path = "/Solar System/Missions/Apollo/8" } } From 5a6ac848f9cecac172948e04d523be59d958f03e Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Mar 2023 17:31:48 +0100 Subject: [PATCH 50/68] Make possible to disable manual depth test in opacity mode --- modules/base/rendering/renderablemodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 02b712f622..7ffd74c943 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -816,7 +816,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Use a manuel depth test to make the models aware of the rest of the envierment _program->setUniform( _uniformCache.performManualDepthTest, - true + _enableDepthTest ); // Bind the G-buffer depth texture for a manual depth test towards the rest From 896ca0f108d8d807d9c2decf9ea666c34912744a Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 1 Mar 2023 17:33:26 +0100 Subject: [PATCH 51/68] Make debug texture prettier --- modules/base/shaders/model_fs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 640f74dbf2..cfe1b02702 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -72,7 +72,7 @@ Fragment getFragment() { // Render invisible mesh with flashy procedural material if (use_forced_color) { - vec3 adjustedPos = floor(vs_positionCameraSpace.xyz * 3.0); + vec3 adjustedPos = floor(vs_positionCameraSpace.xyz / 500.0); float chessboard = adjustedPos.x + adjustedPos.y + adjustedPos.z; chessboard = fract(chessboard * 0.5); chessboard *= 2; From fedbf9a31ea5facd688f0fa94aafac11780e8b4a Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 2 Mar 2023 15:31:10 +0100 Subject: [PATCH 52/68] Remove unused textures --- modules/base/rendering/renderablemodel.cpp | 24 ++-------------------- modules/base/rendering/renderablemodel.h | 3 +-- modules/base/shaders/modelOpacity_fs.glsl | 4 ---- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 7ffd74c943..52185f2545 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -79,9 +79,8 @@ namespace { "specularIntensity", "performManualDepthTest", "gBufferDepthTexture" }; - constexpr std::array UniformOpacityNames = { - "opacity", "colorTexture", "depthTexture", "positionTexture", - "normalTexture" + constexpr std::array UniformOpacityNames = { + "opacity", "colorTexture", "depthTexture" }; constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { @@ -860,25 +859,6 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ); _quadProgram->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); - ghoul::opengl::TextureUnit positionTextureUnit; - positionTextureUnit.activate(); - glBindTexture( - GL_TEXTURE_2D, - global::renderEngine->renderer()->additionalColorTexture2() - ); - _quadProgram->setUniform( - _uniformOpacityCache.positionTexture, - positionTextureUnit - ); - - ghoul::opengl::TextureUnit normalTextureUnit; - normalTextureUnit.activate(); - glBindTexture( - GL_TEXTURE_2D, - global::renderEngine->renderer()->additionalColorTexture3() - ); - _quadProgram->setUniform(_uniformOpacityCache.normalTexture, normalTextureUnit); - ghoul::opengl::TextureUnit depthTextureUnit; depthTextureUnit.activate(); glBindTexture( diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 0ef9d8041f..eafd558810 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -122,8 +122,7 @@ private: // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; - UniformCache(opacity, colorTexture, depthTexture, positionTexture, - normalTexture) _uniformOpacityCache; + UniformCache(opacity, colorTexture, depthTexture) _uniformOpacityCache; // Store the original RenderBin Renderable::RenderBin _originalRenderBin; diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index a9a0da3281..1f19bef9ec 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -31,8 +31,6 @@ uniform float opacity = 1.0; uniform sampler2D colorTexture; uniform sampler2D depthTexture; -uniform sampler2D positionTexture; -uniform sampler2D normalTexture; Fragment getFragment() { Fragment frag; @@ -46,8 +44,6 @@ Fragment getFragment() { frag.color.a = opacity * textureColor.a; frag.depth = denormalizeFloat(texture(depthTexture, vs_st).x); - frag.gPosition = texture(positionTexture, vs_st); - frag.gNormal = vec4(texture(normalTexture, vs_st).rgb, 0.0); frag.disableLDR2HDR = true; return frag; From 98836e5393a319caa2d11b60cacc4eb672d9c8aa Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 3 Mar 2023 08:44:13 +0100 Subject: [PATCH 53/68] Fix manual depth test hole cutting --- modules/base/rendering/renderablemodel.cpp | 25 +++++++++++++++++++--- modules/base/rendering/renderablemodel.h | 3 ++- modules/base/shaders/model_fs.glsl | 24 +++++++++++++++++++-- modules/base/shaders/model_vs.glsl | 6 ------ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 52185f2545..1841b967ef 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -72,11 +73,12 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", - "specularIntensity", "performManualDepthTest", "gBufferDepthTexture" + "specularIntensity", "performManualDepthTest", "gBufferDepthTexture", + "viewport", "resolution" }; constexpr std::array UniformOpacityNames = { @@ -812,7 +814,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glClearBufferfv(GL_COLOR, 1, glm::value_ptr(glm::vec4(0.f, 0.f, 0.f, 0.f))); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // Use a manuel depth test to make the models aware of the rest of the envierment + // Use a manuel depth test to make the models aware of the rest of the scene _program->setUniform( _uniformCache.performManualDepthTest, _enableDepthTest @@ -831,6 +833,23 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { gBufferDepthTextureUnit ); + // Will also need the resolution and viewport to get a texture coordinate for the + // G-buffer depth texture + _program->setUniform( + _uniformCache.resolution, + glm::vec2(global::windowDelegate->currentDrawBufferResolution()) + ); + + GLint vp[4] = { 0 }; + global::renderEngine->openglStateCache().viewport(vp); + glm::ivec4 viewport = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); + _program->setUniform( + _uniformCache.viewport, + static_cast(viewport[0]), + static_cast(viewport[1]), + static_cast(viewport[2]), + static_cast(viewport[3]) + ); // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index eafd558810..a65e669a74 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -105,7 +105,8 @@ private: UniformCache(nLightSources, lightDirectionsViewSpace, lightIntensities, modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, - specularIntensity, performManualDepthTest, gBufferDepthTexture) _uniformCache; + specularIntensity, performManualDepthTest, gBufferDepthTexture, + viewport, resolution) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index cfe1b02702..cf11ee634b 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -25,7 +25,6 @@ #include "fragment.glsl" in vec2 vs_st; -in vec2 vs_viewportPixelCoord; in vec3 vs_normalViewSpace; in vec4 vs_positionCameraSpace; in float vs_screenSpaceDepth; @@ -51,6 +50,9 @@ uniform float lightIntensities[8]; uniform bool performManualDepthTest = false; uniform sampler2D gBufferDepthTexture; +uniform vec4 viewport; +uniform vec2 resolution; + Fragment getFragment() { Fragment frag; frag.depth = vs_screenSpaceDepth; @@ -60,9 +62,27 @@ Fragment getFragment() { frag.color.a = 1.0; if (performManualDepthTest) { + // gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to + // resolution.y, need to normalize it + vec2 texCoord = gl_FragCoord.xy; + texCoord.x = texCoord.x / resolution.x; + texCoord.y = texCoord.y / resolution.y; + + // Modify the texCoord based on the Viewport and Resolution. This modification is + // necessary in case of side-by-side stereo as we only want to access the part of the + // feeding texture that we are currently responsible for. Otherwise we would map the + // entire feeding texture into our half of the result texture, leading to a doubling + // of the "missing" half. If you don't believe me, load a configuration file with the + // side_by_side stereo mode enabled, disable FXAA, and remove this modification. + // The same calculation is done in the FXAA shader, the HDR resolving and the + // atmosphere shader + vec2 st = texCoord; + st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); + st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + // Manual depth test float gBufferDepth = - denormalizeFloat(texture(gBufferDepthTexture, vs_viewportPixelCoord).x); + denormalizeFloat(texture(gBufferDepthTexture, st).x); if (vs_screenSpaceDepth > gBufferDepth) { frag.color = vec4(0.0); frag.depth = gBufferDepth; diff --git a/modules/base/shaders/model_vs.glsl b/modules/base/shaders/model_vs.glsl index d100ed7c7d..c6a049cae8 100644 --- a/modules/base/shaders/model_vs.glsl +++ b/modules/base/shaders/model_vs.glsl @@ -32,7 +32,6 @@ layout(location = 2) in vec3 in_normal; layout(location = 3) in vec3 in_tangent; out vec2 vs_st; -out vec2 vs_viewportPixelCoord; out vec3 vs_normalViewSpace; out float vs_screenSpaceDepth; out vec4 vs_positionCameraSpace; @@ -68,9 +67,4 @@ void main() { vec3 B = normalize(cross(N, T)); vs_TBN = mat3(T, B, N); - - // Figure out the fragment's position in the viewport - vec3 ndc = gl_Position.xyz / gl_Position.w; // perspective divide/normalize - vec2 viewportCoord = ndc.xy * 0.5 + 0.5; // ndc is -1 to 1 in GL. scale for 0 to 1 - vs_viewportPixelCoord = viewportCoord; } From 0d4c47f3be6916658672e5f599f6a98c80eb81fd Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 3 Mar 2023 14:55:06 +0100 Subject: [PATCH 54/68] Move boundingsphere size in asset into the node from model projection --- .../solarsystem/missions/dawn/vesta.asset | 2 +- .../solarsystem/missions/rosetta/67p.asset | 99 +++++++++---------- .../rendering/renderablemodelprojection.cpp | 24 +---- .../rendering/renderablemodelprojection.h | 1 - 4 files changed, 55 insertions(+), 71 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/dawn/vesta.asset b/data/assets/scene/solarsystem/missions/dawn/vesta.asset index 57a1d68144..c806d808fb 100644 --- a/data/assets/scene/solarsystem/missions/dawn/vesta.asset +++ b/data/assets/scene/solarsystem/missions/dawn/vesta.asset @@ -48,10 +48,10 @@ local Vesta = { DestinationFrame = "GALACTIC" } }, + BoundingSphere = 262000, Renderable = { Type = "RenderableModelProjection", GeometryFile = models .. "VestaComet_5000.obj", - BoundingSphereRadius = 262000, Projection = { Sequence = images, SequenceType = "image-sequence", diff --git a/data/assets/scene/solarsystem/missions/rosetta/67p.asset b/data/assets/scene/solarsystem/missions/rosetta/67p.asset index 2c694b7059..0e10b330d3 100644 --- a/data/assets/scene/solarsystem/missions/rosetta/67p.asset +++ b/data/assets/scene/solarsystem/missions/rosetta/67p.asset @@ -46,63 +46,62 @@ local Comet67P = { Identifier = "67P", Parent = Barycenter.Identifier, Transform = { - Rotation = { - Type = "SpiceRotation", - SourceFrame = "67P/C-G_CK", - DestinationFrame = "GALACTIC" - } + Rotation = { + Type = "SpiceRotation", + SourceFrame = "67P/C-G_CK", + DestinationFrame = "GALACTIC" + } }, + BoundingSphere = 5000.0, Renderable = { - Type = "RenderableModelProjection", - GeometryFile = models .. "67P_rotated_5_130.obj", - Projection = { - Sequence = { imagesDestination }, - SequenceType = "image-sequence", - Observer = "ROSETTA", - Target = "CHURYUMOV-GERASIMENKO", - Aberration = "NONE", - TextureMap = true, - ShadowMap = true, + Type = "RenderableModelProjection", + GeometryFile = models .. "67P_rotated_5_130.obj", + Projection = { + Sequence = { imagesDestination }, + SequenceType = "image-sequence", + Observer = "ROSETTA", + Target = "CHURYUMOV-GERASIMENKO", + Aberration = "NONE", + TextureMap = true, + ShadowMap = true, - DataInputTranslation = { - Instrument = { - NAVCAM = { - DetectorType = "Camera", - Spice = { "ROS_NAVCAM-A" } - } - }, - Target = { - Read = { - "TARGET_NAME", - "INSTRUMENT_HOST_NAME", - "INSTRUMENT_ID", - "START_TIME", - "STOP_TIME" - }, - Convert = { - CHURYUMOV = { "CHURYUMOV-GERASIMENKO" }, - ROSETTA = { "ROSETTA" }, - ["ROSETTA-ORBITER"] = { "ROSETTA" }, - CHURYUMOVGERASIMENKO11969R1 = { "CHURYUMOV-GERASIMENKO" }, - CHURYUMOVGERASIMENKO = { "CHURYUMOV-GERASIMENKO" }, - ["CHURYUMOV-GERASIMENKO1(1969R1)"] = { "CHURYUMOV-GERASIMENKO" }, - CALIBRATION = { "CALIBRATION" }, - ALPHALYR = { "ALPHALYR" }, - ZETACAS = { "ZETACAS" } - } + DataInputTranslation = { + Instrument = { + NAVCAM = { + DetectorType = "Camera", + Spice = { "ROS_NAVCAM-A" } } }, - - Instrument = { - Name = "ROS_NAVCAM-A", - Method = "ELLIPSOID", - Aberration = "NONE", - Fovy = 5.00, - Aspect = 1 + Target = { + Read = { + "TARGET_NAME", + "INSTRUMENT_HOST_NAME", + "INSTRUMENT_ID", + "START_TIME", + "STOP_TIME" + }, + Convert = { + CHURYUMOV = { "CHURYUMOV-GERASIMENKO" }, + ROSETTA = { "ROSETTA" }, + ["ROSETTA-ORBITER"] = { "ROSETTA" }, + CHURYUMOVGERASIMENKO11969R1 = { "CHURYUMOV-GERASIMENKO" }, + CHURYUMOVGERASIMENKO = { "CHURYUMOV-GERASIMENKO" }, + ["CHURYUMOV-GERASIMENKO1(1969R1)"] = { "CHURYUMOV-GERASIMENKO" }, + CALIBRATION = { "CALIBRATION" }, + ALPHALYR = { "ALPHALYR" }, + ZETACAS = { "ZETACAS" } + } } - }, + }, - BoundingSphereRadius = 5000.0 + Instrument = { + Name = "ROS_NAVCAM-A", + Method = "ELLIPSOID", + Aberration = "NONE", + Fovy = 5.00, + Aspect = 1 + } + }, }, GUI = { Name = "67P Churymov-Gerasimenko", diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 5acf6ecefd..9030983ff3 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -108,12 +108,6 @@ namespace { // [[codegen::verbatim(PerformShadingInfo.description)]] std::optional performShading; - - // The radius of the bounding sphere of this object. This has to be a - // radius that is larger than anything that is rendered by it. It has to - // be at least as big as the convex hull of the object. The default value - // is 10e9 meters. - std::optional boundingSphereRadius; }; #include "renderablemodelprojection_codegen.cpp" } // namespace @@ -171,12 +165,6 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di addPropertySubOwner(_projectionComponent); _projectionComponent.initialize(identifier(), p.projection); - if (p.boundingSphereRadius.has_value()) { - _shouldOverrideBoundingSphere = true; - double boundingSphereRadius = p.boundingSphereRadius.value(); - setBoundingSphere(boundingSphereRadius); - } - _performShading = p.performShading.value_or(_performShading); addProperty(_performShading); } @@ -254,14 +242,12 @@ ghoul::opengl::Texture& RenderableModelProjection::baseTexture() const { void RenderableModelProjection::render(const RenderData& data, RendererTasks&) { // Update boundingsphere - if (!_shouldOverrideBoundingSphere) { - setBoundingSphere(_geometry->boundingRadius() * _modelScale * - glm::compMax(data.modelTransform.scale) - ); + setBoundingSphere(_geometry->boundingRadius() * _modelScale * + glm::compMax(data.modelTransform.scale) + ); - // Set Interaction sphere size to be 10% of the bounding sphere - setInteractionSphere(_boundingSphere * 0.1); - } + // Set Interaction sphere size to be 10% of the bounding sphere + setInteractionSphere(_boundingSphere * 0.1); if (_projectionComponent.needsClearProjection()) { _projectionComponent.clearAllProjections(); diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h index 420d0eaaac..14627c14ea 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h @@ -85,7 +85,6 @@ private: UniformCache(ProjectorMatrix, ModelTransform) _depthFboUniformCache; std::unique_ptr _geometry; - bool _shouldOverrideBoundingSphere = false; double _modelScale = 1.0; bool _invertModelScale = false; bool _forceRenderInvisible = false; From a3b5300684aafe2ca1eab1959a626011cdc904be Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 8 Mar 2023 10:24:26 +0100 Subject: [PATCH 55/68] Update model shader example shaders --- .../assets/examples/modelshader/model_fs.glsl | 53 +++++++++++++++---- .../assets/examples/modelshader/model_vs.glsl | 21 ++++---- modules/base/shaders/model_fs.glsl | 9 +++- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/data/assets/examples/modelshader/model_fs.glsl b/data/assets/examples/modelshader/model_fs.glsl index be9f2558fc..71c7f9237c 100644 --- a/data/assets/examples/modelshader/model_fs.glsl +++ b/data/assets/examples/modelshader/model_fs.glsl @@ -28,21 +28,19 @@ in vec2 vs_st; in vec3 vs_normalViewSpace; in vec4 vs_positionCameraSpace; in float vs_screenSpaceDepth; -in mat3 TBN; +in mat3 vs_TBN; uniform float ambientIntensity = 0.2; uniform float diffuseIntensity = 1.0; uniform float specularIntensity = 1.0; - uniform bool performShading = true; + uniform bool use_forced_color = false; uniform bool has_texture_diffuse; uniform bool has_texture_normal; uniform bool has_texture_specular; uniform bool has_color_specular; -uniform bool opacityBlending = false; - uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; @@ -54,22 +52,57 @@ uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; -uniform float opacity = 1.0; +uniform bool performManualDepthTest = false; +uniform sampler2D gBufferDepthTexture; + +uniform vec4 viewport; +uniform vec2 resolution; Fragment getFragment() { Fragment frag; + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionCameraSpace; + frag.gNormal = vec4(vs_normalViewSpace, 0.0); + frag.disableLDR2HDR = true; + frag.color.a = 1.0; + if (performManualDepthTest) { + // gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to + // resolution.y, need to normalize it + vec2 texCoord = gl_FragCoord.xy; + texCoord.x = texCoord.x / resolution.x; + texCoord.y = texCoord.y / resolution.y; + + // Modify the texCoord based on the Viewport and Resolution. This modification is + // necessary in case of side-by-side stereo as we only want to access the part of the + // feeding texture that we are currently responsible for. Otherwise we would map the + // entire feeding texture into our half of the result texture, leading to a doubling + // of the "missing" half. If you don't believe me, load a configuration file with the + // side_by_side stereo mode enabled, disable FXAA, and remove this modification. + // The same calculation is done in the FXAA shader, the HDR resolving and the + // atmosphere shader + vec2 st = texCoord; + st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); + st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + + // Manual depth test + float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, st).x); + if (vs_screenSpaceDepth > gBufferDepth) { + frag.color = vec4(0.0); + frag.depth = gBufferDepth; + return frag; + } + } + + // Frag color is the normal values if (has_texture_normal) { vec3 normalAlbedo = texture(texture_normal, vs_st).rgb; normalAlbedo = normalize(normalAlbedo * 2.0 - 1.0); - frag.color.rgb = normalize(TBN * normalAlbedo); + frag.color.rgb = normalize(vs_TBN * normalAlbedo); } else { frag.color.rgb = normalize(vs_normalViewSpace); } - frag.color.a = 1.0; - frag.gPosition = vs_positionCameraSpace; - frag.gNormal = vec4(vs_normalViewSpace, 0.0); - frag.disableLDR2HDR = true; + return frag; } diff --git a/data/assets/examples/modelshader/model_vs.glsl b/data/assets/examples/modelshader/model_vs.glsl index 8413d4f4c1..ddd94fe996 100644 --- a/data/assets/examples/modelshader/model_vs.glsl +++ b/data/assets/examples/modelshader/model_vs.glsl @@ -35,7 +35,7 @@ out vec2 vs_st; out vec3 vs_normalViewSpace; out float vs_screenSpaceDepth; out vec4 vs_positionCameraSpace; -out mat3 TBN; +out mat3 vs_TBN; uniform mat4 modelViewTransform; uniform mat4 projectionTransform; @@ -52,17 +52,18 @@ void main() { vs_st = in_st; vs_screenSpaceDepth = positionScreenSpace.w; - vs_normalViewSpace = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); + vs_normalViewSpace = + normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); - // TBN matrix for normal mapping - vec3 T = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_tangent)); - vec3 N = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); + // TBN matrix for normal mapping + vec3 T = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_tangent)); + vec3 N = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal)); - // Re-orthogonalize T with respect to N - T = normalize(T - dot(T, N) * N); + // Re-orthogonalize T with respect to N + T = normalize(T - dot(T, N) * N); - // Retrieve perpendicular vector B with cross product of T and N - vec3 B = normalize(cross(N, T)); + // Retrieve perpendicular vector B with cross product of T and N + vec3 B = normalize(cross(N, T)); - TBN = mat3(T, B, N); + vs_TBN = mat3(T, B, N); } diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index cf11ee634b..43906d95ef 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -34,19 +34,24 @@ uniform float ambientIntensity = 0.2; uniform float diffuseIntensity = 1.0; uniform float specularIntensity = 1.0; uniform bool performShading = true; + uniform bool use_forced_color = false; uniform bool has_texture_diffuse; uniform bool has_texture_normal; uniform bool has_texture_specular; uniform bool has_color_specular; + uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; + uniform vec4 color_diffuse; uniform vec4 color_specular; + uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; uniform float lightIntensities[8]; + uniform bool performManualDepthTest = false; uniform sampler2D gBufferDepthTexture; @@ -81,8 +86,7 @@ Fragment getFragment() { st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); // Manual depth test - float gBufferDepth = - denormalizeFloat(texture(gBufferDepthTexture, st).x); + float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, st).x); if (vs_screenSpaceDepth > gBufferDepth) { frag.color = vec4(0.0); frag.depth = gBufferDepth; @@ -136,6 +140,7 @@ Fragment getFragment() { else { normal = normalize(vs_normalViewSpace); } + frag.gNormal = vec4(normal, 0.0); // Could be seperated into ambinet, diffuse and specular and passed in as uniforms const vec3 lightColor = vec3(1.0); From 184a8b59ac74ddfd20fc76e6d24ac96a3dbbba67 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 8 Mar 2023 11:49:55 +0100 Subject: [PATCH 56/68] Fix hole cutting or side by side stereo * And disable face culling for Orion model that is a one sided plane --- .../assets/examples/modelshader/model_fs.glsl | 15 +-------------- .../milkyway/objects/orionnebula/nebula.asset | 2 +- modules/base/rendering/renderablemodel.cpp | 19 ++++--------------- modules/base/rendering/renderablemodel.h | 2 +- modules/base/shaders/model_fs.glsl | 15 +-------------- 5 files changed, 8 insertions(+), 45 deletions(-) diff --git a/data/assets/examples/modelshader/model_fs.glsl b/data/assets/examples/modelshader/model_fs.glsl index 71c7f9237c..8a4a383185 100644 --- a/data/assets/examples/modelshader/model_fs.glsl +++ b/data/assets/examples/modelshader/model_fs.glsl @@ -55,7 +55,6 @@ uniform float lightIntensities[8]; uniform bool performManualDepthTest = false; uniform sampler2D gBufferDepthTexture; -uniform vec4 viewport; uniform vec2 resolution; Fragment getFragment() { @@ -73,20 +72,8 @@ Fragment getFragment() { texCoord.x = texCoord.x / resolution.x; texCoord.y = texCoord.y / resolution.y; - // Modify the texCoord based on the Viewport and Resolution. This modification is - // necessary in case of side-by-side stereo as we only want to access the part of the - // feeding texture that we are currently responsible for. Otherwise we would map the - // entire feeding texture into our half of the result texture, leading to a doubling - // of the "missing" half. If you don't believe me, load a configuration file with the - // side_by_side stereo mode enabled, disable FXAA, and remove this modification. - // The same calculation is done in the FXAA shader, the HDR resolving and the - // atmosphere shader - vec2 st = texCoord; - st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); - st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); - // Manual depth test - float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, st).x); + float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, texCoord).x); if (vs_screenSpaceDepth > gBufferDepth) { frag.color = vec4(0.0); frag.depth = gBufferDepth; diff --git a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset index de8aae2960..58c5375fe8 100644 --- a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset +++ b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset @@ -58,7 +58,7 @@ local OrionNebulaModel = { Type = "RenderableModel", GeometryFile = sync .. "orion_nebula.obj", Opacity = 1.0, - EnableFaceCulling = true, + EnableFaceCulling = false, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 1841b967ef..dc68cc93e6 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -73,12 +73,12 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", "specularIntensity", "performManualDepthTest", "gBufferDepthTexture", - "viewport", "resolution" + "resolution" }; constexpr std::array UniformOpacityNames = { @@ -833,24 +833,13 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { gBufferDepthTextureUnit ); - // Will also need the resolution and viewport to get a texture coordinate for the - // G-buffer depth texture + // Will also need the resolution to get a texture coordinate for the G-buffer + // depth texture _program->setUniform( _uniformCache.resolution, glm::vec2(global::windowDelegate->currentDrawBufferResolution()) ); - GLint vp[4] = { 0 }; - global::renderEngine->openglStateCache().viewport(vp); - glm::ivec4 viewport = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); - _program->setUniform( - _uniformCache.viewport, - static_cast(viewport[0]), - static_cast(viewport[1]), - static_cast(viewport[2]), - static_cast(viewport[3]) - ); - // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity _geometry->render(*_program); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index a65e669a74..7733fd005a 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -106,7 +106,7 @@ private: modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, specularIntensity, performManualDepthTest, gBufferDepthTexture, - viewport, resolution) _uniformCache; + resolution) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 43906d95ef..857b365b3c 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -55,7 +55,6 @@ uniform float lightIntensities[8]; uniform bool performManualDepthTest = false; uniform sampler2D gBufferDepthTexture; -uniform vec4 viewport; uniform vec2 resolution; Fragment getFragment() { @@ -73,20 +72,8 @@ Fragment getFragment() { texCoord.x = texCoord.x / resolution.x; texCoord.y = texCoord.y / resolution.y; - // Modify the texCoord based on the Viewport and Resolution. This modification is - // necessary in case of side-by-side stereo as we only want to access the part of the - // feeding texture that we are currently responsible for. Otherwise we would map the - // entire feeding texture into our half of the result texture, leading to a doubling - // of the "missing" half. If you don't believe me, load a configuration file with the - // side_by_side stereo mode enabled, disable FXAA, and remove this modification. - // The same calculation is done in the FXAA shader, the HDR resolving and the - // atmosphere shader - vec2 st = texCoord; - st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); - st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); - // Manual depth test - float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, st).x); + float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, texCoord).x); if (vs_screenSpaceDepth > gBufferDepth) { frag.color = vec4(0.0); frag.depth = gBufferDepth; From 3cd2cfac93660fa4ec9d59009f90ba3b82bbea31 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 9 Mar 2023 11:59:44 +0100 Subject: [PATCH 57/68] Fix issue with side by side stereo rendering --- modules/base/rendering/renderablemodel.cpp | 21 +++++++++++++++++++-- modules/base/rendering/renderablemodel.h | 3 ++- modules/base/shaders/modelOpacity_fs.glsl | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index dc68cc93e6..64fdf8ea67 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -81,8 +81,8 @@ namespace { "resolution" }; - constexpr std::array UniformOpacityNames = { - "opacity", "colorTexture", "depthTexture" + constexpr std::array UniformOpacityNames = { + "opacity", "colorTexture", "depthTexture", "viewport", "resolution" }; constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { @@ -875,6 +875,23 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ); _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); + // Will also need the resolution and viewport to get a texture coordinate + _quadProgram->setUniform( + _uniformOpacityCache.resolution, + glm::vec2(global::windowDelegate->currentDrawBufferResolution()) + ); + + GLint vp[4] = { 0 }; + global::renderEngine->openglStateCache().viewport(vp); + glm::ivec4 viewport = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); + _quadProgram->setUniform( + _uniformOpacityCache.viewport, + static_cast(viewport[0]), + static_cast(viewport[1]), + static_cast(viewport[2]), + static_cast(viewport[3]) + ); + // Draw glBindVertexArray(_quadVao); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 7733fd005a..ba40bb4d80 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -123,7 +123,8 @@ private: // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; - UniformCache(opacity, colorTexture, depthTexture) _uniformOpacityCache; + UniformCache(opacity, colorTexture, depthTexture, viewport, + resolution) _uniformOpacityCache; // Store the original RenderBin Renderable::RenderBin _originalRenderBin; diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 1f19bef9ec..4ce6761239 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -32,10 +32,24 @@ uniform float opacity = 1.0; uniform sampler2D colorTexture; uniform sampler2D depthTexture; +uniform vec4 viewport; +uniform vec2 resolution; + Fragment getFragment() { Fragment frag; - vec4 textureColor = texture(colorTexture, vs_st); + // Modify the texCoord based on the Viewport and Resolution. This modification is + // necessary in case of side-by-side stereo as we only want to access the part of the + // feeding texture that we are currently responsible for. Otherwise we would map the + // entire feeding texture into our half of the result texture, leading to a doubling of + // the "missing" half. If you don't believe me, load a configuration file with the + // side_by_side stereo mode enabled, disable FXAA, and remove this modification. + // The same calculation is done in the HDR resolving shader + vec2 st = vs_st; + st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); + st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + + vec4 textureColor = texture(colorTexture, st); if (textureColor.a == 0.0 || opacity == 0.0) { discard; } From be2e9d5cafbe8f54879b2bc0f66037caf064384e Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 22 Mar 2023 13:37:30 +0100 Subject: [PATCH 58/68] Address PR comments --- .../solarsystem/missions/dawn/dawn.asset | 5 ++- .../missions/rosetta/rosetta.asset | 5 ++- .../openspace/rendering/framebufferrenderer.h | 32 +++++++++---------- include/openspace/rendering/renderengine.h | 2 +- modules/base/rendering/renderablemodel.cpp | 32 +++++++++---------- modules/base/rendering/renderablemodel.h | 6 ++-- modules/base/shaders/modelOpacity_fs.glsl | 2 +- src/rendering/framebufferrenderer.cpp | 32 +++++++++---------- src/rendering/renderengine.cpp | 4 +-- 9 files changed, 59 insertions(+), 61 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/dawn/dawn.asset b/data/assets/scene/solarsystem/missions/dawn/dawn.asset index b175fbf311..5bea3aad26 100644 --- a/data/assets/scene/solarsystem/missions/dawn/dawn.asset +++ b/data/assets/scene/solarsystem/missions/dawn/dawn.asset @@ -1,6 +1,5 @@ local transforms = asset.require("scene/solarsystem/sun/transforms") local sun = asset.require("scene/solarsystem/sun/sun") -local M_PI = 3.141592657 local kernels = asset.syncedResource({ Name = "Dawn Kernels", @@ -88,7 +87,7 @@ local DawnPosition = { -- Rotation for model version 2 Rotation = { Type = "StaticRotation", - Rotation = { M_PI/2.0, 0.0, M_PI/2.0 } + Rotation = { math.pi/2.0, 0.0, math.pi/2.0 } } }, GUI = { @@ -209,7 +208,7 @@ local DawnFramingCamera2 = { }, Rotation = { Type = "StaticRotation", - Rotation = { 0, M_PI/2.0, 0 } + Rotation = { 0, math.pi/2.0, 0 } } }, GUI = { diff --git a/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset b/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset index fb015cf949..8bd1a9f300 100644 --- a/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset +++ b/data/assets/scene/solarsystem/missions/rosetta/rosetta.asset @@ -1,7 +1,6 @@ local sun = asset.require("scene/solarsystem/sun/sun") local sunTransforms = asset.require("scene/solarsystem/sun/transforms") local transforms = asset.require("./67p") -local M_PI = 3.141592657 local models = asset.syncedResource({ Name = "Rosetta Models", @@ -101,7 +100,7 @@ local Rosetta = { Transform = { Rotation = { Type = "StaticRotation", - Rotation = { 0.0, M_PI/2.0, 0.0 } + Rotation = { 0.0, math.pi/2.0, 0.0 } } }, Renderable = { @@ -153,7 +152,7 @@ local Philae = { Transform = { Rotation = { Type = "StaticRotation", - Rotation = { 0.0, M_PI/2.0, 0.0 } + Rotation = { 0.0, math.pi/2.0, 0.0 } } }, Renderable = { diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 32dd262d94..a9701e8a8e 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -71,36 +71,36 @@ public: * depending on where in the render cycle you are. Especially after the Deferred * Caster Tasks. * - * \return GLuint identifier of the currently NOT used pingPongTexture + * \return identifier of the currently NOT used pingPongTexture */ - GLuint additionalColorTexture1(); + GLuint additionalColorTexture1() const; /** * Gives access to the exitColorTexture. This texture is available for all RenderBins. * However, it cannot be used at the same time as the Raycaster Tasks. The size of the * texture is the resolution of the viewport. * - * \return GLuint identifier of the exitColorTexture + * \return identifier of the exitColorTexture */ - GLuint additionalColorTexture2(); + GLuint additionalColorTexture2() const; /** * Gives access to the fxaaTexture. This texture is available for all RenderBins. * However, it cannot be used at the same time as the FXAA Task. The size of the * texture is the resolution of the viewport. * - * \return GLuint identifier of the fxaaTexture + * \return identifier of the fxaaTexture */ - GLuint additionalColorTexture3(); + GLuint additionalColorTexture3() const; /** * Gives access to the exitDepthTexture. This texture is available for all RenderBins. * However, it cannot be used at the same time as the Raycaster Tasks. The size of the * texture is the resolution of the viewport. * - * \return GLuint identifier of the exitDepthTexture + * \return identifier of the exitDepthTexture */ - GLuint additionalDepthTexture(); + GLuint additionalDepthTexture() const; //=============================// //===== Access G-buffer =====// @@ -111,36 +111,36 @@ public: * the majority of rendering the scene and might be already in use. Use CAUTION when * using this function. The size of the texture is the resolution of the viewport. * - * \return GLuint identifier of the color texture of the G-buffer + * \return identifier of the color texture of the G-buffer */ - GLuint gBufferColorTexture(); + GLuint gBufferColorTexture() const; /** * Gives access to the position texture of the G-buffer. NOTE: This texture is used for * the majority of rendering the scene and might be already in use. Use CAUTION when * using this function. The size of the texture is the resolution of the viewport. * - * \return GLuint identifier of the position texture of the G-buffer + * \return identifier of the position texture of the G-buffer */ - GLuint gBufferPositionTexture(); + GLuint gBufferPositionTexture() const; /** * Gives access to the normal texture of the G-buffer. NOTE: This texture is used for * the majority of rendering the scene and might be already in use. Use CAUTION when * using this function. The size of the texture is the resolution of the viewport. * - * \return GLuint identifier of the normal texture of the G-buffer + * \return identifier of the normal texture of the G-buffer */ - GLuint gBufferNormalTexture(); + GLuint gBufferNormalTexture() const; /** * Gives access to the depth texture of the G-buffer. NOTE: This texture is used for * the majority of rendering the scene and might be already in use. Use CAUTION when * using this function. The size of the texture is the resolution of the viewport. * - * \return GLuint identifier of the depth texture of the G-buffer + * \return identifier of the depth texture of the G-buffer */ - GLuint gBufferDepthTexture(); + GLuint gBufferDepthTexture() const; void initialize(); void deinitialize(); diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 173e0699c2..4a298becb6 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -68,7 +68,7 @@ public: RenderEngine(); virtual ~RenderEngine() override; - FramebufferRenderer* renderer(); + const FramebufferRenderer& renderer() const; void initialize(); void initializeGL(); diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index a615602b21..948c13de01 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -586,7 +586,7 @@ void RenderableModel::initializeGL() { GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), - (void*)(2 * sizeof(GLfloat)) + reinterpret_cast(2 * sizeof(GLfloat)) ); // Generate textures and the frame buffer @@ -597,25 +597,25 @@ void RenderableModel::initializeGL() { glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - global::renderEngine->renderer()->additionalColorTexture1(), + global::renderEngine->renderer().additionalColorTexture1(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, - global::renderEngine->renderer()->additionalColorTexture2(), + global::renderEngine->renderer().additionalColorTexture2(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, - global::renderEngine->renderer()->additionalColorTexture3(), + global::renderEngine->renderer().additionalColorTexture3(), 0 ); glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - global::renderEngine->renderer()->additionalDepthTexture(), + global::renderEngine->renderer().additionalDepthTexture(), 0 ); @@ -772,17 +772,17 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { } // Only render two pass if the model is in any way transparent - bool shouldRenderTwise = false; + bool shouldRenderTwice = false; const float o = opacity(); if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { setRenderBin(Renderable::RenderBin::PostDeferredTransparent); - shouldRenderTwise = true; + shouldRenderTwice = true; } else { setRenderBin(_originalRenderBin); } - if (!shouldRenderTwise) { + if (!shouldRenderTwice) { // Reset manual depth test _program->setUniform( _uniformCache.performManualDepthTest, @@ -801,7 +801,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - global::renderEngine->renderer()->additionalColorTexture1(), + global::renderEngine->renderer().additionalColorTexture1(), 0 ); // Check status @@ -826,7 +826,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { gBufferDepthTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - global::renderEngine->renderer()->gBufferDepthTexture() + global::renderEngine->renderer().gBufferDepthTexture() ); _program->setUniform( _uniformCache.gBufferDepthTexture, @@ -863,7 +863,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { colorTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - global::renderEngine->renderer()->additionalColorTexture1() + global::renderEngine->renderer().additionalColorTexture1() ); _quadProgram->setUniform(_uniformOpacityCache.colorTexture, colorTextureUnit); @@ -871,7 +871,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { depthTextureUnit.activate(); glBindTexture( GL_TEXTURE_2D, - global::renderEngine->renderer()->additionalDepthTexture() + global::renderEngine->renderer().additionalDepthTexture() ); _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); @@ -886,10 +886,10 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glm::ivec4 viewport = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); _quadProgram->setUniform( _uniformOpacityCache.viewport, - static_cast(viewport[0]), - static_cast(viewport[1]), - static_cast(viewport[2]), - static_cast(viewport[3]) + viewport[0], + viewport[1], + viewport[2], + viewport[3] ); // Draw diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index ba40bb4d80..9f1d820ea3 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -117,9 +117,9 @@ private: properties::PropertyOwner _lightSourcePropertyOwner; // Framebuffer and screen space quad - GLuint _framebuffer; - GLuint _quadVao; - GLuint _quadVbo; + GLuint _framebuffer = 0; + GLuint _quadVao = 0; + GLuint _quadVbo = 0; // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 4ce6761239..cbe4f94f8b 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -32,7 +32,7 @@ uniform float opacity = 1.0; uniform sampler2D colorTexture; uniform sampler2D depthTexture; -uniform vec4 viewport; +uniform ivec4 viewport; uniform vec2 resolution; Fragment getFragment() { diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index d2490d0999..6c85a386ac 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -90,47 +90,47 @@ namespace openspace { //============================// //===== Reuse textures =====// //============================// -// Gives access to the currently NOT used pingPongTexture -GLuint FramebufferRenderer::additionalColorTexture1() { +GLuint FramebufferRenderer::additionalColorTexture1() const { + // Gives access to the currently NOT used pingPongTexture int unusedPingPongIndex = _pingPongIndex == 0 ? 1 : 0; return _pingPongBuffers.colorTexture[unusedPingPongIndex]; } -// Gives access to the exitColorTexture -GLuint FramebufferRenderer::additionalColorTexture2() { +GLuint FramebufferRenderer::additionalColorTexture2() const { + // Gives access to the exitColorTexture return _exitColorTexture; } -// Gives access to the fxaaTexture -GLuint FramebufferRenderer::additionalColorTexture3() { +GLuint FramebufferRenderer::additionalColorTexture3() const { + // Gives access to the fxaaTexture return _fxaaBuffers.fxaaTexture; } -// Gives access to the exitDepthTexture -GLuint FramebufferRenderer::additionalDepthTexture() { +GLuint FramebufferRenderer::additionalDepthTexture() const { + // Gives access to the exitDepthTexture return _exitDepthTexture; } //=============================// //===== Access G-buffer =====// //=============================// -// / Gives access to the color texture of the G-buffer -GLuint FramebufferRenderer::gBufferColorTexture() { +GLuint FramebufferRenderer::gBufferColorTexture() const { + // Gives access to the color texture of the G-buffer return _gBuffers.colorTexture; } -// Gives access to the position texture of the G-buffer -GLuint FramebufferRenderer::gBufferPositionTexture() { +GLuint FramebufferRenderer::gBufferPositionTexture() const { + // Gives access to the position texture of the G-buffer return _gBuffers.positionTexture; } -// Gives access to the normal texture of the G-buffer -GLuint FramebufferRenderer::gBufferNormalTexture() { +GLuint FramebufferRenderer::gBufferNormalTexture() const { + // Gives access to the normal texture of the G-buffer return _gBuffers.normalTexture; } -// Gives access to the depth texture of the G-buffer -GLuint FramebufferRenderer::gBufferDepthTexture() { +GLuint FramebufferRenderer::gBufferDepthTexture() const { + // Gives access to the depth texture of the G-buffer return _gBuffers.depthTexture; } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 8b701c0cac..85da66d100 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -413,8 +413,8 @@ RenderEngine::RenderEngine() RenderEngine::~RenderEngine() {} -FramebufferRenderer* RenderEngine::renderer() { - return &_renderer; +const FramebufferRenderer& RenderEngine::renderer() const { + return _renderer; } void RenderEngine::initialize() { From f636b76469d22d6b2ee63a732f557a9cdd18068c Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 27 Mar 2023 11:26:43 +0200 Subject: [PATCH 59/68] Address more PR comments --- data/assets/examples/animation.asset | 15 ++++------ data/assets/examples/approachevents.asset | 3 +- .../assets/examples/modelshader/model_fs.glsl | 2 +- .../examples/modelshader/modelshader.asset | 1 - .../milkyway/objects/orionnebula/nebula.asset | 4 +-- .../missions/apollo/15/apollo15.asset | 3 +- .../missions/apollo/17/bouldersstation2.asset | 6 ++-- .../missions/apollo/17/bouldersstation6.asset | 6 ++-- .../missions/apollo/17/bouldersstation7.asset | 2 +- .../missions/apollo/8/launch_model.asset | 3 +- .../solarsystem/missions/apollo/8/model.asset | 3 +- .../solarsystem/missions/dawn/dawn.asset | 30 ------------------- .../solarsystem/missions/dawn/vesta.asset | 1 + .../solarsystem/missions/jwst/jwst.asset | 3 +- .../solarsystem/missions/rosetta/67p.asset | 22 +++++++------- .../planets/earth/satellites/misc/iss.asset | 3 +- .../planets/mars/moons/deimos.asset | 3 +- .../planets/mars/moons/phobos.asset | 3 +- .../scene/solarsystem/sssb/itokawa.asset | 1 - modules/base/rendering/renderablemodel.cpp | 2 -- modules/base/rendering/renderabletrail.cpp | 1 - .../rendering/renderablemodelprojection.cpp | 13 ++------ 22 files changed, 37 insertions(+), 93 deletions(-) diff --git a/data/assets/examples/animation.asset b/data/assets/examples/animation.asset index 55af363650..8ab005c037 100644 --- a/data/assets/examples/animation.asset +++ b/data/assets/examples/animation.asset @@ -29,8 +29,7 @@ local animationLoop = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "Animated Model example (LoopFromStart)", @@ -58,8 +57,7 @@ local animationLoopInf = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "Animated Model example (LoopInfinitely)", @@ -87,8 +85,7 @@ local animationOnce = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "Animated Model example (Once)", @@ -116,8 +113,7 @@ local animationBounceInf = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "Animated Model example (BounceInfinitely)", @@ -145,8 +141,7 @@ local animationBounce = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "Animated Model example (BounceFromStart)", diff --git a/data/assets/examples/approachevents.asset b/data/assets/examples/approachevents.asset index 4e99e963d3..fea49cc210 100644 --- a/data/assets/examples/approachevents.asset +++ b/data/assets/examples/approachevents.asset @@ -36,8 +36,7 @@ local obj = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, InteractionSphere = 900, ApproachFactor = 50.0, diff --git a/data/assets/examples/modelshader/model_fs.glsl b/data/assets/examples/modelshader/model_fs.glsl index 8a4a383185..0973172d93 100644 --- a/data/assets/examples/modelshader/model_fs.glsl +++ b/data/assets/examples/modelshader/model_fs.glsl @@ -81,7 +81,7 @@ Fragment getFragment() { } } - // Frag color is the normal values + // Frag color is the values of the normal vector if (has_texture_normal) { vec3 normalAlbedo = texture(texture_normal, vs_st).rgb; normalAlbedo = normalize(normalAlbedo * 2.0 - 1.0); diff --git a/data/assets/examples/modelshader/modelshader.asset b/data/assets/examples/modelshader/modelshader.asset index ab747c8917..405e9bb3f6 100644 --- a/data/assets/examples/modelshader/modelshader.asset +++ b/data/assets/examples/modelshader/modelshader.asset @@ -25,7 +25,6 @@ local model = { sun.LightSource }, PerformShading = true, - EnableFaceCulling = true, VertexShader = asset.localResource("model_vs.glsl"), FragmentShader = asset.localResource("model_fs.glsl"), }, diff --git a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset index 58c5375fe8..4b06ae454d 100644 --- a/data/assets/scene/milkyway/objects/orionnebula/nebula.asset +++ b/data/assets/scene/milkyway/objects/orionnebula/nebula.asset @@ -92,8 +92,7 @@ local OrionNebulaShocksModel = { Renderable = { Type = "RenderableModel", GeometryFile = sync .. "orishocks.obj", - Opacity = 1.0, - EnableFaceCulling = true, + Opacity = 1.0, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, @@ -129,7 +128,6 @@ local OrionNebulaProplydsModel = { Type = "RenderableModel", GeometryFile = sync .. "proplyds.obj", Opacity = 1.0, - EnableFaceCulling = true, SpecularIntensity = 0.0, AmbientIntensity = 0.0, DiffuseIntensity = 1.0, diff --git a/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset b/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset index c151963293..c47c88f0a1 100644 --- a/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset +++ b/data/assets/scene/solarsystem/missions/apollo/15/apollo15.asset @@ -44,8 +44,7 @@ local Apollo15 = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, TimeFrame = { Type = "TimeFrameInterval", diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset index 27b9134e5d..585565ce27 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation2.asset @@ -49,7 +49,7 @@ local Station2Boulder1Model = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 2 Boulder 1 Model", @@ -98,7 +98,7 @@ local Station2Boulder2Model = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 2 Boulder 2 Model", @@ -147,7 +147,7 @@ local Station2Boulder3Model = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 2 Boulder 3 Model", diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset index 310b4aca4b..be41f91fe8 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation6.asset @@ -60,7 +60,7 @@ local Station6Frag1Model = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 6 Fragment 1 Model", @@ -110,7 +110,7 @@ local Station6Frag2Model = { } }, PerformShading = false, - EnableFaceCulling = true, + EnableFaceCulling = false, }, GUI = { Name = "Station 6 Fragment 2 Model", @@ -148,7 +148,7 @@ local Station6Frag3Model = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 6 Fragment 3 Model", diff --git a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset index 62bcfe0030..843f431930 100644 --- a/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset +++ b/data/assets/scene/solarsystem/missions/apollo/17/bouldersstation7.asset @@ -49,7 +49,7 @@ local Station7BoulderModel = { } }, PerformShading = false, - EnableFaceCulling = true + EnableFaceCulling = false }, GUI = { Name = "Station 7 Boulder Model", diff --git a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset index 5760d52161..1b2a7b7ab5 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/launch_model.asset @@ -55,8 +55,7 @@ local Apollo8LaunchModel = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Hidden = true, diff --git a/data/assets/scene/solarsystem/missions/apollo/8/model.asset b/data/assets/scene/solarsystem/missions/apollo/8/model.asset index 740d4efb6e..493bc2b05f 100644 --- a/data/assets/scene/solarsystem/missions/apollo/8/model.asset +++ b/data/assets/scene/solarsystem/missions/apollo/8/model.asset @@ -67,8 +67,7 @@ local Apollo8Model = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Hidden = true, diff --git a/data/assets/scene/solarsystem/missions/dawn/dawn.asset b/data/assets/scene/solarsystem/missions/dawn/dawn.asset index 5bea3aad26..fedc5a04c1 100644 --- a/data/assets/scene/solarsystem/missions/dawn/dawn.asset +++ b/data/assets/scene/solarsystem/missions/dawn/dawn.asset @@ -188,37 +188,7 @@ local DawnFramingCamera2 = { } } --- To make sure the size is correct ---[[local MeassureStick = { - Identifier = "MeassureStick", - Parent = DawnPosition.Identifier, - Renderable = { - Type = "RenderablePrism", - Segments = 16, - Lines = 16, - Radius = 0.855, - LineWidth = 1.0, - Color = { 1.0, 1.0, 1.0 }, - Length = 19.7 - }, - Transform = { - Translation = { - Type = "StaticTranslation", - Position = { -9.85, 0, 0 } - }, - Rotation = { - Type = "StaticRotation", - Rotation = { 0, math.pi/2.0, 0 } - } - }, - GUI = { - Name = "MeassureStick", - Path = "/Solar System/Missions/Dawn", - } -}]] - local nodes = { - --MeassureStick, DawnPosition, Dawn, DawnTrail, diff --git a/data/assets/scene/solarsystem/missions/dawn/vesta.asset b/data/assets/scene/solarsystem/missions/dawn/vesta.asset index c806d808fb..543245f3da 100644 --- a/data/assets/scene/solarsystem/missions/dawn/vesta.asset +++ b/data/assets/scene/solarsystem/missions/dawn/vesta.asset @@ -49,6 +49,7 @@ local Vesta = { } }, BoundingSphere = 262000, + InteractionSphere = 262000, Renderable = { Type = "RenderableModelProjection", GeometryFile = models .. "VestaComet_5000.obj", diff --git a/data/assets/scene/solarsystem/missions/jwst/jwst.asset b/data/assets/scene/solarsystem/missions/jwst/jwst.asset index 92114813a9..c333782857 100644 --- a/data/assets/scene/solarsystem/missions/jwst/jwst.asset +++ b/data/assets/scene/solarsystem/missions/jwst/jwst.asset @@ -80,8 +80,7 @@ local JWSTModel = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, GUI = { Name = "James Webb Space Telescope Model", diff --git a/data/assets/scene/solarsystem/missions/rosetta/67p.asset b/data/assets/scene/solarsystem/missions/rosetta/67p.asset index 0e10b330d3..e89ccb0542 100644 --- a/data/assets/scene/solarsystem/missions/rosetta/67p.asset +++ b/data/assets/scene/solarsystem/missions/rosetta/67p.asset @@ -57,10 +57,10 @@ local Comet67P = { Type = "RenderableModelProjection", GeometryFile = models .. "67P_rotated_5_130.obj", Projection = { - Sequence = { imagesDestination }, + Sequence = { imagesDestination }, SequenceType = "image-sequence", - Observer = "ROSETTA", - Target = "CHURYUMOV-GERASIMENKO", + Observer = "ROSETTA", + Target = "CHURYUMOV-GERASIMENKO", Aberration = "NONE", TextureMap = true, ShadowMap = true, @@ -68,12 +68,12 @@ local Comet67P = { DataInputTranslation = { Instrument = { NAVCAM = { - DetectorType = "Camera", - Spice = { "ROS_NAVCAM-A" } + DetectorType = "Camera", + Spice = { "ROS_NAVCAM-A" } } }, Target = { - Read = { + Read = { "TARGET_NAME", "INSTRUMENT_HOST_NAME", "INSTRUMENT_ID", @@ -95,11 +95,11 @@ local Comet67P = { }, Instrument = { - Name = "ROS_NAVCAM-A", - Method = "ELLIPSOID", + Name = "ROS_NAVCAM-A", + Method = "ELLIPSOID", Aberration = "NONE", - Fovy = 5.00, - Aspect = 1 + Fovy = 5.00, + Aspect = 1 } }, }, @@ -189,6 +189,6 @@ end) asset.export("Barycenter", Barycenter) -- @TODO: This double export should disappear asset.export(Barycenter) -asset.export("Comet67P", Comet67P) -- @TODO: This double export should disappear +asset.export("Comet67P", Comet67P) -- @TODO: This double export should disappear asset.export(Comet67P) asset.export(Trail67P) diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 716f67358d..5df3ea5861 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -61,8 +61,7 @@ local issModel = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, Tag = { "earth_satellite", "ISS" }, GUI = { diff --git a/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset b/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset index 9fa4b8db34..f47cf5f5cc 100644 --- a/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset +++ b/data/assets/scene/solarsystem/planets/mars/moons/deimos.asset @@ -44,8 +44,7 @@ local Deimos = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, Tag = { "moon_solarSystem", "moon_terrestrial", "moon_mars" }, GUI = { diff --git a/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset b/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset index e60a490a23..bf318c1dd2 100644 --- a/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset +++ b/data/assets/scene/solarsystem/planets/mars/moons/phobos.asset @@ -45,8 +45,7 @@ local Phobos = { LightSources = { sun.LightSource }, - PerformShading = true, - EnableFaceCulling = true + PerformShading = true }, Tag = { "moon_solarSystem", "moon_terrestrial", "moon_mars" }, GUI = { diff --git a/data/assets/scene/solarsystem/sssb/itokawa.asset b/data/assets/scene/solarsystem/sssb/itokawa.asset index f7e59f18c0..3a652206d5 100644 --- a/data/assets/scene/solarsystem/sssb/itokawa.asset +++ b/data/assets/scene/solarsystem/sssb/itokawa.asset @@ -68,7 +68,6 @@ local ItokawaModel = { sun.LightSource }, PerformShading = true, - EnableFaceCulling = true, SpecularIntensity = 0.0 }, GUI = { diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 948c13de01..aeeb06e12c 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -168,8 +168,6 @@ namespace { Decimeter, Meter, Kilometer, - - // Weird units Thou, Inch, Foot, diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 23d837c9b7..949a155b08 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -437,7 +437,6 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { // Reset global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetDepthState(); - return; } diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 9030983ff3..6e9f19fea9 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -78,8 +78,6 @@ namespace { Decimeter, Meter, Kilometer, - - // Weird units Thou, Inch, Foot, @@ -221,6 +219,9 @@ void RenderableModelProjection::initializeGL() { double bs = boundingSphere(); _geometry->initialize(); setBoundingSphere(bs); // ignore bounding sphere set by geometry. + + // Set Interaction sphere size to be 10% of the bounding sphere + setInteractionSphere(_boundingSphere * 0.1); } void RenderableModelProjection::deinitializeGL() { @@ -241,14 +242,6 @@ ghoul::opengl::Texture& RenderableModelProjection::baseTexture() const { } void RenderableModelProjection::render(const RenderData& data, RendererTasks&) { - // Update boundingsphere - setBoundingSphere(_geometry->boundingRadius() * _modelScale * - glm::compMax(data.modelTransform.scale) - ); - - // Set Interaction sphere size to be 10% of the bounding sphere - setInteractionSphere(_boundingSphere * 0.1); - if (_projectionComponent.needsClearProjection()) { _projectionComponent.clearAllProjections(); } From be1b8201738e0553d5d3bc4103305e667a3ab3d4 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 27 Mar 2023 13:55:20 +0200 Subject: [PATCH 60/68] Fix model projection issues --- .../rendering/renderablemodelprojection.cpp | 32 +++++-------------- .../rendering/renderablemodelprojection.h | 9 ++---- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 6e9f19fea9..42394f9896 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -39,11 +39,9 @@ #include namespace { - constexpr std::array MainUniformNames = { - "modelViewTransform", "projectionTransform", "meshTransform", - "meshNormalTransform", "has_texture_diffuse", "baseTexture", "baseColor", - "projectionTexture", "performShading", "projectionFading", - "directionToSunViewSpace" + constexpr std::array MainUniformNames = { + "performShading", "directionToSunViewSpace", "modelViewTransform", + "projectionTransform", "projectionFading", "baseTexture", "projectionTexture" }; constexpr std::array FboUniformNames = { @@ -96,10 +94,6 @@ namespace { // given ModelScale std::optional invertModelScale; - // Set if invisible parts (parts with no textures or materials) of the model - // should be forced to render or not. - std::optional forceRenderInvisible; - // Contains information about projecting onto this planet. ghoul::Dictionary projection [[codegen::reference("spacecraftinstruments_projectioncomponent")]]; @@ -122,21 +116,11 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di { const Parameters p = codegen::bake(dictionary); - if (p.forceRenderInvisible.has_value()) { - _forceRenderInvisible = *p.forceRenderInvisible; - - if (!_forceRenderInvisible) { - // Asset file have specifically said to not render invisible parts, - // do not notify in the log if invisible parts are detected and dropped - _notifyInvisibleDropped = false; - } - } - std::filesystem::path file = absPath(p.geometryFile.string()); _geometry = ghoul::io::ModelReader::ref().loadModel( file.string(), - ghoul::io::ModelReader::ForceRenderInvisible(_forceRenderInvisible), - ghoul::io::ModelReader::NotifyInvisibleDropped(_notifyInvisibleDropped) + ghoul::io::ModelReader::ForceRenderInvisible::No, + ghoul::io::ModelReader::NotifyInvisibleDropped::Yes ); _invertModelScale = p.invertModelScale.value_or(_invertModelScale); @@ -216,9 +200,8 @@ void RenderableModelProjection::initializeGL() { _projectionComponent.initializeGL(); - double bs = boundingSphere(); _geometry->initialize(); - setBoundingSphere(bs); // ignore bounding sphere set by geometry. + setBoundingSphere(_geometry->boundingRadius() * _modelScale); // Set Interaction sphere size to be 10% of the bounding sphere setInteractionSphere(_boundingSphere * 0.1); @@ -280,7 +263,8 @@ void RenderableModelProjection::render(const RenderData& data, RendererTasks&) { const glm::dmat4 transform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * glm::dmat4(data.modelTransform.rotation) * - glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * + glm::scale(glm::dmat4(1.0), glm::dvec3(_modelScale)); const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * transform; // malej 2023-FEB-23: The light sources should probably not be hard coded diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h index 14627c14ea..c2b70bbc86 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.h +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.h @@ -73,10 +73,9 @@ private: ProjectionComponent _projectionComponent; std::unique_ptr _programObject; - UniformCache(modelViewTransform, projectionTransform, meshTransform, - meshNormalTransform, has_texture_diffuse, baseTexture, baseColor, - projectionTexture, performShading, projectionFading, - directionToSunViewSpace) _mainUniformCache; + UniformCache(performShading, directionToSunViewSpace, modelViewTransform, + projectionTransform, projectionFading, baseTexture, + projectionTexture) _mainUniformCache; std::unique_ptr _fboProgramObject; UniformCache(projectionTexture, depthTexture, needShadowMap, ProjectorMatrix, @@ -87,8 +86,6 @@ private: std::unique_ptr _geometry; double _modelScale = 1.0; bool _invertModelScale = false; - bool _forceRenderInvisible = false; - bool _notifyInvisibleDropped = true; glm::dmat3 _instrumentMatrix = glm::dmat3(1.0); From 6c56630217386819da0eebee5781b39133d95a55 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 3 Apr 2023 11:31:49 +0200 Subject: [PATCH 61/68] Set model boundingsphere in initialize instead of update --- modules/base/rendering/renderablemodel.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index aeeb06e12c..91766ff128 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -631,6 +631,10 @@ void RenderableModel::initializeGL() { // Initialize geometry _geometry->initialize(); _geometry->calculateBoundingRadius(); + setBoundingSphere(_geometry->boundingRadius() * _modelScale); + + // Set Interaction sphere size to be 10% of the bounding sphere + setInteractionSphere(_boundingSphere * 0.1); } void RenderableModel::deinitializeGL() { @@ -916,12 +920,6 @@ void RenderableModel::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } - setBoundingSphere(_geometry->boundingRadius() * _modelScale * - glm::compMax(data.modelTransform.scale) - ); - // Set Interaction sphere size to be 10% of the bounding sphere - setInteractionSphere(_boundingSphere * 0.1); - if (_geometry->hasAnimation() && !_animationStart.empty()) { double relativeTime; double now = data.time.j2000Seconds(); From 1d923833175db79569101d60aa5ed87d2ff0162b Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 6 Apr 2023 14:53:05 +0200 Subject: [PATCH 62/68] Make sure RenderBin is set before render function is called --- modules/base/rendering/renderablemodel.cpp | 23 +++++++++++----------- modules/base/rendering/renderablemodel.h | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 91766ff128..9ef42fcbc9 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -773,18 +773,8 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glDisable(GL_DEPTH_TEST); } - // Only render two pass if the model is in any way transparent - bool shouldRenderTwice = false; - const float o = opacity(); - if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { - setRenderBin(Renderable::RenderBin::PostDeferredTransparent); - shouldRenderTwice = true; - } - else { - setRenderBin(_originalRenderBin); - } - if (!shouldRenderTwice) { + if (!_shouldRenderTwice) { // Reset manual depth test _program->setUniform( _uniformCache.performManualDepthTest, @@ -920,6 +910,17 @@ void RenderableModel::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } + // Only render two pass if the model is in any way transparent + const float o = opacity(); + if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { + setRenderBin(Renderable::RenderBin::PostDeferredTransparent); + _shouldRenderTwice = true; + } + else { + setRenderBin(_originalRenderBin); + _shouldRenderTwice = false; + } + if (_geometry->hasAnimation() && !_animationStart.empty()) { double relativeTime; double now = data.time.j2000Seconds(); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 9f1d820ea3..be2203f466 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -120,6 +120,7 @@ private: GLuint _framebuffer = 0; GLuint _quadVao = 0; GLuint _quadVbo = 0; + bool _shouldRenderTwice = false; // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; From 94e8f90d1a25889effd4b2654e02ce94d22a3abd Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 12 Apr 2023 16:50:08 +0200 Subject: [PATCH 63/68] Take into account the scale in the gui when calculating distance culling --- modules/base/rendering/renderablemodel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 9ef42fcbc9..d359516e42 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -683,7 +683,8 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Formula from RenderableGlobe constexpr double tfov = 0.5773502691896257; constexpr int res = 2880; - const double maxDistance = res * boundingSphere() / tfov; + const double maxDistance = + res * boundingSphere() * glm::compMax(data.modelTransform.scale) / tfov; // Don't render if model is too far away if (distanceToCamera >= maxDistance) { From 6d8f7b2fbd5bb0c0ce4f51519340c311ce9c6ced Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 13 Apr 2023 10:59:23 +0200 Subject: [PATCH 64/68] Handle override RenderBins from asset files --- include/openspace/rendering/renderable.h | 2 + modules/base/rendering/renderablemodel.cpp | 48 ++++++++++++++++------ modules/base/rendering/renderablemodel.h | 2 +- modules/base/shaders/model_fs.glsl | 5 ++- src/rendering/renderable.cpp | 5 +++ 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index 181390083a..3e98be8cc6 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -131,6 +131,7 @@ protected: SceneGraphNode* parent() const noexcept; bool automaticallyUpdatesRenderBin() const noexcept; + bool hasOverrideRenderBin() const noexcept; RenderBin _renderBin = RenderBin::Opaque; @@ -146,6 +147,7 @@ private: SceneGraphNode* _parent = nullptr; const bool _shouldUpdateIfDisabled = false; bool _automaticallyUpdateRenderBin = true; + bool _hasOverrideRenderBin = false; // We only want the SceneGraphNode to be able manipulate the parent, so we don't want // to provide a set method for this. Otherwise, anyone might mess around with our diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index b34ab5247d..2479ca13c0 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -73,12 +73,12 @@ namespace { GL_COLOR_ATTACHMENT2, }; - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "nLightSources", "lightDirectionsViewSpace", "lightIntensities", "modelViewTransform", "normalTransform", "projectionTransform", "performShading", "ambientIntensity", "diffuseIntensity", "specularIntensity", "performManualDepthTest", "gBufferDepthTexture", - "resolution" + "resolution", "opacity" }; constexpr std::array UniformOpacityNames = { @@ -273,7 +273,7 @@ documentation::Documentation RenderableModel::Documentation() { } RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) + : Renderable(dictionary, { .automaticallyUpdateRenderBin = false }) , _enableAnimation(EnableAnimationInfo, false) , _ambientIntensity(AmbientIntensityInfo, 0.2f, 0.f, 1.f) , _diffuseIntensity(DiffuseIntensityInfo, 1.f, 0.f, 1.f) @@ -781,6 +781,21 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { false ); + if (hasOverrideRenderBin()) { + // If override render bin is set then use the opacity values as normal + _program->setUniform( + _uniformCache.opacity, + opacity() + ); + } + else { + // Otherwise reset + _program->setUniform( + _uniformCache.opacity, + 1.f + ); + } + _geometry->render(*_program); } else { @@ -832,6 +847,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { glm::vec2(global::windowDelegate->currentDrawBufferResolution()) ); + // Make sure opacity in first pass is always 1 + _program->setUniform( + _uniformCache.opacity, + 1.f + ); + // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity _geometry->render(*_program); @@ -910,17 +931,20 @@ void RenderableModel::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); } - // Only render two pass if the model is in any way transparent - const float o = opacity(); - if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { - setRenderBin(Renderable::RenderBin::PostDeferredTransparent); - _shouldRenderTwice = true; - } - else { - setRenderBin(_originalRenderBin); - _shouldRenderTwice = false; + if (!hasOverrideRenderBin()) { + // Only render two pass if the model is in any way transparent + const float o = opacity(); + if ((o >= 0.f && o < 1.f) || _geometry->isTransparent()) { + setRenderBin(Renderable::RenderBin::PostDeferredTransparent); + _shouldRenderTwice = true; + } + else { + setRenderBin(_originalRenderBin); + _shouldRenderTwice = false; + } } + if (_geometry->hasAnimation() && !_animationStart.empty()) { double relativeTime; double now = data.time.j2000Seconds(); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index be2203f466..11b11e0155 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -106,7 +106,7 @@ private: modelViewTransform, normalTransform, projectionTransform, performShading, ambientIntensity, diffuseIntensity, specularIntensity, performManualDepthTest, gBufferDepthTexture, - resolution) _uniformCache; + resolution, opacity) _uniformCache; std::vector> _lightSources; diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 857b365b3c..8b6d2eced5 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -44,6 +44,7 @@ uniform bool has_color_specular; uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; +uniform float opacity = 1.0; uniform vec4 color_diffuse; uniform vec4 color_specular; @@ -63,7 +64,7 @@ Fragment getFragment() { frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); frag.disableLDR2HDR = true; - frag.color.a = 1.0; + frag.color.a = opacity; if (performManualDepthTest) { // gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to @@ -160,6 +161,6 @@ Fragment getFragment() { frag.color.rgb = diffuseAlbedo.rgb; } - frag.color.a = diffuseAlbedo.a; + frag.color.a = diffuseAlbedo.a * opacity; return frag; } diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 8c8c15c4af..aa5309b6eb 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -150,6 +150,7 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary, Settings settings) if (p.renderBinMode.has_value()) { _automaticallyUpdateRenderBin = false; + _hasOverrideRenderBin = true; setRenderBin(codegen::map(*p.renderBinMode)); } @@ -326,4 +327,8 @@ bool Renderable::automaticallyUpdatesRenderBin() const noexcept { return _automaticallyUpdateRenderBin; } +bool Renderable::hasOverrideRenderBin() const noexcept { + return _hasOverrideRenderBin; +} + } // namespace openspace From 71caf31f02fb76fbe9f3d4e7cd3ab12dd07f8989 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 13 Apr 2023 11:27:11 +0200 Subject: [PATCH 65/68] Small clean up --- data/assets/examples/animation.asset | 15 +++++---------- data/assets/examples/approachevents.asset | 3 +-- data/assets/examples/modelshader/model_fs.glsl | 3 ++- .../scene/solarsystem/missions/dawn/dawn.asset | 2 +- .../scene/solarsystem/missions/dawn/vesta.asset | 2 +- .../planets/earth/satellites/misc/iss.asset | 2 +- modules/base/shaders/model_fs.glsl | 2 +- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/data/assets/examples/animation.asset b/data/assets/examples/animation.asset index 8ab005c037..7dc15495c2 100644 --- a/data/assets/examples/animation.asset +++ b/data/assets/examples/animation.asset @@ -28,8 +28,7 @@ local animationLoop = { ModelScale = 3E7, LightSources = { sun.LightSource - }, - PerformShading = true + } }, GUI = { Name = "Animated Model example (LoopFromStart)", @@ -56,8 +55,7 @@ local animationLoopInf = { ModelScale = 3E7, LightSources = { sun.LightSource - }, - PerformShading = true + } }, GUI = { Name = "Animated Model example (LoopInfinitely)", @@ -84,8 +82,7 @@ local animationOnce = { ModelScale = 3E7, LightSources = { sun.LightSource - }, - PerformShading = true + } }, GUI = { Name = "Animated Model example (Once)", @@ -112,8 +109,7 @@ local animationBounceInf = { ModelScale = 3E7, LightSources = { sun.LightSource - }, - PerformShading = true + } }, GUI = { Name = "Animated Model example (BounceInfinitely)", @@ -140,8 +136,7 @@ local animationBounce = { ModelScale = 3E7, LightSources = { sun.LightSource - }, - PerformShading = true + } }, GUI = { Name = "Animated Model example (BounceFromStart)", diff --git a/data/assets/examples/approachevents.asset b/data/assets/examples/approachevents.asset index d8db9da578..26b77d9cc7 100644 --- a/data/assets/examples/approachevents.asset +++ b/data/assets/examples/approachevents.asset @@ -35,8 +35,7 @@ local obj = { ModelScale = 1000, LightSources = { sun.LightSource - }, - PerformShading = true + } }, InteractionSphere = 900, ApproachFactor = 50.0, diff --git a/data/assets/examples/modelshader/model_fs.glsl b/data/assets/examples/modelshader/model_fs.glsl index 0973172d93..09d448619a 100644 --- a/data/assets/examples/modelshader/model_fs.glsl +++ b/data/assets/examples/modelshader/model_fs.glsl @@ -47,6 +47,7 @@ uniform sampler2D texture_specular; uniform vec3 color_diffuse; uniform vec3 color_specular; +uniform float opacity = 1.0; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; @@ -63,7 +64,7 @@ Fragment getFragment() { frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); frag.disableLDR2HDR = true; - frag.color.a = 1.0; + frag.color.a = opacity; if (performManualDepthTest) { // gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to diff --git a/data/assets/scene/solarsystem/missions/dawn/dawn.asset b/data/assets/scene/solarsystem/missions/dawn/dawn.asset index fedc5a04c1..42285429f4 100644 --- a/data/assets/scene/solarsystem/missions/dawn/dawn.asset +++ b/data/assets/scene/solarsystem/missions/dawn/dawn.asset @@ -215,7 +215,7 @@ end asset.meta = { Name = "Dawn", - Version = "1.0", + Version = "2.0", Description = "Dawn spacecraft and trail", Author = "OpenSpace Team", URL = "http://openspaceproject.com", diff --git a/data/assets/scene/solarsystem/missions/dawn/vesta.asset b/data/assets/scene/solarsystem/missions/dawn/vesta.asset index 543245f3da..b70a62a4fa 100644 --- a/data/assets/scene/solarsystem/missions/dawn/vesta.asset +++ b/data/assets/scene/solarsystem/missions/dawn/vesta.asset @@ -153,7 +153,7 @@ asset.export(VestaTrail) asset.meta = { Name = "Vesta", - Version = "1.0", + Version = "1.1", Description = "Vesta model projection and trail", Author = "OpenSpace Team", URL = "http://openspaceproject.com", diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 5df3ea5861..b257dc2599 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -156,7 +156,7 @@ asset.export(issPosition) asset.meta = { Name = "ISS", - Version = "1.1", + Version = "2.0", Description = [[Model and Trail for ISS. Model from NASA 3D models, trail from Celestrak.]], Author = "OpenSpace Team", diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index 8b6d2eced5..0c3108274a 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -44,10 +44,10 @@ uniform bool has_color_specular; uniform sampler2D texture_diffuse; uniform sampler2D texture_normal; uniform sampler2D texture_specular; -uniform float opacity = 1.0; uniform vec4 color_diffuse; uniform vec4 color_specular; +uniform float opacity = 1.0; uniform int nLightSources; uniform vec3 lightDirectionsViewSpace[8]; From a017006ec60ae5dbb6b3b64078d7c45364e4ab92 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 13 Apr 2023 12:35:51 +0200 Subject: [PATCH 66/68] Add todo comment from discussion in PR --- modules/base/rendering/renderablemodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 2479ca13c0..db610f75e9 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -682,6 +682,9 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { // Formula from RenderableGlobe constexpr double tfov = 0.5773502691896257; constexpr int res = 2880; + + // @TODO (malej 13-APR-23): This should only use the boundingSphere function once + // that takes the gui scale into account too for all renderables const double maxDistance = res * boundingSphere() * glm::compMax(data.modelTransform.scale) / tfov; From c2457e5c41c68b49843efbfc9fe91d7d6649536f Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 13 Apr 2023 14:54:49 +0200 Subject: [PATCH 67/68] Address PR comments --- modules/base/rendering/renderablemodel.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index db610f75e9..6b2c82319c 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -786,17 +786,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { if (hasOverrideRenderBin()) { // If override render bin is set then use the opacity values as normal - _program->setUniform( - _uniformCache.opacity, - opacity() - ); + _program->setUniform(_uniformCache.opacity, opacity()); } else { - // Otherwise reset - _program->setUniform( - _uniformCache.opacity, - 1.f - ); + // Otherwise reset to 1 + _program->setUniform(_uniformCache.opacity, 1.f); } _geometry->render(*_program); @@ -851,10 +845,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ); // Make sure opacity in first pass is always 1 - _program->setUniform( - _uniformCache.opacity, - 1.f - ); + _program->setUniform(_uniformCache.opacity, 1.f); // Render Pass 1 // Render all parts of the model into the new framebuffer without opacity From 2f19e7712f19074a5b7206d8a3c2c4cf584a9a7e Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 13 Apr 2023 17:24:55 +0200 Subject: [PATCH 68/68] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 0bf5aa66c6..eb435c3bb9 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 0bf5aa66c67873d5e859bc040c164bf000b40a15 +Subproject commit eb435c3bb9847320cd59d3ee978132ee171b7fb9