Commit 030250bf authored by schultezub's avatar schultezub
Browse files

Tidied up GLSL includes:

 * samplerXd.frag is now textureXd.frag
 * TextureParameters is now TextureXd and contains also the handle to the GLSL texture2d.frag
 * simplified getElementXd footprint: now only one texture parameter
 * adapted bind() methods of textures

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@220 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 20d6ef26
......@@ -76,7 +76,7 @@ namespace TUMVis {
// bind input textures
tgt::TextureUnit colorUnit, depthUnit;
image->bind(_copyShader, colorUnit, depthUnit);
image->bind(_copyShader, &colorUnit, &depthUnit);
LGL_ERROR;
// execute the shader
......
......@@ -71,13 +71,32 @@ namespace TUMVis {
_texture->bind();
}
void ImageDataGL::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& texUniform /*= "_texture"*/, const std::string& textureParametersUniform /*= "_textureParameters"*/) const {
void ImageDataGL::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& texUniform /*= "_texture"*/) const {
bind(texUnit);
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
shader->setUniform(texUniform, texUnit.getUnitNumber());
shader->setUniform(textureParametersUniform + "._size", tgt::vec2(_size.xy()));
shader->setUniform(textureParametersUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(_size.xy()));
switch (_dimensionality) {
case 1:
LERROR("Setting um 1D texture uniforms currently not implemented - you probably wanna do that yourself...");
break;
case 2:
shader->setUniform(texUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(texUniform + "._size", tgt::vec2(_size.xy()));
shader->setUniform(texUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(_size.xy()));
break;
case 3:
shader->setUniform(texUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(texUniform + "._size", tgt::vec3(_size));
shader->setUniform(texUniform + "._sizeRCP", tgt::vec3(1.f) / tgt::vec3(_size));
break;
default:
tgtAssert(false, "Should not reach this!");
break;
}
shader->setIgnoreUniformLocationError(tmp);
}
......
......@@ -74,8 +74,7 @@ namespace TUMVis {
void bind(
tgt::Shader* shader,
const tgt::TextureUnit& texUnit,
const std::string& texUniform = "_texture",
const std::string& textureParametersUniform = "_textureParameters") const;
const std::string& texUniform = "_texture") const;
......
......@@ -127,13 +127,18 @@ namespace TUMVis {
_depthTexture->bind();
}
void ImageDataRenderTarget::bind(tgt::Shader* shader, const tgt::TextureUnit& colorTexUnit, const tgt::TextureUnit& depthTexUnit, const std::string& colorTexUniform /*= "_colorTexture"*/, const std::string& depthTexUniform /*= "_depthTexture"*/, const std::string& textureParametersUniform /*= "_textureParameters"*/) const {
bindColorTexture(colorTexUnit);
bindDepthTexture(depthTexUnit);
void ImageDataRenderTarget::bind(tgt::Shader* shader, const tgt::TextureUnit* colorTexUnit, const tgt::TextureUnit* depthTexUnit, const std::string& colorTexUniform /*= "_colorTexture"*/, const std::string& depthTexUniform /*= "_depthTexture"*/, const std::string& textureParametersUniform /*= "_textureParameters"*/) const {
if (colorTexUnit != 0)
bindColorTexture(*colorTexUnit);
if (depthTexUnit != 0)
bindDepthTexture(*depthTexUnit);
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
shader->setUniform(colorTexUniform, colorTexUnit.getUnitNumber());
shader->setUniform(depthTexUniform, depthTexUnit.getUnitNumber());
if (colorTexUnit != 0)
shader->setUniform(colorTexUniform, colorTexUnit->getUnitNumber());
if (depthTexUnit != 0)
shader->setUniform(depthTexUniform, depthTexUnit->getUnitNumber());
shader->setUniform(textureParametersUniform + "._size", tgt::vec2(_size.xy()));
shader->setUniform(textureParametersUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(_size.xy()));
shader->setIgnoreUniformLocationError(tmp);
......
......@@ -82,10 +82,22 @@ namespace TUMVis {
*/
void bindDepthTexture(const tgt::TextureUnit& texUnit) const;
/**
* Binds the textures of this render target and sets the according shader uniforms.
* Of \a colorTexUnit or \a depthTexUnit is 0, the corresponding texture will not be bound
* and the corresponding uniforms will not be set.
*
* \param shader Shader to set the uniforms to.
* \param colorTexUnit Pointer to color texture unit, may be 0.
* \param depthTexUnit Pointer to depth texture unit, may be 0.
* \param colorTexUniform Name for color texture unit uniform.
* \param depthTexUniform Name for depth texture unit uniform.
* \param textureParametersUniform Name for texture parameters uniform.
*/
void bind(
tgt::Shader* shader,
const tgt::TextureUnit& colorTexUnit,
const tgt::TextureUnit& depthTexUnit,
const tgt::TextureUnit* colorTexUnit,
const tgt::TextureUnit* depthTexUnit,
const std::string& colorTexUniform = "_colorTexture",
const std::string& depthTexUniform = "_depthTexture",
const std::string& textureParametersUniform = "_textureParameters") const;
......
#include "tools/sampler2d.frag"
#include "tools/texture2d.frag"
uniform vec2 _viewportSize;
uniform vec2 _viewportSizeRCP;
uniform sampler2D _colorTexture;
uniform sampler2D _depthTexture;
uniform TextureParameters _textureParameters;
uniform Texture2D _colorTexture;
uniform Texture2D _depthTexture;
void main() {
vec2 fragCoord = gl_FragCoord.xy * _viewportSizeRCP;
gl_FragData[0] = getElement2DNormalized(_colorTexture, _textureParameters, fragCoord);
gl_FragDepth = getElement2DNormalized(_depthTexture, _textureParameters, fragCoord).z;
gl_FragData[0] = getElement2DNormalized(_colorTexture, fragCoord);
gl_FragDepth = getElement2DNormalized(_depthTexture, fragCoord).z;
}
// TODO: implement coordinate transformation using a trafo matrix?
struct TextureParameters {
struct Texture2D {
sampler2D _texture;
vec2 _size;
vec2 _sizeRCP;
};
/**
* Texture lookup function for 2D textures using pixel coordinates, i.e [(0,0) , textureSize].
* \param tex 2D texture for lookup
* \param texParams Corresponding texture parameters struct
* \param tex Texture2D struct with texture for lookup
* \param texCoords Lookup coordinates in pixel coordinates
* \return The texel at the given coordinates.
*/
vec4 getElement2D(in sampler2D tex, in TextureParameters texParams, in vec2 texCoords) {
vec2 texCoordsNormalized = texCoords * texParams._sizeRCP;
vec4 getElement2D(in Texture2D tex, in vec2 texCoords) {
vec2 texCoordsNormalized = texCoords * tex._sizeRCP;
//vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoordsNormalized, 0.0, 1.0)).xy;
return texture2D(tex, texCoordsNormalized);
return texture2D(tex._texture, texCoordsNormalized);
}
/**
* Texture lookup function for 2D textures using normalized texture coordinates, i.e. [0,1].
* \param tex 2D texture for lookup
* \param texParams Corresponding texture parameters struct
* \param tex Texture2D struct with texture for lookup
* \param texCoords Lookup coordinates in normlized texture coordinates
* \return The texel at the given coordinates.
*/
vec4 getElement2DNormalized(in sampler2D tex, in TextureParameters texParams, in vec2 texCoords) {
vec4 getElement2DNormalized(in Texture2D tex, in vec2 texCoords) {
//vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoords, 0.0, 1.0)).xy;
return texture2D(tex, texCoords);
return texture2D(tex._texture, texCoords);
}
// TODO: implement coordinate transformation using a trafo matrix?
struct Texture3D {
// The texture
sampler3D _texture;
// Texture size
vec3 _size;
vec3 _sizeRCP;
};
/**
* Texture lookup function for 3D textures using pixel coordinates, i.e [(0,0) , textureSize].
* \param tex Texture3D struct with texture for lookup
* \param texCoords Lookup coordinates in pixel coordinates
* \return The texel at the given coordinates.
*/
vec4 getElement3D(in Texture3D tex, in vec3 texCoords) {
vec3 texCoordsNormalized = texCoords * tex._sizeRCP;
//vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoordsNormalized, 0.0, 1.0)).xy;
return texture3D(tex._texture, texCoordsNormalized);
}
/**
* Texture lookup function for 3D textures using normalized texture coordinates, i.e. [0,1].
* \param tex Texture3D struct with texture for lookup
* \param texCoords Lookup coordinates in normlized texture coordinates
* \return The texel at the given coordinates.
*/
vec4 getElement3DNormalized(in Texture3D tex, in vec3 texCoords) {
//vec2 texCoordsTransformed = (texParams.matrix_ * vec4(texCoords, 0.0, 1.0)).xy;
return texture3D(tex._texture, texCoords);
}
......@@ -6,12 +6,8 @@
#include "tgt/shadermanager.h"
#include "tgt/textureunit.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagedatagl.h"
#include "core/datastructures/imagedatarendertarget.h"
#include "core/datastructures/imagedataconverter.h"
#include "core/classification/simpletransferfunction.h"
namespace TUMVis {
const std::string EEPGenerator::loggerCat_ = "TUMVis.modules.vis.EEPGenerator";
......@@ -28,6 +24,8 @@ namespace TUMVis {
addProperty(&_entryImageID);
addProperty(&_exitImageID);
addProperty(&_camera);
// TODO: remove this ugly hack: automatically adapt near/far plane to volume extent.
tgt::Camera c;
c.setFarDist(512.f);
_camera.setValue(c);
......@@ -44,6 +42,7 @@ namespace TUMVis {
void EEPGenerator::deinit() {
ShdrMgr.dispose(_shader);
_shader = 0;
VisualizationProcessor::deinit();
}
......
uniform bool _jitterPoints;
void main() {
gl_FragData[0] = gl_TexCoord[0];
}
#include "tools/sampler2d.frag"
#include "tools/texture2d.frag"
#include "tools/transferfunction.frag"
uniform sampler2D _texture;
uniform TextureParameters _textureParameters;
uniform Texture2D _texture;
uniform sampler1D _tfTex;
uniform TFParameters _tfTextureParameters;
void main() {
float intensity = getElement2DNormalized(_texture, _textureParameters, gl_TexCoord[0].xy).a;
float intensity = getElement2DNormalized(_texture, gl_TexCoord[0].xy).a;
gl_FragData[0] = lookupTF(_tfTextureParameters, _tfTex, intensity);
}
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