Commit fbaee4f4 authored by schultezub's avatar schultezub
Browse files

improved EEPGenerator to support opaque geometry in volume by adapting EEPs

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@381 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent aead807e
......@@ -44,8 +44,8 @@ using namespace campvis;
int main(int argc, char** argv) {
CampVisApplication app(argc, argv);
//app.addVisualizationPipeline("SliceVis", new SliceVis());
//app.addVisualizationPipeline("DVRVis", new DVRVis());
app.addVisualizationPipeline("DVR with OpenCL", new OpenCLPipeline());
app.addVisualizationPipeline("DVRVis", new DVRVis());
//app.addVisualizationPipeline("DVR with OpenCL", new OpenCLPipeline());
app.init();
int toReturn = app.run();
......
......@@ -32,11 +32,86 @@
in vec3 ex_TexCoord; ///< incoming texture coordinate
out vec4 out_Color; ///< outgoing fragment color
#include "tools/texture2d.frag"
#include "tools/masking.frag"
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 Texture2D _entryColorTexture; ///< depth texture of the entrypoints (only used in exitpoints run)
uniform Texture2D _entryDepthTexture; ///< depth texture of the entrypoints (only used in exitpoints run)
uniform Texture2D _geometryDepthTexture; ///< depth texture of rendered geometry
uniform float _near;
uniform float _far;
uniform mat4 _inverseViewMatrix; ///< inverse camera view matrix
uniform mat4 _inverseProjectionMatrix; ///< inverse camera projection matrix
uniform mat4 _volumeWorldToTexture; ///< world-to-texture matrix of volume
void main() {
MASKING_PROLOG(gl_FragCoord.xy * _viewportSizeRCP);
out_Color = vec4(ex_TexCoord, 1.0);
vec2 fragCoordNormalized = gl_FragCoord.xy * _viewportSizeRCP;
MASKING_PROLOG(fragCoordNormalized);
float fragDepth = gl_FragCoord.z;
if (_integrateGeometry) {
float geometryDepth = getElement2DNormalized(_geometryDepthTexture, fragCoordNormalized).z;
if (_isEntrypoint) {
// integrating geometry into Entrypoints
float entryDepth = gl_FragCoord.z;
if (geometryDepth <= entryDepth) {
// geometry before Entrypoint
out_Color = vec4(0.0);
fragDepth = geometryDepth;
}
else {
// geometry behind Entrypoint
out_Color = vec4(ex_TexCoord, 1.0);
fragDepth = entryDepth;
}
}
else {
// integrating geometry into Exitpoints
float entryDepth = getElement2DNormalized(_entryDepthTexture, fragCoordNormalized).z;
float exitDepth = gl_FragCoord.z;
if (geometryDepth <= entryDepth) {
// geometry before Entrypoint
out_Color = vec4(0.0);
fragDepth = exitDepth;
}
else if (geometryDepth <= exitDepth) {
// 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);
out_Color = vec4(result.xyz, 1.0);
fragDepth = geometryDepth;
}
else {
// geometry behind exitpoint
out_Color = vec4(ex_TexCoord, 1.0);
fragDepth = exitDepth;
}
}
}
else {
out_Color = vec4(ex_TexCoord, 1.0);
}
gl_FragDepth = fragDepth;
MASKING_EPILOG;
}
......@@ -47,6 +47,7 @@ namespace campvis {
, p_sourceImageID("sourceImageID", "Input Image", "", DataNameProperty::READ)
, p_geometryID("geometryID", "Input Geometry ID", "proxygeometry", DataNameProperty::READ)
, p_mirrorID("mirrorID", "Input Mirror ID", "mirror", DataNameProperty::READ)
, p_geometryImageId("GeometryImageId", "Rendered Geometry to Integrate (optional)", "", DataNameProperty::READ)
, p_entryImageID("entryImageID", "Output Entry Points Image", "eep.entry", DataNameProperty::WRITE)
, p_exitImageID("exitImageID", "Output Exit Points Image", "eep.exit", DataNameProperty::WRITE)
, p_camera("camera", "Camera")
......@@ -58,6 +59,7 @@ namespace campvis {
addProperty(&p_sourceImageID);
addProperty(&p_geometryID);
addProperty(&p_mirrorID);
addProperty(&p_geometryImageId);
addProperty(&p_entryImageID);
addProperty(&p_exitImageID);
addProperty(&p_camera);
......@@ -96,6 +98,8 @@ namespace campvis {
_shader->rebuild();
}
DataContainer::ScopedTypedData<ImageDataRenderTarget> geometryImage(data, p_geometryImageId.getValue());
tgt::Bounds volumeExtent = img->getWorldBounds();
tgt::Bounds textureBounds(tgt::vec3(0.f), tgt::vec3(1.f));
......@@ -137,8 +141,32 @@ namespace campvis {
_shader->setIgnoreUniformLocationError(true);
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
_shader->setUniform("_modelMatrix", mirrorMatrix);
_shader->setUniform("_projectionMatrix", p_camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", p_camera.getValue().getViewMatrix());
const tgt::Camera& cam = p_camera.getValue();
_shader->setUniform("_projectionMatrix", cam.getProjectionMatrix());
_shader->setUniform("_viewMatrix", cam.getViewMatrix());
tgt::TextureUnit geometryDepthUnit;
if (geometryImage != 0) {
geometryImage->bind(_shader, 0, &geometryDepthUnit, "", "_geometryDepthTexture");
_shader->setUniform("_integrateGeometry", true);
_shader->setUniform("_near", cam.getNearDist());
_shader->setUniform("_far", cam.getFarDist());
tgt::mat4 inverseView = tgt::mat4::identity;
if (cam.getViewMatrix().invert(inverseView))
_shader->setUniform("_inverseViewMatrix", inverseView);
tgt::mat4 inverseProjection = tgt::mat4::identity;
if (cam.getProjectionMatrix().invert(inverseProjection))
_shader->setUniform("_inverseProjectionMatrix", inverseProjection);
_shader->setUniform("_volumeWorldToTexture", img->getMappingInformation().getWorldToTextureMatrix());
}
else {
_shader->setUniform("_integrateGeometry", false);
}
_shader->setIgnoreUniformLocationError(false);
glEnable(GL_CULL_FACE);
......@@ -147,6 +175,7 @@ namespace campvis {
// create entry points texture
ImageDataRenderTarget* entrypoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1), GL_RGBA16);
entrypoints->activate();
_shader->setUniform("_isEntrypoint", true);
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
......@@ -159,6 +188,12 @@ namespace campvis {
// create exit points texture
ImageDataRenderTarget* exitpoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1), GL_RGBA16);
exitpoints->activate();
_shader->setUniform("_isEntrypoint", false);
if (geometryImage != 0) {
tgt::TextureUnit entryColorUnit, entryDepthUnit;
entrypoints->bind(_shader, &entryColorUnit, &entryDepthUnit, "_entryColorTexture", "_entryDepthTexture");
}
glDepthFunc(GL_GREATER);
glClearDepth(0.0f);
......
......@@ -77,6 +77,7 @@ namespace campvis {
DataNameProperty p_sourceImageID; ///< image ID for input image
DataNameProperty p_geometryID; ///< ID for input geometry
DataNameProperty p_mirrorID; ///< ID for input mirror geometry
DataNameProperty p_geometryImageId; ///< image ID for the optional rendered geometry to integrate into the EEP
DataNameProperty p_entryImageID; ///< image ID for output entry points image
DataNameProperty p_exitImageID; ///< image ID for output exit points image
......
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