Commit 2c074ac7 authored by schultezub's avatar schultezub
Browse files

* added ShaderManager::globalHeader_

* added depth calculation fragment shader

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@234 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 1972191d
......@@ -41,7 +41,7 @@ using namespace TUMVis;
**/
int main(int argc, char** argv) {
TumVisApplication app(argc, argv);
//app.addVisualizationPipeline("SliceVis", new SliceVis());
app.addVisualizationPipeline("SliceVis", new SliceVis());
app.addVisualizationPipeline("DVRVis", new DVRVis());
app.init();
......
......@@ -119,7 +119,7 @@ namespace TUMVis {
c.look();
glColor3f(1.f, 0.f, 0.f);
tgt::Sphere sphere(.5f, 64, 32);
//sphere.render();
sphere.render();
/*
// render error texture
......
......@@ -26,11 +26,50 @@
//
// ================================================================================================
/**
* 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);
}
/**
* Converts a depth value in eye space to the corresponding depth value in viewport space.
* \param depth Depth value in eye space.
* \return The given depth value transformed to viewport space.
*/
float depthEyeToViewport(in float depth) {
float f = gl_DepthRange.far;
float n = gl_DepthRange.near;
float diff = gl_DepthRange.diff;
return (1.0/depth)*((f*n)/diff) + 0.5*((f+n)/diff) + 0.5;
}
/**
* Converts a depth value in viewport space to the corresponding depth value in eye space.
* \param depth Depth value in viewport space.
* \return The given depth value transformed to eye space.
*/
float depthViewportToEye(in float depth) {
float f = gl_DepthRange.far;
float n = gl_DepthRange.near;
float diff = gl_DepthRange.diff;
return 1.0/((depth - 0.5 - 0.5*((f+n)/diff)) * (diff/(f*n)));
}
/**
* Interpolates the depth \a ratio in viewport space between \a startDepth and \a endDepth.
* \note Mind the costs: Because the depth in viewport space does not scale linearly, the interpolation
* must be done in eye space. Hence, this method includes two coordinate transformations!
*
* \param ratio Depth value to interpolate given as ratio of endDepth/startDepth.
* \param startDepth Start depth value in viewport space.
* \param endDepth End depth value in viewport space.
* \return The interpolated depth value.
*/
float interpolateDepthViewport(in float ratio, in float startDepth, in float endDepth) {
float startEye = depthViewportToEye(startDepth);
float endEye = depthViewportToEye(endDepth);
return depthEyeToViewport(startEye + ratio*(endEye - startEye));
}
\ No newline at end of file
......@@ -130,6 +130,10 @@ void ShaderPreprocessor::parse() {
lineTracker_.clear();
result_.clear();
outputComment("BEGIN GLOBAL HEADER");
parsePart(ShdrMgr.getGlobalHeader(), "GLOBAL HEADER");
outputComment("END GLOBAL HEADER");
if (!shd_->header_.empty()) {
outputComment("BEGIN HEADER");
parsePart(shd_->header_, "HEADER");
......
......@@ -469,7 +469,25 @@ public:
bool rebuildAllShadersFromFile();
/**
* Sets the global header that will be added to all shaders to \a header.
* \param header The new global header that will be added to all shaders.
*/
void setGlobalHeader(const std::string& header) {
globalHeader_ = header;
}
/**
* Gets the global header that will be added to all shaders.
* \return globalHeader_
*/
const std::string& getGlobalHeader() const {
return globalHeader_;
}
protected:
std::string globalHeader_; ///< Global header that will be added to all shaders.
static const std::string loggerCat_;
};
......
......@@ -50,6 +50,7 @@ namespace TUMVis {
rt->activate();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_ALWAYS);
tgt::QuadRenderer::renderQuad();
LGL_ERROR;
......
......@@ -53,7 +53,7 @@ const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
*/
vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) {
vec4 result = vec4(0.0);
float depthT = -1.0;
float firstHitT = -1.0;
// calculate ray parameters
vec3 direction = exitPoint.rgb - entryPoint.rgb;
......@@ -78,8 +78,8 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
}
// save first hit ray parameter for depth value calculation
if (depthT < 0.0 && result.a > 0.0)
depthT = t;
if (firstHitT < 0.0 && result.a > 0.0)
firstHitT = t;
// early ray termination
if (result.a >= 1.0) {
......@@ -92,10 +92,10 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
// calculate depth value from ray parameter
gl_FragDepth = 1.0;
//if (depthT >= 0.0) {
// float depthEntry = getElement2DNormalized(_entryPointsDepth, texCoords).z;
// float depthExit = getElement2DNormalized(_exitPointsDepth, texCoords).z;
// gl_FragDepth = calculateDepthValue(depthT/tend, depthEntry, depthExit);
//if (firstHitT >= 0.0) {
//float depthEntry = getElement2DNormalized(_entryPointsDepth, texCoords).z;
//float depthExit = getElement2DNormalized(_exitPointsDepth, texCoords).z;
//gl_FragDepth = interpolateDepthViewport(firstHitT/tend, depthEntry, depthExit);
//}
return result;
......
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