Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

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 {
_spinBox = new QDoubleSpinBox(this);
_spinBox->setMinimum(property->getMinValue());
_spinBox->setMaximum(property->getMaxValue());
_spinBox->setDecimals(3);
_spinBox->setSingleStep(0.01);
_spinBox->setValue(property->getValue());
addWidget(_spinBox);
......
......@@ -12,7 +12,7 @@ namespace TUMVis {
SimpleTransferFunction::SimpleTransferFunction(size_t size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/)
: AbstractTransferFunction(tgt::svec3(size, 1, 1), intensityDomain)
, _leftColor(0, 0, 0, 255)
, _leftColor(0, 0, 0, 0)
, _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 {
};
/**
* 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 texCoords Lookup coordinates in pixel coordinates
* \return The texel at the given coordinates.
......
......@@ -22,10 +22,11 @@ namespace TUMVis {
, _exitImageID("exitImageID", "Output Exit Points Image", "")
, _targetImageID("targetImageID", "Output Image", "")
, _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)
, _scale("scale", "Normalization Scale", 1.f, 0.f, 1000.f)
, _invertMapping("invertMapping", "Invert Mapping", false, InvalidationLevel::INVALID_RESULT | InvalidationLevel::INVALID_SHADER)
, _jitterEntryPoints("jitterEntryPoints", "Jitter Entry Points", true)
, _shader(0)
{
addProperty(&_sourceImageID);
......@@ -37,6 +38,7 @@ namespace TUMVis {
addProperty(&_shift);
addProperty(&_scale);
addProperty(&_invertMapping);
addProperty(&_jitterEntryPoints);
}
DRRRaycaster::~DRRRaycaster() {
......@@ -71,8 +73,10 @@ namespace TUMVis {
ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
glPushAttrib(GL_ALL_ATTRIB_BITS);
_shader->activate();
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
_shader->setUniform("_jitterEntryPoints", _jitterEntryPoints.getValue());
_shader->setUniform("_samplingStepSize", _samplingStepSize.getValue());
_shader->setUniform("_shift", _shift.getValue());
_shader->setUniform("_scale", _scale.getValue());
......@@ -84,6 +88,11 @@ namespace TUMVis {
_transferFunction.getTF()->bind(_shader, tfUnit);
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);
LGL_ERROR;
tgt::QuadRenderer::renderQuad();
......@@ -92,6 +101,7 @@ namespace TUMVis {
_shader->deactivate();
tgt::TextureUnit::setZeroUnit();
glPopAttrib();
data.addData(_targetImageID.getValue(), rt);
}
......
#include "tools/raycasting.frag"
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform vec2 _viewportSizeRCP;
uniform bool _jitterEntryPoints;
uniform Texture2D _entryPoints; // ray entry points
uniform Texture2D _exitPoints; // ray exit points
......@@ -18,60 +20,51 @@ uniform float _scale;
// TODO: copy+paste from Voreen - eliminate or improve.
const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
/***
* Performs direct volume rendering and
* returns the final fragment color.
***/
vec4 raycastDRR(in vec3 first, in vec3 last, vec2 p) {
/**
* Computes the DRR by simple raycasting and returns the final fragment color.
*/
vec4 raycastDRR(in vec3 entryPoint, in vec3 exitPoint) {
vec4 result = vec4(0.0);
bool finished = false;
// calculate ray parameters
float stepIncr = _samplingStepSize;
float tend;
vec3 direction = exitPoint.rgb - entryPoint.rgb;
float t = 0.0;
vec3 direction = last.rgb - first.rgb;
tend = length(direction);
float tend = length(direction);
direction = normalize(direction);
// 2 nested loops allow for more than 255 iterations,
// but is slower than while (t < tend)
for (int loop0=0; !finished && loop0<255; loop0++) {
for (int loop1=0; !finished && loop1<255; loop1++) {
if (_jitterEntryPoints)
jitterEntryPoint(entryPoint, direction, _samplingStepSize);
vec3 samplePosition = first.rgb + t * direction;
vec4 voxel = getElement3D(_volume, samplePosition);
vec4 color = lookupTF(_tfTextureParameters, _tfTex, voxel.a);
while (t < tend) {
vec3 samplePosition = entryPoint.rgb + t * direction;
vec4 voxel = getElement3DNormalized(_volume, samplePosition);
vec4 color = lookupTF(_tfTextureParameters, _tfTex, voxel.a);
#ifdef DEPTH_MAPPING
// use Bernstein Polynomials for depth-color mapping
float depth = t / tend;
// use Bernstein Polynomials for depth-color mapping
float depth = t / tend;
float b02 = (1-depth) * (1-depth);
float b12 = 2 * depth * (1-depth);
float b22 = depth * depth;
float b02 = (1-depth) * (1-depth);
float b12 = 2 * depth * (1-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 inv_t_sq = (1-depth) * (1-depth);
float b04 = inv_t_sq * inv_t_sq;
float b24 = 6 * t_sq * inv_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));*/
result.rgb = result.rgb + (1.0 - result.a) * color.a * color.rgb;
result.a = result.a + color.a * _scale;
float inv_t_sq = (1-depth) * (1-depth);
float b04 = inv_t_sq * inv_t_sq;
float b24 = 6 * t_sq * inv_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));*/
result.rgb = result.rgb + (1.0 - result.a) * color.a * color.rgb;
result.a = result.a + color.a * _scale;
#else
// perform compositing (account for differen step size / sampling rate)
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP);
result.a = result.a + color.a * _scale;
// perform compositing (account for differen step size / sampling rate)
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP);
result.a = result.a + color.a * _scale;
#endif
t += stepIncr;
finished = finished || (t > tend);
}
t += _samplingStepSize;
}
// DRR images don't have a meaningful depth value
......@@ -107,6 +100,6 @@ void main() {
discard;
} else {
//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 {
FloatProperty _shift;
FloatProperty _scale;
BoolProperty _invertMapping;
BoolProperty _jitterEntryPoints;
protected:
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