mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-06 11:29:55 -05:00
Improved performance. Clean up.
This commit is contained in:
@@ -27,13 +27,10 @@
|
||||
|
||||
in vec2 vs_st;
|
||||
in float vs_screenSpaceDepth;
|
||||
in vec4 vs_positionViewSpace;
|
||||
in vec4 shadowCoords;
|
||||
|
||||
uniform sampler2D shadowPositionTexture;
|
||||
|
||||
uniform sampler2DShadow shadowMap;
|
||||
uniform sampler1D texture1;
|
||||
uniform sampler2DShadow shadowMapTexture;
|
||||
uniform sampler1D ringTexture;
|
||||
uniform vec2 textureOffset;
|
||||
uniform float transparency;
|
||||
|
||||
@@ -64,7 +61,7 @@ Fragment getFragment() {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 diffuse = texture(texture1, texCoord);
|
||||
vec4 diffuse = texture(ringTexture, texCoord);
|
||||
float colorValue = length(diffuse.rgb);
|
||||
// times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want
|
||||
// to normalize the transparency value to [0,1]
|
||||
@@ -76,30 +73,12 @@ Fragment getFragment() {
|
||||
float shadow = 1.0;
|
||||
if ( shadowCoords.z >= 0 ) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.z = normalizeFloat(normalizedShadowCoords.w - 0.3);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
shadow = textureProj(shadowMap, normalizedShadowCoords);
|
||||
//shadow = textureProj(shadowMap, shadowCoords);
|
||||
shadow = textureProj(shadowMapTexture, normalizedShadowCoords);
|
||||
}
|
||||
|
||||
// shadow = 1.0;
|
||||
// vec4 depthInTexture = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
// //if (shadowCoords.z >= 0) {
|
||||
// if (true) {
|
||||
// vec4 byHandCoords = shadowCoords / shadowCoords.w;
|
||||
// // Distance of the current pixel from the light source
|
||||
// depthInTexture = texture(shadowPositionTexture, byHandCoords.xy);
|
||||
// //depthInTexture = texture(shadowPositionTexture, vec2(0.5, 0.5));
|
||||
// // if (depthInTexture.x < byHandCoords.z) {
|
||||
// // shadow = 0.0;
|
||||
// // }
|
||||
// if (length(fragPosInLightSpace) > depthInTexture.x) {
|
||||
// shadow = 0.2;
|
||||
// }
|
||||
// //shadow = length(fragPosInLightSpace);
|
||||
// }
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
vec3 normal;
|
||||
@@ -119,15 +98,10 @@ Fragment getFragment() {
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
//frag.color = depthInTexture;
|
||||
|
||||
frag.color = (0.55 * diffuse * shadow) + diffuse * 0.45;
|
||||
//frag.color = vec4(shadow * vec3(1.0, 1.0, 1.0), 1.0);
|
||||
//frag.depth = vs_position.w;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
if (diffuse.a < 1.0)
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
else
|
||||
frag.gPosition = vs_positionViewSpace;
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
frag.gNormal = vec4(normal, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
in vec2 vs_st;
|
||||
in float vs_screenSpaceDepth;
|
||||
in vec4 vs_positionViewSpace;
|
||||
|
||||
uniform vec2 textureOffset;
|
||||
|
||||
@@ -66,8 +65,6 @@ Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color = vec4(vec3(vs_screenSpaceDepth), 1.0);
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
//renderedPosition = vec4(vec3(length(vs_positionViewSpace.xyz)), 1.0);//vec4(vs_positionViewSpace.xyz, 1.0);
|
||||
//renderedPosition = vec4(vec3(vs_screenSpaceDepth.w)/10.0, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -31,21 +31,17 @@ layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out float vs_screenSpaceDepth;
|
||||
out vec4 vs_positionViewSpace;
|
||||
|
||||
uniform dmat4 modelViewMatrix;
|
||||
uniform dmat4 projectionMatrix;
|
||||
uniform dmat4 modelViewProjectionMatrix;
|
||||
|
||||
void main() {
|
||||
vs_st = in_st;
|
||||
|
||||
dvec4 positionViewSpace = modelViewMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpace = vec4(projectionMatrix * positionViewSpace);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(positionClipSpace);
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix *
|
||||
dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
vs_positionViewSpace = vec4(positionViewSpace);
|
||||
|
||||
//gl_Position = positionClipSpaceZNorm;
|
||||
gl_Position = positionClipSpace;
|
||||
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
}
|
||||
@@ -34,12 +34,7 @@ out float vs_screenSpaceDepth;
|
||||
out vec4 vs_positionViewSpace;
|
||||
out vec4 shadowCoords;
|
||||
|
||||
// temp
|
||||
out vec4 fragPosInLightSpace;
|
||||
uniform dmat4 objectToLightSpaceMatrix;
|
||||
|
||||
uniform dmat4 modelViewMatrix;
|
||||
uniform dmat4 projectionMatrix;
|
||||
uniform dmat4 modelViewProjectionMatrix;
|
||||
|
||||
// ShadowMatrix is the matrix defined by:
|
||||
// textureCoordsMatrix * projectionMatrix * combinedViewMatrix * modelMatrix
|
||||
@@ -50,18 +45,13 @@ uniform dmat4 shadowMatrix;
|
||||
void main() {
|
||||
vs_st = in_st;
|
||||
|
||||
dvec4 positionViewSpace = modelViewMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpace = vec4(projectionMatrix * positionViewSpace);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(positionClipSpace);
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix *
|
||||
dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(in_position, 0.0, 1.0));
|
||||
// temp
|
||||
fragPosInLightSpace = vec4(objectToLightSpaceMatrix *
|
||||
dvec4(in_position.xy, 0.0, 1.0));
|
||||
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
vs_positionViewSpace = vec4(positionViewSpace);
|
||||
|
||||
//gl_Position = positionClipSpaceZNorm;
|
||||
gl_Position = positionClipSpace;
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
}
|
||||
|
||||
@@ -687,9 +687,10 @@ void RenderableGlobe::initializeGL() {
|
||||
|
||||
_grid.initializeGL();
|
||||
|
||||
_ringsComponent.initializeGL();
|
||||
|
||||
_shadowComponent.initializeGL();
|
||||
if (_hasRings) {
|
||||
_ringsComponent.initializeGL();
|
||||
_shadowComponent.initializeGL();
|
||||
}
|
||||
|
||||
// Recompile the shaders directly so that it is not done the first time the render
|
||||
// function is called.
|
||||
@@ -713,9 +714,10 @@ void RenderableGlobe::deinitializeGL() {
|
||||
|
||||
_grid.deinitializeGL();
|
||||
|
||||
_ringsComponent.deinitializeGL();
|
||||
|
||||
_shadowComponent.deinitializeGL();
|
||||
if (_hasRings) {
|
||||
_ringsComponent.deinitializeGL();
|
||||
_shadowComponent.deinitializeGL();
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderableGlobe::isReady() const {
|
||||
@@ -746,21 +748,18 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask
|
||||
if (_hasRings && _ringsComponent.isEnabled()) {
|
||||
if (_shadowComponent.isEnabled()) {
|
||||
|
||||
// Render from light source point of view
|
||||
// Set matrices and other GL states
|
||||
RenderData lightRenderData(_shadowComponent.begin(data));
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(2.5f, 10.0f);
|
||||
|
||||
|
||||
// Render from light source point of view
|
||||
renderChunks(lightRenderData, rendererTask, true);
|
||||
_ringsComponent.draw(lightRenderData, RingsComponent::GeometryOnly);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
_shadowComponent.end(data);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
_shadowComponent.end();
|
||||
|
||||
// Render again from original point of view
|
||||
renderChunks(data, rendererTask);
|
||||
|
||||
@@ -56,13 +56,13 @@
|
||||
#include <locale>
|
||||
|
||||
namespace {
|
||||
constexpr const std::array<const char*, 7> UniformNames = {
|
||||
"modelViewMatrix", "projectionMatrix", "textureOffset",
|
||||
"transparency", "_nightFactor", "sunPosition", "texture1"
|
||||
constexpr const std::array<const char*, 8> UniformNames = {
|
||||
"modelViewProjectionMatrix", "textureOffset", "transparency", "_nightFactor",
|
||||
"sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture"
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 3> GeomUniformNames = {
|
||||
"modelViewMatrix", "projectionMatrix", "textureOffset"
|
||||
constexpr const std::array<const char*, 2> GeomUniformNames = {
|
||||
"modelViewProjectionMatrix", "textureOffset"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo TextureInfo = {
|
||||
@@ -273,50 +273,44 @@ namespace openspace {
|
||||
glm::dmat4(data.modelTransform.rotation) *
|
||||
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
|
||||
|
||||
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
const glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix());
|
||||
const glm::dmat4 modelViewProjectionTransform =
|
||||
glm::dmat4(data.camera.projectionMatrix()) * data.camera.combinedViewMatrix()
|
||||
* modelTransform;
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
if (renderPass == GeometryAndShading) {
|
||||
_shader->setUniform(_uniformCache.modelViewMatrix, modelViewTransform);
|
||||
_shader->setUniform(_uniformCache.projectionMatrix, projectionMatrix);
|
||||
_shader->setUniform(
|
||||
_uniformCache.modelViewProjectionMatrix,
|
||||
modelViewProjectionTransform
|
||||
);
|
||||
_shader->setUniform(_uniformCache.textureOffset, _offset);
|
||||
_shader->setUniform(_uniformCache.transparency, _transparency);
|
||||
_shader->setUniform(_uniformCache.nightFactor, _nightFactor);
|
||||
_shader->setUniform(_uniformCache.sunPosition, _sunPosition);
|
||||
|
||||
unit.activate();
|
||||
ghoul::opengl::TextureUnit ringTextureUnit;
|
||||
ringTextureUnit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform(_uniformCache.texture, unit);
|
||||
_shader->setUniform(_uniformCache.ringTexture, ringTextureUnit);
|
||||
|
||||
// Adding the model transformation to the final shadow matrix so we have a
|
||||
// complete transformation from the model coordinates to the clip space of
|
||||
// the light position.
|
||||
_shader->setUniform("shadowMatrix", shadowData.shadowMatrix * modelTransform);
|
||||
_shader->setUniform(
|
||||
_uniformCache.shadowMatrix,
|
||||
shadowData.shadowMatrix * modelTransform
|
||||
);
|
||||
|
||||
ghoul::opengl::TextureUnit shadowMapUnit;
|
||||
shadowMapUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture);
|
||||
|
||||
_shader->setUniform("shadowMap", shadowMapUnit);
|
||||
|
||||
// DEBUGGING
|
||||
ghoul::opengl::TextureUnit shadowTextureUnit;
|
||||
shadowTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, shadowData.positionInLightSpaceTexture);
|
||||
_shader->setUniform("shadowPositionTexture", shadowTextureUnit);
|
||||
_shader->setUniform("objectToLightSpaceMatrix",
|
||||
shadowData.worldToLightSpaceMatrix * modelTransform);
|
||||
_shader->setUniform(_uniformCache.shadowMapTexture, shadowMapUnit);
|
||||
|
||||
}
|
||||
else if (renderPass == GeometryOnly) {
|
||||
_geometryOnlyShader->setUniform(
|
||||
_geomUniformCache.modelViewMatrix,
|
||||
modelViewTransform
|
||||
);
|
||||
_geometryOnlyShader->setUniform(
|
||||
_geomUniformCache.projectionMatrix,
|
||||
projectionMatrix
|
||||
_geomUniformCache.modelViewProjectionMatrix,
|
||||
modelViewProjectionTransform
|
||||
);
|
||||
_geometryOnlyShader->setUniform(
|
||||
_geomUniformCache.textureOffset,
|
||||
|
||||
@@ -95,9 +95,10 @@ namespace openspace {
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _geometryOnlyShader;
|
||||
UniformCache(modelViewMatrix, projectionMatrix, textureOffset,
|
||||
transparency, nightFactor, sunPosition, texture) _uniformCache;
|
||||
UniformCache(modelViewMatrix, projectionMatrix, textureOffset) _geomUniformCache;
|
||||
UniformCache(modelViewProjectionMatrix, textureOffset, transparency, nightFactor,
|
||||
sunPosition, ringTexture, shadowMatrix, shadowMapTexture
|
||||
) _uniformCache;
|
||||
UniformCache(modelViewProjectionMatrix, textureOffset) _geomUniformCache;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _textureFile;
|
||||
|
||||
|
||||
@@ -165,11 +165,11 @@ namespace openspace {
|
||||
ShadowComponent::ShadowComponent(const ghoul::Dictionary& dictionary)
|
||||
: properties::PropertyOwner({ "Shadows" })
|
||||
, _saveDepthTexture(SaveDepthTextureInfo)
|
||||
, _distanceFraction(DistanceFractionInfo, 30, 1, 100000)
|
||||
, _distanceFraction(DistanceFractionInfo, 30, 1, 1000)
|
||||
, _enabled({ "Enabled", "Enabled", "Enable/Disable Shadows" }, true)
|
||||
, _shadowMapDictionary(dictionary)
|
||||
, _shadowDepthTextureHeight(1024)
|
||||
, _shadowDepthTextureWidth(1024)
|
||||
, _shadowDepthTextureHeight(4096)
|
||||
, _shadowDepthTextureWidth(4096)
|
||||
, _shadowDepthTexture(-1)
|
||||
, _positionInLightSpaceTexture(-1)
|
||||
, _shadowFBO(-1)
|
||||
@@ -252,35 +252,6 @@ namespace openspace {
|
||||
//// Light Position
|
||||
//glm::dvec3 lightPosition = glm::dvec3(_sunPosition);
|
||||
|
||||
// Saving current Camera parameters
|
||||
_cameraPos = data.camera.positionVec3();
|
||||
// JCC: We have aim and ancor nodes and position now. Need to fix this.
|
||||
//_cameraFocus = data.camera.focusPositionVec3();
|
||||
|
||||
//const SceneGraphNode * origAimNode = global::navigationHandler.orbitalNavigator().aimNode();
|
||||
//const SceneGraphNode * origAnchorNode = global::navigationHandler.orbitalNavigator().anchorNode();
|
||||
|
||||
_cameraRotation = data.camera.rotationQuaternion();
|
||||
|
||||
//=============== Automatically Created Camera Matrix ===================
|
||||
//=======================================================================
|
||||
//glm::dmat4 lightViewMatrix = glm::lookAt(
|
||||
// //lightPosition,
|
||||
// glm::dvec3(0.0),
|
||||
// //glm::dvec3(_sunPosition), // position
|
||||
// glm::dvec3(data.modelTransform.translation), // focus
|
||||
// data.camera.lookUpVectorWorldSpace() // up
|
||||
// //glm::dvec3(0.0, 1.0, 0.0)
|
||||
//);
|
||||
|
||||
//camera->setPositionVec3(lightPosition);
|
||||
//camera->setFocusPositionVec3(data.modelTransform.translation);
|
||||
//camera->setRotation(glm::dquat(glm::inverse(lightViewMatrix)));
|
||||
|
||||
//=======================================================================
|
||||
//=======================================================================
|
||||
|
||||
|
||||
//=============== Manually Created Camera Matrix ===================
|
||||
//==================================================================
|
||||
// camera Z
|
||||
@@ -314,16 +285,10 @@ namespace openspace {
|
||||
//matrix[13] = -glm::dot(cameraY, lightPosition);
|
||||
//matrix[14] = -glm::dot(cameraZ, lightPosition);
|
||||
|
||||
/*Scene* scene = camera->parent()->scene();
|
||||
global::navigationHandler.setFocusNode(data.);
|
||||
*/
|
||||
|
||||
_lightCamera = new Camera(data.camera);
|
||||
_lightCamera = std::move(std::unique_ptr<Camera>(new Camera(data.camera)));
|
||||
_lightCamera->setPositionVec3(lightPosition);
|
||||
// JCC: We have aim and ancor nodes and position now. Need to fix this.
|
||||
//camera.setFocusPositionVec3(data.modelTransform.translation);
|
||||
_lightCamera->setRotation(glm::dquat(glm::inverse(cameraRotationMatrix)));
|
||||
|
||||
//=======================================================================
|
||||
//=======================================================================
|
||||
|
||||
@@ -331,9 +296,7 @@ namespace openspace {
|
||||
//============= Light Matrix by Camera Matrices Composition =============
|
||||
//=======================================================================
|
||||
glm::dmat4 lightProjectionMatrix = glm::dmat4(_lightCamera->projectionMatrix());
|
||||
//glm::dmat4 lightProjectionMatrix = glm::ortho(-1000.0, 1000.0, -1000.0, 1000.0, 0.0010, 1000.0);
|
||||
//glm::dmat4 lightProjectionMatrix = glm::frustum(-1.0, 1.0, -1.0, 1.0, 1.0, 1000000.0);
|
||||
|
||||
|
||||
// The model transformation missing in the final shadow matrix is add when rendering each
|
||||
// object (using its transformations provided by the RenderData structure)
|
||||
_shadowData.shadowMatrix =
|
||||
@@ -341,10 +304,7 @@ namespace openspace {
|
||||
lightProjectionMatrix *
|
||||
_lightCamera->combinedViewMatrix();
|
||||
|
||||
// temp
|
||||
_shadowData.worldToLightSpaceMatrix = glm::dmat4(_lightCamera->combinedViewMatrix());
|
||||
|
||||
checkGLError("begin() -- Saving Current GL State");
|
||||
|
||||
// Saves current state
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
|
||||
glGetIntegerv(GL_VIEWPORT, _mViewport);
|
||||
@@ -360,19 +320,15 @@ namespace openspace {
|
||||
_blendIsEnabled = glIsEnabled(GL_BLEND);
|
||||
|
||||
|
||||
checkGLError("begin() -- before binding FBO");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _shadowFBO);
|
||||
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_NONE, GL_NONE };
|
||||
glDrawBuffers(3, drawBuffers);
|
||||
checkGLError("begin() -- after binding FBO");
|
||||
glViewport(0, 0, _shadowDepthTextureWidth, _shadowDepthTextureHeight);
|
||||
checkGLError("begin() -- set new viewport");
|
||||
glClearDepth(1.0f);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
checkGLError("begin() -- after cleanning Depth buffer");
|
||||
|
||||
|
||||
/*glEnable(GL_CULL_FACE);
|
||||
@@ -384,16 +340,6 @@ namespace openspace {
|
||||
glPolygonOffset(2.5f, 10.0f);
|
||||
checkGLError("begin() -- set values for polygon offset");*/
|
||||
|
||||
checkGLError("begin() finished");
|
||||
|
||||
/*RenderData lightRenderData{
|
||||
camera,
|
||||
data.time,
|
||||
data.doPerformanceMeasurement,
|
||||
data.renderBinMask,
|
||||
data.modelTransform
|
||||
};*/
|
||||
|
||||
RenderData lightRenderData{
|
||||
*_lightCamera,
|
||||
data.time,
|
||||
@@ -405,28 +351,18 @@ namespace openspace {
|
||||
return lightRenderData;
|
||||
}
|
||||
|
||||
void ShadowComponent::end(const RenderData& dataOrig) {
|
||||
checkGLError("end() -- Flushing");
|
||||
//glFlush();
|
||||
void ShadowComponent::end() {
|
||||
if (_executeDepthTextureSave) {
|
||||
saveDepthBuffer();
|
||||
_executeDepthTextureSave = false;
|
||||
}
|
||||
|
||||
// Restores Camera Parameters
|
||||
Camera camera = dataOrig.camera;
|
||||
camera.setPositionVec3(_cameraPos);
|
||||
// JCC: We have aim and ancor nodes and position now. Need to fix this.
|
||||
//camera.setFocusPositionVec3(_cameraFocus);
|
||||
camera.setRotation(_cameraRotation);
|
||||
|
||||
// Restores system state
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
|
||||
GLenum drawBuffers[] = {
|
||||
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2
|
||||
};
|
||||
glDrawBuffers(3, drawBuffers);
|
||||
checkGLError("end() -- Rebinding default FBO");
|
||||
glViewport(
|
||||
_mViewport[0],
|
||||
_mViewport[1],
|
||||
@@ -470,8 +406,6 @@ namespace openspace {
|
||||
if (_blendIsEnabled) {
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
checkGLError("end() finished");
|
||||
}
|
||||
|
||||
void ShadowComponent::update(const UpdateData& /*data*/) {
|
||||
@@ -479,7 +413,6 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void ShadowComponent::createDepthTexture() {
|
||||
checkGLError("createDepthTexture() -- Starting configuration");
|
||||
glGenTextures(1, &_shadowDepthTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, _shadowDepthTexture);
|
||||
glTexStorage2D(
|
||||
@@ -501,21 +434,19 @@ namespace openspace {
|
||||
GL_FLOAT,
|
||||
0
|
||||
);*/
|
||||
checkGLError("createDepthTexture() -- Depth testure created");
|
||||
|
||||
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);
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, shadowBorder);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, ShadowBorder);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
checkGLError("createdDepthTexture");
|
||||
|
||||
checkGLError("createDepthTexture() -- Depth testure created");
|
||||
|
||||
glGenTextures(1, &_positionInLightSpaceTexture);
|
||||
/*glGenTextures(1, &_positionInLightSpaceTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, _positionInLightSpaceTexture);
|
||||
//glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
@@ -527,13 +458,11 @@ namespace openspace {
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
checkGLError("createDepthTexture() -- Position/Distance buffer created");
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
checkGLError("createdPositionTexture");
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);*/
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
_shadowData.shadowDepthTexture = _shadowDepthTexture;
|
||||
@@ -544,9 +473,7 @@ namespace openspace {
|
||||
// Saves current FBO first
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
|
||||
|
||||
/*GLint _mViewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, _mViewport);*/
|
||||
|
||||
|
||||
glGenFramebuffers(1, &_shadowFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _shadowFBO);
|
||||
glFramebufferTexture(
|
||||
@@ -556,28 +483,22 @@ namespace openspace {
|
||||
0
|
||||
);
|
||||
|
||||
glFramebufferTexture(
|
||||
/*glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_positionInLightSpaceTexture,
|
||||
0
|
||||
);
|
||||
);*/
|
||||
|
||||
checkGLError("createShadowFBO() -- Created Shadow Framebuffer");
|
||||
//GLenum drawBuffers[] = { GL_NONE };
|
||||
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_NONE, GL_NONE };
|
||||
//GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_NONE, GL_NONE };
|
||||
GLenum drawBuffers[] = { GL_NONE, GL_NONE, GL_NONE };
|
||||
glDrawBuffers(3, drawBuffers);
|
||||
|
||||
checkFrameBufferState("createShadowFBO()");
|
||||
|
||||
// Restores system state
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
|
||||
/*glViewport(
|
||||
_mViewport[0],
|
||||
_mViewport[1],
|
||||
_mViewport[2],
|
||||
_mViewport[3]
|
||||
);*/
|
||||
checkGLError("createShadowFBO() -- createdShadowFBO");
|
||||
}
|
||||
|
||||
void ShadowComponent::saveDepthBuffer() {
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
static const GLfloat shadowBorder[] = { 1.f, 1.f, 1.f, 1.f };
|
||||
static const GLfloat ShadowBorder[] = { 1.f, 1.f, 1.f, 1.f };
|
||||
|
||||
class ShadowComponent : public properties::PropertyOwner {
|
||||
public:
|
||||
@@ -82,7 +82,7 @@ namespace openspace {
|
||||
bool isReady() const;
|
||||
|
||||
RenderData begin(const RenderData& data);
|
||||
void end(const RenderData& dataOrig);
|
||||
void end();
|
||||
void update(const UpdateData& data);
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
@@ -107,8 +107,8 @@ namespace openspace {
|
||||
const glm::dmat4 _toTextureCoordsMatrix = glm::dmat4(
|
||||
glm::dvec4(0.5, 0.0, 0.0, 0.0),
|
||||
glm::dvec4(0.0, 0.5, 0.0, 0.0),
|
||||
glm::dvec4(0.0, 0.0, 0.5, 0.0),
|
||||
glm::dvec4(0.5, 0.5, 0.5, 1.0)
|
||||
glm::dvec4(0.0, 0.0, 1.0, 0.0),
|
||||
glm::dvec4(0.5, 0.5, 0.0, 1.0)
|
||||
);
|
||||
|
||||
// DEBUG
|
||||
@@ -152,7 +152,7 @@ namespace openspace {
|
||||
|
||||
std::stringstream _serializedCamera;
|
||||
|
||||
Camera *_lightCamera;
|
||||
std::unique_ptr<Camera> _lightCamera;
|
||||
|
||||
// DEBUG
|
||||
bool _executeDepthTextureSave;
|
||||
|
||||
Reference in New Issue
Block a user