Fixed issue 1432: globebrowsing and shadow mapping. (#1433)

This commit is contained in:
Jonathas Costa
2020-12-09 12:36:23 -05:00
committed by GitHub
parent eb69d2219a
commit c13b211add
4 changed files with 54 additions and 2 deletions
@@ -1399,6 +1399,13 @@ void RenderableGlobe::renderChunkGlobally(const Chunk& chunk, const RenderData&
program.setUniform("shadowMapTexture", shadowMapUnit);
program.setUniform("zFightingPercentage", _generalProperties.zFightingPercentage);
}
else if (_generalProperties.shadowMapping) {
shadowMapUnit.activate();
// JCC: Avoiding a to recompiling the shaders or having more than one
// set of shaders for this step.
glBindTexture(GL_TEXTURE_2D, _shadowComponent.dDepthTexture());
program.setUniform("shadowMapTexture", shadowMapUnit);
}
glEnable(GL_DEPTH_TEST);
@@ -1530,6 +1537,13 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
program.setUniform("shadowMapTexture", shadowMapUnit);
program.setUniform("zFightingPercentage", _generalProperties.zFightingPercentage);
}
else if (_generalProperties.shadowMapping) {
shadowMapUnit.activate();
// JCC: Avoiding a to recompiling the shaders or having more than one
// set of shaders for this step.
glBindTexture(GL_TEXTURE_2D, _shadowComponent.dDepthTexture());
program.setUniform("shadowMapTexture", shadowMapUnit);
}
glEnable(GL_DEPTH_TEST);
+1 -1
View File
@@ -364,7 +364,7 @@ void RingsComponent::draw(const RenderData& data,
ringTextureUnit.activate();
_texture->bind();
_shader->setUniform(_geomUniformCache.ringTexture, ringTextureUnit);
_geometryOnlyShader->setUniform(_geomUniformCache.ringTexture, ringTextureUnit);
}
glEnable(GL_DEPTH_TEST);
+33 -1
View File
@@ -220,7 +220,9 @@ ShadowComponent::ShadowComponent(const ghoul::Dictionary& dictionary)
addProperty(_distanceFraction);
}
void ShadowComponent::initialize() {}
void ShadowComponent::initialize() {
buildDDepthTexture();
}
bool ShadowComponent::isReady() const {
return true;
@@ -236,6 +238,7 @@ void ShadowComponent::initializeGL() {
void ShadowComponent::deinitializeGL() {
glDeleteTextures(1, &_shadowDepthTexture);
glDeleteTextures(1, &_positionInLightSpaceTexture);
glDeleteTextures(1, &_dDepthTexture);
glDeleteFramebuffers(1, &_shadowFBO);
}
@@ -544,6 +547,31 @@ void ShadowComponent::updateDepthTexture() {
glBindTexture(GL_TEXTURE_2D, 0);
}
void ShadowComponent::buildDDepthTexture() {
glGenTextures(1, &_dDepthTexture);
glBindTexture(GL_TEXTURE_2D, _dDepthTexture);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT32F,
1,
1,
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
nullptr
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glBindTexture(GL_TEXTURE_2D, 0);
}
void ShadowComponent::saveDepthBuffer() {
int size = _shadowDepthTextureWidth * _shadowDepthTextureHeight;
std::vector<GLubyte> buffer(size);
@@ -652,4 +680,8 @@ void ShadowComponent::setViewDepthMap(bool enable) {
_viewDepthMap = enable;
}
GLuint ShadowComponent::dDepthTexture() const {
return _dDepthTexture;
}
} // namespace openspace
@@ -79,10 +79,13 @@ public:
void setViewDepthMap(bool enable);
GLuint dDepthTexture() const;
private:
void createDepthTexture();
void createShadowFBO();
void updateDepthTexture();
void buildDDepthTexture();
// Debug
void saveDepthBuffer();
@@ -109,6 +112,9 @@ private:
bool _dynamicDepthTextureRes = true;
GLuint _shadowDepthTexture = 0;
// JCC: Used to avoid recompilation of Globebrowsing's shaders
// and incorrect binding of texture type
GLuint _dDepthTexture = 0;
GLuint _positionInLightSpaceTexture = 0;
GLuint _shadowFBO = 0;
GLint _defaultFBO = 0;