Commit d81337c6 authored by schultezub's avatar schultezub

* added detection of double includes in tgt::ShaderPreprocessor

 * added gradient fragment shader include
 * implemented first hit normal computation to SimpleRaycaster

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@294 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 1175aee0
......@@ -119,6 +119,8 @@ namespace TUMVis {
shader->setUniform(texUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(texUniform + "._size", tgt::vec3(_size));
shader->setUniform(texUniform + "._sizeRCP", tgt::vec3(1.f) / tgt::vec3(_size));
shader->setUniform(texUniform + "._voxelSize", _mappingInformation.getVoxelSize());
shader->setUniform(texUniform + "._voxelSizeRCP", tgt::vec3(1.f) / _mappingInformation.getVoxelSize());
break;
default:
......
#include "tools/texture3d.frag"
/**
* Compute the gradient using forward differences on the texture's alpha channel.
* \param tex 3D texture to calculate gradients for
* \param texCoords Lookup position in texture coordinates
*/
vec3 computeGradientForwardDifferences(in Texture3D tex, in vec3 texCoords) {
vec3 offset = tex._sizeRCP;
float v = getElement3DNormalized(tex, texCoords).a;
float dx = getElement3DNormalized(tex, texCoords + vec3(offset.x, 0.0, 0.0)).a;
float dy = getElement3DNormalized(tex, texCoords + vec3(0, offset.y, 0)).a;
float dz = getElement3DNormalized(tex, texCoords + vec3(0, 0, offset.z)).a;
return vec3(v - dx, v - dy, v - dz) * tex._voxelSize;
}
/**
* Compute the gradient using central differences on the texture's alpha channel.
* \param tex 3D texture to calculate gradients for
* \param texCoords Lookup position in texture coordinates
*/
vec3 computeGradientCentralDifferences(in Texture3D tex, in vec3 texCoords) {
vec3 offset = tex._sizeRCP;
float dx = getElement3DNormalized(tex, texCoords + vec3(offset.x, 0.0, 0.0)).a;
float dy = getElement3DNormalized(tex, texCoords + vec3(0, offset.y, 0)).a;
float dz = getElement3DNormalized(tex, texCoords + vec3(0, 0, offset.z)).a;
float mdx = getElement3DNormalized(tex, texCoords + vec3(-offset.x, 0, 0)).a;
float mdy = getElement3DNormalized(tex, texCoords + vec3(0, -offset.y, 0)).a;
float mdz = getElement3DNormalized(tex, texCoords + vec3(0, 0, -offset.z)).a;
return vec3(mdx - dx, mdy - dy, mdz - dz) * tex._voxelSize * vec3(0.5);
}
/**
* Compute the gradient using filtered central differences on the texture's alpha channel.
* \param tex 3D texture to calculate gradients for
* \param texCoords Lookup position in texture coordinates
*/
vec3 computeGradientFilteredCentralDifferences(in Texture3D tex, in vec3 texCoords) {
vec3 offset = tex._sizeRCP;
vec3 g0 = computeGradientCentralDifferences(tex, texCoords);
vec3 g1 = computeGradientCentralDifferences(tex, texCoords + vec3(-offset.x, -offset.y, -offset.z));
vec3 g2 = computeGradientCentralDifferences(tex, texCoords + vec3( offset.x, offset.y, offset.z));
vec3 g3 = computeGradientCentralDifferences(tex, texCoords + vec3(-offset.x, offset.y, -offset.z));
vec3 g4 = computeGradientCentralDifferences(tex, texCoords + vec3( offset.x, -offset.y, offset.z));
vec3 g5 = computeGradientCentralDifferences(tex, texCoords + vec3(-offset.x, -offset.y, offset.z));
vec3 g6 = computeGradientCentralDifferences(tex, texCoords + vec3( offset.x, offset.y, -offset.z));
vec3 g7 = computeGradientCentralDifferences(tex, texCoords + vec3(-offset.x, offset.y, offset.z));
vec3 g8 = computeGradientCentralDifferences(tex, texCoords + vec3( offset.x, -offset.y, -offset.z));
vec3 mix0 = mix(mix(g1, g2, 0.5), mix(g3, g4, 0.5), 0.5);
vec3 mix1 = mix(mix(g5, g6, 0.5), mix(g7, g8, 0.5), 0.5);
return mix(g0, mix(mix0, mix1, 0.5), 0.75);
}
......@@ -35,6 +35,10 @@ struct Texture3D {
// Texture size
vec3 _size;
vec3 _sizeRCP;
// Voxel spacing
vec3 _voxelSize;
vec3 _voxelSizeRCP;
};
/**
......
......@@ -92,32 +92,36 @@ void ShaderPreprocessor::parsePart(const std::string& input, const std::string&
string filename(line, pos + 1, end - pos - 1);
filename = ShdrMgr.completePath(filename);
File* file = FileSys.open(filename);
string content;
if ((!file) || (!file->isOpen())) {
LERROR("Cannot open shader include '" << filename << "' in " << resolveLineNumber(activeLine_, lineTracker_));
if (includedFilenames_.find(filename) == includedFilenames_.end()) {
File* file = FileSys.open(filename);
string content;
if ((!file) || (!file->isOpen())) {
LERROR("Cannot open shader include '" << filename << "' in " << resolveLineNumber(activeLine_, lineTracker_));
}
else {
size_t len = file->size();
// check if file is empty
if (len == 0)
content = "";
else
content = file->getAsString();
file->close();
outputComment("BEGIN INCLUDE " + filename, "BEGIN");
if (!content.empty() && content[content.size() - 1] != '\n')
content += "\n";
parsePart(content, filename);
outputComment("END INCLUDE " + filename, "END");
lineTracker_.push_back(ShaderObject::LineInfo(activeLine_, name, locallinenumber + 1));
}
delete file;
includedFilenames_.insert(filename);
}
else {
size_t len = file->size();
// check if file is empty
if (len == 0)
content = "";
else
content = file->getAsString();
file->close();
outputComment("BEGIN INCLUDE " + filename, "BEGIN");
if (!content.empty() && content[content.size() - 1] != '\n')
content += "\n";
parsePart(content, filename);
outputComment("END INCLUDE " + filename, "END");
lineTracker_.push_back(ShaderObject::LineInfo(activeLine_, name, locallinenumber + 1));
}
delete file;
} else {
result_ << line << "\n";
activeLine_++;
......@@ -129,6 +133,7 @@ void ShaderPreprocessor::parse() {
activeLine_ = 1;
lineTracker_.clear();
result_.clear();
includedFilenames_.clear();
outputComment("BEGIN GLOBAL HEADER");
parsePart(ShdrMgr.getGlobalHeader(), "GLOBAL HEADER");
......
......@@ -26,6 +26,7 @@
#define TGT_SHADERMANAGER_H
#include <list>
#include <set>
#include <string>
#include "tgt/exception.h"
......@@ -542,6 +543,7 @@ protected:
ShaderObject* shd_;
std::vector<ShaderObject::LineInfo>& lineTracker_; ///< keeps track of line numbers when includes are used
std::set<std::string> includedFilenames_; ///< list of all filenames that have already been included (to avoid double inclusion)
int activeLine_;
std::ostringstream result_;
......
......@@ -51,10 +51,11 @@ namespace TUMVis {
void SimpleRaycaster::processImpl(DataContainer& data) {
ImageDataRenderTarget* output = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
output->createAndAttachTexture(GL_RGBA32F);
output->createAndAttachTexture(GL_RGBA32F);
output->activate();
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(2, buffers);
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 , GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, buffers);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_ALWAYS);
......
......@@ -28,9 +28,11 @@
#version 330
layout(location = 0) out vec4 out_Color; ///< outgoing fragment color
layout(location = 1) out vec4 out_FHP; ///< outgoing fragment first hitpoint
layout(location = 0) out vec4 out_Color; ///< outgoing fragment color
layout(location = 1) out vec4 out_FHP; ///< outgoing fragment first hitpoint
layout(location = 2) out vec4 out_FHN; ///< outgoing fragment first hit normal
#include "tools/gradient.frag"
#include "tools/raycasting.frag"
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
......@@ -77,7 +79,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
// perform compositing
if (color.a > 0.0) {
// accomodate for variable sampling rates (base interval defined by mod_compositing.frag)
// accomodate for variable sampling rates
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP);
result.rgb = mix(color.rgb, result.rgb, result.a);
result.a = result.a + (1.0 -result.a) * color.a;
......@@ -87,6 +89,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
if (firstHitT < 0.0 && result.a > 0.0) {
firstHitT = t;
out_FHP = vec4(samplePosition, 1.0);
out_FHN = vec4(normalize(computeGradientCentralDifferences(_volume, samplePosition)), 1.0);
}
// early ray termination
......
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