In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit 9d605fb4 authored by schultezub's avatar schultezub

Added preliminary rendering of 3D textures in DataContainerInspectorCanvas

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@399 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 1de68ac3
......@@ -13,6 +13,8 @@ FILE(GLOB CampvisApplicationSources
FILE(GLOB CampvisApplicationHeaders
*.h
glsl/*.frag
glsl/*.vert
gui/*.h
gui/properties/*.h
tools/*.h
......
......@@ -33,14 +33,35 @@ in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/texture2d.frag"
uniform Texture2D _texture;
#include "tools/texture3d.frag"
uniform Texture2D _texture2d;
uniform Texture3D _texture3d;
uniform bool _is3d;
uniform int _sliceNumber;
uniform vec4 _color;
const vec4 checkerboardColor1 = vec4(0.75, 0.75, 0.75, 1.0);
const vec4 checkerboardColor2 = vec4(0.50, 0.50, 0.50, 1.0);
void main() {
out_Color = getElement2DNormalized(_texture, ex_TexCoord.xy);
if (_is3d) {
if (_sliceNumber < 0) {
// perform MIP
out_Color = vec4(0.0);
for (float slice = 0.0; slice < 1.0; slice += _texture3d._sizeRCP.z) {
out_Color = max(out_Color, getElement3DNormalized(_texture3d, vec3(ex_TexCoord.xy, slice)));
}
}
else {
// render the corresponding slice
vec3 coord = vec3(ex_TexCoord.xy, _texture3d._sizeRCP.z * _sliceNumber);
out_Color = getElement3DNormalized(_texture3d, coord);
}
}
else {
out_Color = getElement2DNormalized(_texture2d, ex_TexCoord.xy);
}
// mix with fancy checkerboard pattern:
if ((mod(ex_TexCoord.x * 10.0, 2.0) > 1.0) ^^ (mod(ex_TexCoord.y * 10.0, 2.0) > 1.0))
......
......@@ -141,8 +141,7 @@ namespace campvis {
std::vector<const tgt::Texture*> textures;
for (std::map<std::string, DataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageDataGL* imgGL = dynamic_cast<const ImageDataGL*>(it->second.getData())) {
if (imgGL->getDimensionality() == 2)
textures.push_back(imgGL->getTexture());
textures.push_back(imgGL->getTexture());
}
else if (const ImageDataRenderTarget* imgRT = dynamic_cast<const ImageDataRenderTarget*>(it->second.getData())) {
if (imgRT->getDimensionality() == 2) {
......@@ -187,15 +186,15 @@ namespace campvis {
tgt::mat4 projection = tgt::mat4::createOrtho(0, size_.x, 0, size_.y, -1, 1);
_paintShader->setUniform("_projectionMatrix", projection);
tgt::TextureUnit tu;
tu.activate();
_paintShader->setUniform("_texture._texture", tu.getUnitNumber());
tgt::TextureUnit unit2d, unit3d;
_paintShader->setUniform("_texture2d._texture", unit2d.getUnitNumber());
_paintShader->setUniform("_texture3d._texture", unit3d.getUnitNumber());
if (_renderFullscreen) {
if(_selectedTexture >= 0 && _selectedTexture < (int)textures.size()) {
tgt::mat4 scaleMatrix = tgt::mat4::createScale(tgt::vec3(size_, 1.f));
_paintShader->setUniform("_modelMatrix", scaleMatrix);
paintTexture(textures[_selectedTexture]);
paintTexture2D(textures[_selectedTexture], unit2d, unit3d);
}
}
else {
......@@ -208,7 +207,7 @@ namespace campvis {
tgt::mat4 scaleMatrix = tgt::mat4::createScale(tgt::vec3(_quadSize, 1.f));
tgt::mat4 translation = tgt::mat4::createTranslation(tgt::vec3(_quadSize.x * x, _quadSize.y * y, 0.f));
_paintShader->setUniform("_modelMatrix", translation * scaleMatrix);
paintTexture(textures[index]);
paintTexture2D(textures[index], unit2d, unit3d);
}
}
}
......@@ -218,12 +217,24 @@ namespace campvis {
glPopAttrib();
}
void DataContainerInspectorCanvas::paintTexture(const tgt::Texture* texture) {
texture->bind();
void DataContainerInspectorCanvas::paintTexture2D(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d) {
_paintShader->setIgnoreUniformLocationError(true);
_paintShader->setUniform("_texture._size", tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_texture._sizeRCP", tgt::vec2(1.f) / tgt::vec2(texture->getDimensions().xy()));
if (texture->getDimensions().z == 1) {
unit2d.activate();
texture->bind();
_paintShader->setUniform("_is3d", false);
_paintShader->setUniform("_texture2d._size", tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_texture2d._sizeRCP", tgt::vec2(1.f) / tgt::vec2(texture->getDimensions().xy()));
}
else {
unit3d.activate();
texture->bind();
_paintShader->setUniform("_is3d", true);
_paintShader->setUniform("_sliceNumber", -1);
_paintShader->setUniform("_texture3d._size", tgt::vec3(texture->getDimensions()));
_paintShader->setUniform("_texture3d._sizeRCP", tgt::vec3(1.f) / tgt::vec3(texture->getDimensions()));
}
_paintShader->setIgnoreUniformLocationError(false);
_quad->render();
......
......@@ -123,11 +123,11 @@ namespace campvis {
void invalidate();
/**
* Renders the given texture.
* Renders the given 2D texture.
* Binds the texture to the shader, sets the uniforms and renders the quad.
* \param texture The texture to render.
*/
void paintTexture(const tgt::Texture* texture);
void paintTexture2D(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d);
/**
* Creates the quad used for rendering the textures.
......
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