Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 6c3588f3 authored by schultezub's avatar schultezub
Browse files

* further work on DRRRaycaster

 * introduced tools/raycasting.frag with useful helper methods for ray casting

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@225 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent c2e5178b
...@@ -8,6 +8,8 @@ namespace TUMVis { ...@@ -8,6 +8,8 @@ namespace TUMVis {
_spinBox = new QDoubleSpinBox(this); _spinBox = new QDoubleSpinBox(this);
_spinBox->setMinimum(property->getMinValue()); _spinBox->setMinimum(property->getMinValue());
_spinBox->setMaximum(property->getMaxValue()); _spinBox->setMaximum(property->getMaxValue());
_spinBox->setDecimals(3);
_spinBox->setSingleStep(0.01);
_spinBox->setValue(property->getValue()); _spinBox->setValue(property->getValue());
addWidget(_spinBox); addWidget(_spinBox);
......
...@@ -12,7 +12,7 @@ namespace TUMVis { ...@@ -12,7 +12,7 @@ namespace TUMVis {
SimpleTransferFunction::SimpleTransferFunction(size_t size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/) SimpleTransferFunction::SimpleTransferFunction(size_t size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/)
: AbstractTransferFunction(tgt::svec3(size, 1, 1), intensityDomain) : AbstractTransferFunction(tgt::svec3(size, 1, 1), intensityDomain)
, _leftColor(0, 0, 0, 255) , _leftColor(0, 0, 0, 0)
, _rightColor(255) , _rightColor(255)
{ {
} }
......
/**
* Code adapted from: https://www.marcusbannerman.co.uk/index.php/component/content/article/42-articles/97-vol-render-optimizations.htm
*/
void jitterEntryPoint(inout vec3 position, in vec3 direction, in float stepSize) {
float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453);
position = position + direction * (stepSize * random);
}
\ No newline at end of file
...@@ -10,7 +10,7 @@ struct Texture3D { ...@@ -10,7 +10,7 @@ struct Texture3D {
}; };
/** /**
* Texture lookup function for 3D textures using pixel coordinates, i.e [(0,0) , textureSize]. * Texture lookup function for 3D textures using voxel coordinates, i.e [(0,0) , textureSize].
* \param tex Texture3D struct with texture for lookup * \param tex Texture3D struct with texture for lookup
* \param texCoords Lookup coordinates in pixel coordinates * \param texCoords Lookup coordinates in pixel coordinates
* \return The texel at the given coordinates. * \return The texel at the given coordinates.
......
...@@ -22,10 +22,11 @@ namespace TUMVis { ...@@ -22,10 +22,11 @@ namespace TUMVis {
, _exitImageID("exitImageID", "Output Exit Points Image", "") , _exitImageID("exitImageID", "Output Exit Points Image", "")
, _targetImageID("targetImageID", "Output Image", "") , _targetImageID("targetImageID", "Output Image", "")
, _transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256)) , _transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, _samplingStepSize("samplingStepSize", "Sampling Step Size", .5f, 0.01f, 2.f) , _samplingStepSize("samplingStepSize", "Sampling Step Size", .1f, 0.001f, 1.f)
, _shift("shift", "Normalization Shift", 0.f, -10.f, 10.f) , _shift("shift", "Normalization Shift", 0.f, -10.f, 10.f)
, _scale("scale", "Normalization Scale", 1.f, 0.f, 1000.f) , _scale("scale", "Normalization Scale", 1.f, 0.f, 1000.f)
, _invertMapping("invertMapping", "Invert Mapping", false, InvalidationLevel::INVALID_RESULT | InvalidationLevel::INVALID_SHADER) , _invertMapping("invertMapping", "Invert Mapping", false, InvalidationLevel::INVALID_RESULT | InvalidationLevel::INVALID_SHADER)
, _jitterEntryPoints("jitterEntryPoints", "Jitter Entry Points", true)
, _shader(0) , _shader(0)
{ {
addProperty(&_sourceImageID); addProperty(&_sourceImageID);
...@@ -37,6 +38,7 @@ namespace TUMVis { ...@@ -37,6 +38,7 @@ namespace TUMVis {
addProperty(&_shift); addProperty(&_shift);
addProperty(&_scale); addProperty(&_scale);
addProperty(&_invertMapping); addProperty(&_invertMapping);
addProperty(&_jitterEntryPoints);
} }
DRRRaycaster::~DRRRaycaster() { DRRRaycaster::~DRRRaycaster() {
...@@ -71,8 +73,10 @@ namespace TUMVis { ...@@ -71,8 +73,10 @@ namespace TUMVis {
ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1)); ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
glPushAttrib(GL_ALL_ATTRIB_BITS);
_shader->activate(); _shader->activate();
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue())); _shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
_shader->setUniform("_jitterEntryPoints", _jitterEntryPoints.getValue());
_shader->setUniform("_samplingStepSize", _samplingStepSize.getValue()); _shader->setUniform("_samplingStepSize", _samplingStepSize.getValue());
_shader->setUniform("_shift", _shift.getValue()); _shader->setUniform("_shift", _shift.getValue());
_shader->setUniform("_scale", _scale.getValue()); _shader->setUniform("_scale", _scale.getValue());
...@@ -84,6 +88,11 @@ namespace TUMVis { ...@@ -84,6 +88,11 @@ namespace TUMVis {
_transferFunction.getTF()->bind(_shader, tfUnit); _transferFunction.getTF()->bind(_shader, tfUnit);
rt->activate(); rt->activate();
if (_invertMapping.getValue())
glClearColor(0.f, 0.f, 0.f, 1.f);
else
glClearColor(1.f, 1.f, 1.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LGL_ERROR; LGL_ERROR;
tgt::QuadRenderer::renderQuad(); tgt::QuadRenderer::renderQuad();
...@@ -92,6 +101,7 @@ namespace TUMVis { ...@@ -92,6 +101,7 @@ namespace TUMVis {
_shader->deactivate(); _shader->deactivate();
tgt::TextureUnit::setZeroUnit(); tgt::TextureUnit::setZeroUnit();
glPopAttrib();
data.addData(_targetImageID.getValue(), rt); data.addData(_targetImageID.getValue(), rt);
} }
......
#include "tools/raycasting.frag"
#include "tools/texture2d.frag" #include "tools/texture2d.frag"
#include "tools/texture3d.frag" #include "tools/texture3d.frag"
#include "tools/transferfunction.frag" #include "tools/transferfunction.frag"
uniform vec2 _viewportSizeRCP; uniform vec2 _viewportSizeRCP;
uniform bool _jitterEntryPoints;
uniform Texture2D _entryPoints; // ray entry points uniform Texture2D _entryPoints; // ray entry points
uniform Texture2D _exitPoints; // ray exit points uniform Texture2D _exitPoints; // ray exit points
...@@ -18,60 +20,51 @@ uniform float _scale; ...@@ -18,60 +20,51 @@ uniform float _scale;
// TODO: copy+paste from Voreen - eliminate or improve. // TODO: copy+paste from Voreen - eliminate or improve.
const float SAMPLING_BASE_INTERVAL_RCP = 200.0; const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
/*** /**
* Performs direct volume rendering and * Computes the DRR by simple raycasting and returns the final fragment color.
* returns the final fragment color. */
***/ vec4 raycastDRR(in vec3 entryPoint, in vec3 exitPoint) {
vec4 raycastDRR(in vec3 first, in vec3 last, vec2 p) {
vec4 result = vec4(0.0); vec4 result = vec4(0.0);
bool finished = false;
// calculate ray parameters // calculate ray parameters
float stepIncr = _samplingStepSize; vec3 direction = exitPoint.rgb - entryPoint.rgb;
float tend;
float t = 0.0; float t = 0.0;
vec3 direction = last.rgb - first.rgb; float tend = length(direction);
tend = length(direction);
direction = normalize(direction); direction = normalize(direction);
// 2 nested loops allow for more than 255 iterations, if (_jitterEntryPoints)
// but is slower than while (t < tend) jitterEntryPoint(entryPoint, direction, _samplingStepSize);
for (int loop0=0; !finished && loop0<255; loop0++) {
for (int loop1=0; !finished && loop1<255; loop1++) {
vec3 samplePosition = first.rgb + t * direction; while (t < tend) {
vec4 voxel = getElement3D(_volume, samplePosition); vec3 samplePosition = entryPoint.rgb + t * direction;
vec4 color = lookupTF(_tfTextureParameters, _tfTex, voxel.a); vec4 voxel = getElement3DNormalized(_volume, samplePosition);
vec4 color = lookupTF(_tfTextureParameters, _tfTex, voxel.a);
#ifdef DEPTH_MAPPING #ifdef DEPTH_MAPPING
// use Bernstein Polynomials for depth-color mapping // use Bernstein Polynomials for depth-color mapping
float depth = t / tend; float depth = t / tend;
float b02 = (1-depth) * (1-depth); float b02 = (1-depth) * (1-depth);
float b12 = 2 * depth * (1-depth); float b12 = 2 * depth * (1-depth);
float b22 = depth * depth; float b22 = depth * depth;
color = vec4(0.75*b02 + 0.25*b12, b12, 0.25*b12 + 0.75*b22, 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP)); color = vec4(0.75*b02 + 0.25*b12, b12, 0.25*b12 + 0.75*b22, 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP));
/* float t_sq = depth * depth; /* float t_sq = depth * depth;
float inv_t_sq = (1-depth) * (1-depth); float inv_t_sq = (1-depth) * (1-depth);
float b04 = inv_t_sq * inv_t_sq; float b04 = inv_t_sq * inv_t_sq;
float b24 = 6 * t_sq * inv_t_sq; float b24 = 6 * t_sq * inv_t_sq;
float b44 = t_sq * t_sq; float b44 = t_sq * t_sq;
color = vec4(0.5*b04 + 0.5*b24, b24, 0.5*b24 + 0.5*b44, 1.0 - pow(1.0 - color.a, samplingStepSize_ * SAMPLING_BASE_INTERVAL_RCP));*/ color = vec4(0.5*b04 + 0.5*b24, b24, 0.5*b24 + 0.5*b44, 1.0 - pow(1.0 - color.a, samplingStepSize_ * SAMPLING_BASE_INTERVAL_RCP));*/
result.rgb = result.rgb + (1.0 - result.a) * color.a * color.rgb; result.rgb = result.rgb + (1.0 - result.a) * color.a * color.rgb;
result.a = result.a + color.a * _scale; result.a = result.a + color.a * _scale;
#else #else
// perform compositing (account for differen step size / sampling rate) // perform compositing (account for differen step size / sampling rate)
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP); color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP);
result.a = result.a + color.a * _scale; result.a = result.a + color.a * _scale;
#endif #endif
t += stepIncr; t += _samplingStepSize;
finished = finished || (t > tend);
}
} }
// DRR images don't have a meaningful depth value // DRR images don't have a meaningful depth value
...@@ -107,6 +100,6 @@ void main() { ...@@ -107,6 +100,6 @@ void main() {
discard; discard;
} else { } else {
//fragCoords are lying inside the boundingbox //fragCoords are lying inside the boundingbox
gl_FragData[0] = raycastDRR(frontPos, backPos, p); gl_FragData[0] = raycastDRR(frontPos, backPos);
} }
} }
...@@ -53,6 +53,7 @@ namespace TUMVis { ...@@ -53,6 +53,7 @@ namespace TUMVis {
FloatProperty _shift; FloatProperty _shift;
FloatProperty _scale; FloatProperty _scale;
BoolProperty _invertMapping; BoolProperty _invertMapping;
BoolProperty _jitterEntryPoints;
protected: protected:
std::string generateHeader() const; std::string generateHeader() const;
......
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