The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit 2944a868 authored by schultezub's avatar schultezub
Browse files

* added cold/warm color coding to DepthDarkening processor

 * added hard shadows to SimpleRaycaster

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@302 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent b81b25e0
......@@ -49,12 +49,18 @@ namespace TUMVis {
, _outputImage("OutputImage", "Output Image", "dd.output", DataNameProperty::WRITE)
, _sigma("Sigma", "Sigma of Gaussian Filter", 2.f, 0.f, 10.f)
, _lambda("Lambda", "Strength of Depth Darkening Effect", 10.f, 0.f, 50.f)
, _useColorCoding("UseColorCoding", "Cold/Warm Color Coding", false, InvalidationLevel::INVALID_SHADER)
, _coldColor("ColdColor", "Cold Color (Far Objects)", tgt::vec3(0.f, 0.f, 1.f), tgt::vec3(0.f), tgt::vec3(1.f))
, _warmColor("WarmColor", "Warm Color (Near Objects)", tgt::vec3(1.f, 0.f, 0.f), tgt::vec3(0.f), tgt::vec3(1.f))
, _shader(0)
{
addProperty(&_inputImage);
addProperty(&_outputImage);
addProperty(&_sigma);
addProperty(&_lambda);
addProperty(&_useColorCoding);
addProperty(&_coldColor);
addProperty(&_warmColor);
}
DepthDarkening::~DepthDarkening() {
......@@ -63,7 +69,7 @@ namespace TUMVis {
void DepthDarkening::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/vis/depthdarkening.frag", "", false);
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/vis/depthdarkening.frag", generateHeader(), false);
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
}
......@@ -77,6 +83,11 @@ namespace TUMVis {
DataContainer::ScopedTypedData<ImageDataRenderTarget> inputImage(data, _inputImage.getValue());
if (inputImage != 0) {
if (_invalidationLevel.isInvalidShader()) {
_shader->setHeaders(generateHeader());
_shader->rebuild();
}
// TODO: const cast is ugly...
const_cast<tgt::Texture*>(inputImage->getDepthTexture())->downloadTexture();
float* pixels = (float*)inputImage->getDepthTexture()->getPixelData();
......@@ -107,6 +118,10 @@ namespace TUMVis {
_shader->setUniform("_lambda", _lambda.getValue());
_shader->setUniform("_minDepth", minDepth);
_shader->setUniform("_maxDepth", maxDepth);
if (_useColorCoding.getValue()) {
_shader->setUniform("_coldColor", _coldColor.getValue());
_shader->setUniform("_warmColor", _warmColor.getValue());
}
tempTarget->activate();
LGL_ERROR;
......@@ -140,5 +155,12 @@ namespace TUMVis {
_invalidationLevel.setValid();
}
std::string DepthDarkening::generateHeader() const {
if (_useColorCoding.getValue())
return "#define USE_COLORCODING\n";
else
return "";
}
}
......@@ -44,6 +44,9 @@ uniform float _lambda;
uniform float _minDepth;
uniform float _maxDepth;
uniform vec3 _coldColor;
uniform vec3 _warmColor;
int _halfKernelDimension;
float[25] _gaussKernel;
float _norm;
......@@ -113,9 +116,15 @@ void main() {
if (curColor.a == 0)
discard;
#ifdef USE_COLORCODING
float deltaDPlus = (deltaD > 0 ? deltaD : 0.0);
float deltaDMinus = (deltaD < 0 ? -deltaD : 0.0);
curColor.rgb += (_coldColor * deltaDMinus + _warmColor * deltaDPlus) * _lambda;
#else
if (deltaD < 0.0) {
curColor.rgb += deltaD * _lambda;
}
#endif
// write out modulated color and original depth value
out_Color = curColor;
......
......@@ -76,7 +76,17 @@ namespace TUMVis {
FloatProperty _sigma; ///< sigma, standard deviation of the gaussian filter
FloatProperty _lambda; ///< strength of depth effect
BoolProperty _useColorCoding; ///< Flag whether to use depth color coding
Vec3Property _coldColor; ///< Cold color (color for far objects)
Vec3Property _warmColor; ///< Warm color (color for near objects)
protected:
/**
* Generates the GLSL Header
* \return #define uSE_COLORCODING if _useColorCoding is set
*/
std::string generateHeader() const;
tgt::Shader* _shader; ///< Shader for slice rendering
static const std::string loggerCat_;
......
......@@ -38,9 +38,11 @@ namespace TUMVis {
SimpleRaycaster::SimpleRaycaster(GenericProperty<tgt::ivec2>& canvasSize)
: RaycastingProcessor(canvasSize, "modules/vis/simpleraycaster.frag", true)
, _targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, _enableShadowing("EnableShadowing", "Enable Hard Shadows", false, InvalidationLevel::INVALID_SHADER)
{
addDecorator(new ProcessorDecoratorShading());
addProperty(&_enableShadowing);
addProperty(&_targetImageID);
decoratePropertyCollection(this);
......@@ -70,4 +72,12 @@ namespace TUMVis {
data.addData(_targetImageID.getValue(), output);
_targetImageID.issueWrite();
}
std::string SimpleRaycaster::generateHeader() const {
std::string toReturn = RaycastingProcessor::generateHeader();
if (_enableShadowing.getValue())
toReturn += "#define ENABLE_SHADOWING\n";
return toReturn;
}
}
......@@ -82,8 +82,34 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
vec3 gradient = computeGradient(_volume, samplePosition);
vec4 color = lookupTF(_tfTextureParameters, _tfTex, intensity);
#ifdef ENABLE_SHADOWING
// simple and expensive implementation of hard shadows
if (color.a > 0.1) {
// compute direction from sample to light
vec3 L = normalize(_lightSource._position - textureToWorld(_volume, samplePosition).xyz) * _samplingStepSize;
bool finished = false;
vec3 position = samplePosition + L;
float shadowFactor = 0.0;
// traverse ray from sample to light
while (! finished) {
// grab intensity and TF opacity
intensity = getElement3DNormalized(_volume, position).a;
shadowFactor += lookupTF(_tfTextureParameters, _tfTex, intensity).a;
position += L;
finished = (shadowFactor > 0.95)
|| any(lessThan(position, vec3(0.0, 0.0, 0.0)))
|| any(greaterThan(position, vec3(1.0, 1.0, 1.0)));
}
// apply shadow to color
color.rgb *= (1.0 - shadowFactor);
}
#endif
#ifdef ENABLE_SHADING
color.rgb = calculatePhongShading(textureToWorld(_volume, samplePosition).xyz, _lightSource, _cameraPosition, gradient, color.xyz, color.xyz, vec3(1.0, 1.0, 1.0));
color.rgb = calculatePhongShading(textureToWorld(_volume, samplePosition).xyz, _lightSource, _cameraPosition, gradient, color.rgb, color.rgb, vec3(1.0, 1.0, 1.0));
#endif
// perform compositing
......
......@@ -64,11 +64,15 @@ namespace TUMVis {
virtual const std::string getDescription() const { return "Performs a simple volume ray casting."; };
DataNameProperty _targetImageID; ///< image ID for output image
BoolProperty _enableShadowing;
protected:
/// \see RaycastingProcessor::processImpl()
virtual void processImpl(DataContainer& data);
/// \see RaycastingProcessor::generateHeader()
virtual std::string generateHeader() const;
static const std::string loggerCat_;
};
......
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