Viewing Map.

This commit is contained in:
Jonathas Costa
2019-11-15 17:32:43 -05:00
parent 7a893e04c5
commit 74c754d923
5 changed files with 129 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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<Camera> _lightCamera;
// DEBUG
bool _executeDepthTextureSave;
bool _executeDepthTextureSave = false;
bool _viewDepthMap = false;
std::unique_ptr<ghoul::opengl::ProgramObject> _renderDMProgram;
GLuint _quadVAO = 0u;
};