diff --git a/modules/globebrowsing/shaders/smviewer_fs.glsl b/modules/globebrowsing/shaders/smviewer_fs.glsl new file mode 100644 index 0000000000..be189229f1 --- /dev/null +++ b/modules/globebrowsing/shaders/smviewer_fs.glsl @@ -0,0 +1,38 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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 "PowerScaling/powerScaling_fs.hglsl" +#include "fragment.glsl" + +in vec2 texCoord; + +uniform sampler2D shadowMapTexture; + +Fragment getFragment() { + Fragment frag; + frag.color = vec4(vec3(1.f) - texture(shadowMapTexture, texCoord).rrr, 1.f); + frag.depth = 0.f; + + return frag; +} diff --git a/modules/globebrowsing/shaders/smviewer_vs.glsl b/modules/globebrowsing/shaders/smviewer_vs.glsl new file mode 100644 index 0000000000..a69397368e --- /dev/null +++ b/modules/globebrowsing/shaders/smviewer_vs.glsl @@ -0,0 +1,51 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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__ + +out vec2 texCoord; + +const vec3 posData[6] = vec3[] ( + vec3(1.0, -0.5, 0.0), + vec3(0.5, -0.5, 0.0), + vec3(0.5, -1.0, 0.0), + vec3(1.0, -1.0, 0.0), + vec3(1.0, -0.5, 0.0), + vec3(0.5, -1.0, 0.0) +); + +const vec2 texData[6] = vec2[] ( + vec2(1.0, 1.0), + vec2(0.0, 1.0), + vec2(0.0, 0.0), + vec2(1.0, 0.0), + vec2(1.0, 1.0), + vec2(0.0, 0.0) + +); + +void main() { + texCoord = texData[ gl_VertexID ]; + gl_Position = vec4(posData[ gl_VertexID ], 1.0); +} \ No newline at end of file diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 8027d54a55..792bfa3257 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -775,6 +775,8 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask glEnable(GL_BLEND); + _shadowComponent.setViewDepthMap(true); + _shadowComponent.end(); // Render again from original point of view diff --git a/modules/globebrowsing/src/shadowcomponent.cpp b/modules/globebrowsing/src/shadowcomponent.cpp index ec03a3e706..f0fcb217b8 100644 --- a/modules/globebrowsing/src/shadowcomponent.cpp +++ b/modules/globebrowsing/src/shadowcomponent.cpp @@ -406,6 +406,33 @@ namespace openspace { if (_blendIsEnabled) { glEnable(GL_BLEND); } + + if (_viewDepthMap) { + if (!_renderDMProgram) { + _renderDMProgram = global::renderEngine.buildRenderProgram( + "ShadowMappingDebuggingProgram", + absPath("${MODULE_GLOBEBROWSING}/shaders/smviewer_vs.glsl"), + absPath("${MODULE_GLOBEBROWSING}/shaders/smviewer_fs.glsl") + ); + } + + if (!_quadVAO) { + glGenVertexArrays(1, &_quadVAO); + } + + ghoul::opengl::TextureUnit shadowMapUnit; + shadowMapUnit.activate(); + glBindTexture(GL_TEXTURE_2D, _shadowDepthTexture); + + _renderDMProgram->activate(); + + _renderDMProgram->setUniform("shadowMapTexture", shadowMapUnit); + + glBindVertexArray(_quadVAO); + glDrawArrays(GL_TRIANGLES, 0, 6); + + _renderDMProgram->deactivate(); + } } void ShadowComponent::update(const UpdateData& /*data*/) { @@ -655,4 +682,8 @@ namespace openspace { ShadowComponent::ShadowMapData ShadowComponent::shadowMapData() const { return _shadowData; } + + void ShadowComponent::setViewDepthMap(bool enable) { + _viewDepthMap = enable; + } } // namespace openspace diff --git a/modules/globebrowsing/src/shadowcomponent.h b/modules/globebrowsing/src/shadowcomponent.h index bfdbb7c0b5..5391e7714a 100644 --- a/modules/globebrowsing/src/shadowcomponent.h +++ b/modules/globebrowsing/src/shadowcomponent.h @@ -81,13 +81,15 @@ namespace openspace { RenderData begin(const RenderData& data); void end(); void update(const UpdateData& data); - + static documentation::Documentation Documentation(); bool isEnabled() const; ShadowComponent::ShadowMapData shadowMapData() const; + void setViewDepthMap(bool enable); + private: void createDepthTexture(); void createShadowFBO(); @@ -152,7 +154,10 @@ namespace openspace { std::unique_ptr _lightCamera; // DEBUG - bool _executeDepthTextureSave; + bool _executeDepthTextureSave = false; + bool _viewDepthMap = false; + std::unique_ptr _renderDMProgram; + GLuint _quadVAO = 0u; };