Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

Commit af621107 authored by Jakob Weiss's avatar Jakob Weiss

Bugfix: EEPGenerator was not integrating geometry correctly

When adding rendered geometr, the EEPGenerator did not unproject the depth value correctly, leading to wrong exit points. The current solution is a more robust solution, but requires an additional texture lookup into the entrypoint color texture. If performance of the EEPGenerator ever becomes a problem, start here by implementing a proper depth unprojection
parent ac1d35e4
......@@ -23,6 +23,7 @@
// ================================================================================================
in vec3 ex_TexCoord; ///< incoming texture coordinate
in vec4 ex_Position; ///< outgoing world coordinates
out vec4 out_Color; ///< outgoing fragment color
#include "tools/texture2d.frag"
......@@ -33,6 +34,9 @@ uniform vec2 _viewportSizeRCP;
uniform bool _integrateGeometry; ///< flag whether to integrate geometry into the EEP
uniform bool _isEntrypoint; ///< true if current run is for entrypoints, false if current run is for exitpoints
uniform sampler2D _entryColorTexture; ///< color texture of the entrypoints (only used in exitpoints run)
uniform TextureParameters2D _entryColorTexParams;
uniform sampler2D _entryDepthTexture; ///< depth texture of the entrypoints (only used in exitpoints run)
uniform TextureParameters2D _entryDepthTexParams;
......@@ -45,6 +49,27 @@ uniform mat4 _inverseViewMatrix; ///< inverse camera view matrix
uniform mat4 _inverseProjectionMatrix; ///< inverse camera projection matrix
uniform mat4 _volumeWorldToTexture; ///< world-to-texture matrix of volume
/// Matrix defining model-to-world transformation
uniform mat4 _modelMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining view transformation
uniform mat4 _viewMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining projection transformation
uniform mat4 _projectionMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
void main() {
vec2 fragCoordNormalized = gl_FragCoord.xy * _viewportSizeRCP;
MASKING_PROLOG(fragCoordNormalized);
......@@ -80,18 +105,20 @@ void main() {
fragDepth = geometryDepth;
}
else if (geometryDepth <= exitDepth) {
vec3 entryTex = texture(_entryColorTexture, fragCoordNormalized).rgb;
float t = (geometryDepth - entryDepth)/(exitDepth - entryDepth);
vec3 result = mix(entryTex, ex_TexCoord, t);
// geometry between entrypoint and exitpoint
// transform viewport coordinates to [-1, 1] NDC
vec4 result = vec4(fragCoordNormalized, geometryDepth, 1.0);
result = 2.0 * result - 1.0;
// reverse perspective division by w (which is equal to the camera-space z)
float origZG = (2.0 * _far * _near) / ((_far + _near) - result.z * (_far - _near));
result *= origZG;
// unproject and reverse camera-transform
result = vec4((_volumeWorldToTexture * (_inverseViewMatrix * (_inverseProjectionMatrix * result))).xyz, 1.0);
//vec4 result = vec4(fragCoordNormalized, geometryDepth, 1.0);
//result = 2.0 * result - 1.0;
//// reverse perspective division by w (which is equal to the camera-space z)
//float origZG = (2.0 * _far * _near) / ((_far + _near) - result.z * (_far - _near));
//result *= origZG;
//// unproject and reverse camera-transform
//result = vec4((_volumeWorldToTexture * (_inverseViewMatrix * (_inverseProjectionMatrix * result))).xyz, 1.0);
out_Color = vec4(result.xyz, 1.0);
fragDepth = geometryDepth;
......
......@@ -125,7 +125,7 @@ namespace campvis {
}
}
cgt::TextureUnit geometryDepthUnit, entryDepthUnit;
cgt::TextureUnit geometryDepthUnit, entryDepthUnit, entryColorUnit;
_shader->setIgnoreUniformLocationError(true);
_shader->setUniform("_viewportSizeRCP", 1.f / cgt::vec2(getEffectiveViewportSize()));
......@@ -181,6 +181,7 @@ namespace campvis {
_shader->setUniform("_isEntrypoint", false);
if (geometryImage != 0) {
entrypoints->bindColorTexture(_shader, entryColorUnit, "_entryColorTexture", "_entryColorTexParams");
entrypoints->bindDepthTexture(_shader, entryDepthUnit, "_entryDepthTexture", "_entryDepthTexParams");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment