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

* Fixed possible errors when rendering empty geometry

* Introduced tgt::Shader::IgnoreUniformLocationErrorGuard
* Fixed SimpleRaycaster::updateProperties() and OptimizedRaycaster::updateProperties() not calling base class' updateProperties()
parent cdea70de
......@@ -106,6 +106,9 @@ namespace campvis {
}
void FaceGeometry::render(GLenum mode) const {
if (_vertices.empty())
return;
createGLBuffers();
if (_buffersDirty) {
LERROR("Cannot render without initialized OpenGL buffers.");
......
......@@ -118,6 +118,9 @@ namespace campvis {
void IndexedMeshGeometry::render(GLenum mode) const {
if (_indices.empty())
return;
createGLBuffers();
if (_buffersDirty) {
LERROR("Cannot render without initialized OpenGL buffers.");
......
......@@ -78,6 +78,9 @@ namespace campvis {
void MeshGeometry::render(GLenum mode) const {
if (_faces.empty())
return;
createGLBuffers();
if (_buffersDirty) {
LERROR("Cannot render without initialized OpenGL buffers.");
......
......@@ -134,6 +134,9 @@ namespace campvis {
}
void MultiIndexedGeometry::render(GLenum mode) const {
if (_counts.empty())
return;
createGLBuffers();
if (_buffersDirty) {
LERROR("Cannot render without initialized OpenGL buffers.");
......
......@@ -22,6 +22,8 @@
//
// ================================================================================================
const float positiveInfinity = 1.0 / 0.0;
/**
* Code adapted from: https://www.marcusbannerman.co.uk/index.php/component/content/article/42-articles/97-vol-render-optimizations.htm
*/
......@@ -30,6 +32,34 @@ void jitterEntryPoint(inout vec3 position, in vec3 direction, in float stepSize)
position = position + direction * (stepSize * random);
}
/**
* Computes the intersection of the given ray with the given axis-aligned box.
* \param rayOrigin Origin of ray
* \param rayDirection Direction of ray
* \param boxLlf Lower-Left-front corner of box
* \param boxUrb Upper-right-back corner of box
* \param t Starting point for ray-box intersection (as fraction origin/(origin+direction)),
* set to 0 to start at origin
*/
float rayBoxIntersection(in vec3 rayOrigin, in vec3 rayDirection, in vec3 boxLlf, in vec3 boxUrb, in float t) {
vec3 tMin = (boxLlf - rayOrigin) / rayDirection;
vec3 tMax = (boxUrb - rayOrigin) / rayDirection;
// TODO: these many ifs are expensive - the lessThan bvec solution below should be faster but does not work for some reason...
if (tMin.x < t) tMin.x = positiveInfinity;
if (tMin.y < t) tMin.y = positiveInfinity;
if (tMin.z < t) tMin.z = positiveInfinity;
if (tMax.x < t) tMax.x = positiveInfinity;
if (tMax.y < t) tMax.y = positiveInfinity;
if (tMax.z < t) tMax.z = positiveInfinity;
//tMin += vec3(lessThan(tMin, vec3(t, t, t))) * positiveInfinity;
//tMax += vec3(lessThan(tMax, vec3(t, t, t))) * positiveInfinity;
return min(min(tMin.x, min(tMin.y, tMin.z)) , min(tMax.x, min(tMax.y, tMax.z)));
}
/**
* Converts a depth value in eye space to the corresponding depth value in viewport space.
* \param depth Depth value in eye space.
......
......@@ -179,6 +179,35 @@ class TGT_API Shader {
friend class ShaderManager;
public:
/**
* Guard to enable ignoring uniform location errors and ensuring to disable it again upon destruction.
*/
struct IgnoreUniformLocationErrorGuard {
public:
/**
* Creates a new IgnoreUniformLocationErrorGuard for the given shader.
* Sets the shader's ignoreError_ to true.
* \param shader Shader to enable ignoring uniform location errors.
*/
IgnoreUniformLocationErrorGuard(tgt::Shader* shader)
: _shader(shader)
, _stateToRestore(shader->getIgnoreUniformLocationError())
{
_shader->setIgnoreUniformLocationError(true);
};
/**
* Destructor, restores the shader's original ignoreError_ state.
*/
~IgnoreUniformLocationErrorGuard() {
_shader->setIgnoreUniformLocationError(_stateToRestore);
}
private:
tgt::Shader* _shader; ///< Shader to modify
bool _stateToRestore; ///< Original state
};
Shader();
/**
......
......@@ -76,8 +76,6 @@ bool _inVoid = false;
uniform float _shadowIntensity;
#endif
const float positiveInfinity = 1.0 / 0.0;
// TODO: copy+paste from Voreen - eliminate or improve.
const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
......@@ -96,25 +94,6 @@ bool lookupInBbv(in vec3 samplePosition) {
return (texel & (1U << bit)) != 0U;
}
float rayBoxIntersection(in vec3 rayOrigin, in vec3 rayDirection, in vec3 boxLlf, in vec3 boxUrb, in float t) {
vec3 tMin = (boxLlf - rayOrigin) / rayDirection;
vec3 tMax = (boxUrb - rayOrigin) / rayDirection;
// TODO: these many ifs are expensive - the lessThan bvec solution below should be faster but does not work for some reason...
if (tMin.x < t) tMin.x = positiveInfinity;
if (tMin.y < t) tMin.y = positiveInfinity;
if (tMin.z < t) tMin.z = positiveInfinity;
if (tMax.x < t) tMax.x = positiveInfinity;
if (tMax.y < t) tMax.y = positiveInfinity;
if (tMax.z < t) tMax.z = positiveInfinity;
//tMin += vec3(lessThan(tMin, vec3(t, t, t))) * positiveInfinity;
//tMax += vec3(lessThan(tMax, vec3(t, t, t))) * positiveInfinity;
return min(min(tMin.x, min(tMin.y, tMin.z)) , min(tMax.x, min(tMax.y, tMax.z)));
}
/**
* Performs the raycasting and returns the final fragment color.
*/
......
......@@ -139,7 +139,8 @@ namespace campvis {
return toReturn;
}
void OptimizedRaycaster::updateProperties(DataContainer& /*dataContainer*/) {
void OptimizedRaycaster::updateProperties(DataContainer& dataContainer) {
RaycastingProcessor::updateProperties(dataContainer);
p_shadowIntensity.setVisible(p_enableShadowing.getValue());
validate(AbstractProcessor::INVALID_PROPERTIES);
}
......
......@@ -91,7 +91,8 @@ namespace campvis {
return toReturn;
}
void SimpleRaycaster::updateProperties(DataContainer& /*dataContainer*/) {
void SimpleRaycaster::updateProperties(DataContainer& dataContainer) {
RaycastingProcessor::updateProperties(dataContainer);
p_shadowIntensity.setVisible(p_enableShadowing.getValue());
validate(AbstractProcessor::INVALID_PROPERTIES);
}
......
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