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

Commit 4b54ac8a authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Further work on AdvOptRaycaster, fixed some bugs but still showing artifacts...

parent 290a9b79
...@@ -83,7 +83,7 @@ uniform float _shadowIntensity; ...@@ -83,7 +83,7 @@ uniform float _shadowIntensity;
const float SAMPLING_BASE_INTERVAL_RCP = 200.0; const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
float originalTFar = -1.0; float originalTFar = -1.0;
const int MAXSTEPS = 100; const int MAXSTEPS = 50;
float OFFSET = 0.001; float OFFSET = 0.001;
...@@ -109,7 +109,7 @@ bool intersectBits(in uvec4 bitRay, in ivec2 texel, in int level, out uvec4 inte ...@@ -109,7 +109,7 @@ bool intersectBits(in uvec4 bitRay, in ivec2 texel, in int level, out uvec4 inte
return (intersectionBitmask != uvec4(0)); return (intersectionBitmask != uvec4(0));
} }
bool intersectHierarchy2(in vec3 origin, in vec3 direction, in int level, in vec3 posTNear, inout float tFar, out uvec4 intersectionBitmask) { bool intersectHierarchy2(in vec3 origin, in vec3 direction, in int level, in vec3 posTNear, out float tFar, out uvec4 intersectionBitmask) {
// Calculate pixel coordinates ([0,width]x[0,height]) // Calculate pixel coordinates ([0,width]x[0,height])
// of the current position along the ray // of the current position along the ray
float res = float(1 << (_vvMaxMipMapLevel - level)); float res = float(1 << (_vvMaxMipMapLevel - level));
...@@ -140,6 +140,8 @@ bool intersectHierarchy2(in vec3 origin, in vec3 direction, in int level, in vec ...@@ -140,6 +140,8 @@ bool intersectHierarchy2(in vec3 origin, in vec3 direction, in int level, in vec
intersectionBitmask); intersectionBitmask);
} }
float lll;
float clipFirstHitpoint(in vec3 origin, in vec3 direction, in float tNear, in float tFar) { float clipFirstHitpoint(in vec3 origin, in vec3 direction, in float tNear, in float tFar) {
// Compute the exit position of the ray with the scene’s BB // Compute the exit position of the ray with the scene’s BB
// tFar = rayBoxIntersection(origin, direction, vec3(0.0), vec3(1.0), tNear); // tFar = rayBoxIntersection(origin, direction, vec3(0.0), vec3(1.0), tNear);
...@@ -180,6 +182,7 @@ float clipFirstHitpoint(in vec3 origin, in vec3 direction, in float tNear, in fl ...@@ -180,6 +182,7 @@ float clipFirstHitpoint(in vec3 origin, in vec3 direction, in float tNear, in fl
} }
} }
lll = float(level);
return tNear; return tNear;
} }
...@@ -200,18 +203,17 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) ...@@ -200,18 +203,17 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
OFFSET = (0.25 / (1 << _vvMaxMipMapLevel)) / tFar; //< offset value used to avoid self-intersection or previous voxel intersection. OFFSET = (0.25 / (1 << _vvMaxMipMapLevel)) / tFar; //< offset value used to avoid self-intersection or previous voxel intersection.
jitterEntryPoint(entryPoint, direction, _samplingStepSize * _jitterStepSizeMultiplier); //jitterEntryPoint(entryPoint, direction, _samplingStepSize * _jitterStepSizeMultiplier);
float firstHitT = -1.0f; float firstHitT = -1.0f;
tNear = clipFirstHitpoint(entryPoint, direction, tNear, tFar); tNear = clipFirstHitpoint(entryPoint, direction, 0.0, 1.0);
tFar -= clipFirstHitpoint(exitPoint, -direction, tNear, tFar); tFar -= clipFirstHitpoint(exitPoint, -direction, 0.0, 1.0);
originalTFar = tFar; originalTFar = tFar;
tNear *= length(direction); //tNear *= length(direction);
tFar *= length(direction); //tFar *= length(direction);
direction = normalize(direction); //direction = normalize(direction);
// compute sample position // compute sample position
vec3 samplePosition = entryPoint.rgb + tNear * direction; vec3 samplePosition = entryPoint.rgb + tNear * direction;
...@@ -219,7 +221,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) ...@@ -219,7 +221,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
out_FHP = vec4(samplePosition, 1.0); out_FHP = vec4(samplePosition, 1.0);
out_FHN = vec4(entryPoint.rgb + tFar * direction, 1.0); out_FHN = vec4(entryPoint.rgb + tFar * direction, 1.0);
out_count = vec4(tNear, tFar, originalTFar, 0.0); out_count = vec4(tNear, tFar, lll, 0.0);
while (tNear < tFar) { while (tNear < tFar) {
vec3 samplePosition = entryPoint.rgb + tNear * direction; vec3 samplePosition = entryPoint.rgb + tNear * direction;
...@@ -231,9 +233,9 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) ...@@ -231,9 +233,9 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
if (color.a > 0.0) { if (color.a > 0.0) {
#ifdef ENABLE_SHADING #ifdef ENABLE_SHADING
// compute gradient (needed for shading and normals) // compute gradient (needed for shading and normals)
vec3 gradient = computeGradient(_volume, _volumeTextureParams, samplePosition); //vec3 gradient = computeGradient(_volume, _volumeTextureParams, samplePosition);
vec4 worldPos = _volumeTextureParams._textureToWorldMatrix * vec4(samplePosition, 1.0); // calling textureToWorld here crashes Intel HD driver and nVidia driver in debug mode, hence, let's calc it manually... //vec4 worldPos = _volumeTextureParams._textureToWorldMatrix * vec4(samplePosition, 1.0); // calling textureToWorld here crashes Intel HD driver and nVidia driver in debug mode, hence, let's calc it manually...
color.rgb = calculatePhongShading(worldPos.xyz / worldPos.w, _lightSource, _cameraPosition, gradient, color.rgb); //color.rgb = calculatePhongShading(worldPos.xyz / worldPos.w, _lightSource, _cameraPosition, gradient, color.rgb);
#endif #endif
// accomodate for variable sampling rates // accomodate for variable sampling rates
......
...@@ -66,23 +66,19 @@ void main() { ...@@ -66,23 +66,19 @@ void main() {
for (int z = -1; z < _brickDepth + 1; ++z) { for (int z = -1; z < _brickDepth + 1; ++z) {
for (int y = -1; y < _brickSize + 1; ++y) { for (int y = -1; y < _brickSize + 1; ++y) {
for (int x = -1; x < _brickSize + 1; ++x) { for (int x = -1; x < _brickSize + 1; ++x) {
vec3 texCoord = clamp(llf + (vec3(x, y, z) / _volumeTextureParams._size), 0.0, 1.0); vec3 addendum = (vec3(x, y, z) / _volumeTextureParams._size);
vec3 texCoord = clamp(llf + addendum, 0.0, 1.0);
//float intensity = mapIntensityToTFDomain(_transferFunctionParams._intensityDomain, texture(_volume, texCoord).r);
ivec3 voxel = ivec3(texCoord * _volumeTextureParams._size); ivec3 voxel = ivec3(texCoord * _volumeTextureParams._size);
float intensity = mapIntensityToTFDomain(_transferFunctionParams._intensityDomain, texelFetch(_volume, voxel, 0).r); float intensity = mapIntensityToTFDomain(_transferFunctionParams._intensityDomain, texelFetch(_volume, voxel, 0).r);
//float intensity = texture(_volume, voxel).r; //float intensity = texture(_volume, voxel).r;
//vec4 color = lookupTF(_transferFunction, _transferFunctionParams, intensity); //vec4 color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
//if (color.a > 0) { //if (color.a > 0) {
//}
// if there was any data in the volume data in that voxel, set the bit. // if there was any data in the volume data in that voxel, set the bit.
if (intensity >= _tfDomain.x && intensity <= _tfDomain.y) { if (intensity >= _tfDomain.x && intensity <= _tfDomain.y) {
hasData = true; //result[e] |= (1 << d);
break;
}
}
}
}
if (hasData) {
if (e == 0) if (e == 0)
result.r |= (1 << d); result.r |= (1 << d);
else if (e == 1) else if (e == 1)
...@@ -91,6 +87,10 @@ void main() { ...@@ -91,6 +87,10 @@ void main() {
result.b |= (1 << d); result.b |= (1 << d);
else if (e == 3) else if (e == 3)
result.a |= (1 << d); result.a |= (1 << d);
break;
}
}
}
} }
} }
} }
......
...@@ -22,10 +22,29 @@ ...@@ -22,10 +22,29 @@
// //
// ================================================================================================ // ================================================================================================
layout(location = 0) out vec4 result; layout(location = 0) out uvec4 result;
uniform usampler1D _bitmaskTexture;
void main() { void main() {
result = texelFetch(_bitmaskTexture, int(gl_FragCoord.x), 0) ^ texelFetch(_bitmaskTexture, int(gl_FragCoord.y) + 1, 0); const uint ALL_ONES = uint(0xFFFFFFFF);
uvec4[129] bitmask;
for (int e = 0; e < 4; ++e) {
for (int b = 0; b < 32; ++b) {
int idx = 32*e + b;
if (e == 0)
bitmask[idx] = uvec4(ALL_ONES << b, ALL_ONES, ALL_ONES, ALL_ONES);
else if (e == 1)
bitmask[idx] = uvec4(0, ALL_ONES << b, ALL_ONES, ALL_ONES);
else if (e == 2)
bitmask[idx] = uvec4(0, 0, ALL_ONES << b, ALL_ONES);
else if (e == 3)
bitmask[idx] = uvec4(0, 0, 0, ALL_ONES << b);
}
}
bitmask[128] = uvec4(0);
int a = clamp(int(gl_FragCoord.x), 0, 127);
int b = clamp(int(gl_FragCoord.y) + 1, 0, 128);
result = bitmask[a] ^ bitmask[b];
} }
\ No newline at end of file
...@@ -67,8 +67,8 @@ namespace campvis { ...@@ -67,8 +67,8 @@ namespace campvis {
_resampler.p_outputImage.setValue("image.resampled"); _resampler.p_outputImage.setValue("image.resampled");
Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, cgt::vec2(0.f, .05f)); Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, cgt::vec2(0.f, .05f));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.12f, .15f), cgt::col4(85, 0, 0, 128), cgt::col4(255, 0, 0, 128))); //dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.12f, .15f), cgt::col4(85, 0, 0, 128), cgt::col4(255, 0, 0, 128)));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.19f, .28f), cgt::col4(89, 89, 89, 155), cgt::col4(89, 89, 89, 155))); //dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.19f, .28f), cgt::col4(89, 89, 89, 155), cgt::col4(89, 89, 89, 155)));
dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.41f, .51f), cgt::col4(170, 170, 128, 64), cgt::col4(192, 192, 128, 64))); dvrTF->addGeometry(TFGeometry1D::createQuad(cgt::vec2(.41f, .51f), cgt::col4(170, 170, 128, 64), cgt::col4(192, 192, 128, 64)));
static_cast<TransferFunctionProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::TransferFunction"))->replaceTF(dvrTF); static_cast<TransferFunctionProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::TransferFunction"))->replaceTF(dvrTF);
static_cast<FloatProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::SamplingRate"))->setValue(4.f); static_cast<FloatProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::SamplingRate"))->setValue(4.f);
......
...@@ -212,71 +212,12 @@ namespace campvis { ...@@ -212,71 +212,12 @@ namespace campvis {
} }
void VoxelHierarchyMapper::createXorBitmaskTexture() { void VoxelHierarchyMapper::createXorBitmaskTexture() {
int bits = 32; // bits per texture channel cgt::TextureUnit xorUnit;
GLuint all_1 = GLuint(pow(2.0,double(bits))-1);//)0x7FFFFFFFU; // (2^31 -1)
GLuint shifted_ones = all_1;
GLuint R,G,B,A;
int counter = 0;
std::vector<GLuint> bitmaskData;
for (int i = 0; i < 4*bits; i++) {
if (counter == bits) //reset
{
counter = 0;
shifted_ones = all_1;
}
if (i < bits) // first 31 texels: 1-bit in R
{
R = shifted_ones;
G = all_1;
B = all_1;
A = all_1;
}
if (bits <= i && i < 2*bits) // G
{
R = 0;
G = shifted_ones;
B = all_1;
A = all_1;
}
if (2*bits <= i && i < 3*bits) // B
{
R = 0;
G = 0;
B = shifted_ones;
A = all_1;
}
if (3*bits <= i && i < 4*bits) // A
{
R = 0;
G = 0;
B = 0;
A = shifted_ones;
}
bitmaskData.push_back(R); // R
bitmaskData.push_back(G); // G
bitmaskData.push_back(B); // B
bitmaskData.push_back(A); // A
counter++;
shifted_ones = shifted_ones >> 1;
}
GLuint* ptr = &bitmaskData.front();
cgt::TextureUnit bitmaskUnit, xorUnit;
bitmaskUnit.activate();
cgt::Texture* bitmaskTexture = new cgt::Texture(GL_TEXTURE_1D, cgt::ivec3(128, 1, 1), GL_RGBA32UI, reinterpret_cast<GLubyte*>(&bitmaskData.front()), GL_RGBA_INTEGER, GL_UNSIGNED_INT, cgt::Texture::NEAREST);
bitmaskTexture->bind();
bitmaskTexture->setWrapping(cgt::Texture::CLAMP);
xorUnit.activate(); xorUnit.activate();
_xorBitmaskTexture = new cgt::Texture(GL_TEXTURE_2D, cgt::ivec3(128, 128, 1), GL_RGBA32UI, cgt::Texture::NEAREST); _xorBitmaskTexture = new cgt::Texture(GL_TEXTURE_2D, cgt::ivec3(128, 128, 1), GL_RGBA32UI, cgt::Texture::NEAREST);
_xorBitmaskTexture->setWrapping(cgt::Texture::CLAMP); _xorBitmaskTexture->setWrapping(cgt::Texture::CLAMP);
_xorBitmaskShader->activate(); _xorBitmaskShader->activate();
_xorBitmaskShader->setUniform("_bitmaskTexture", bitmaskUnit.getUnitNumber());
_fbo->activate(); _fbo->activate();
_fbo->attachTexture(_xorBitmaskTexture, GL_COLOR_ATTACHMENT0, 0, 0); _fbo->attachTexture(_xorBitmaskTexture, GL_COLOR_ATTACHMENT0, 0, 0);
_fbo->isComplete(); _fbo->isComplete();
......
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