mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 10:59:47 -05:00
Fixed issue 1432: globebrowsing and shadow mapping. (#1433)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user