Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

Commit ac1d35e4 authored by Jakob Weiss's avatar Jakob Weiss

vis module extension: background decorator can now use textures (either ImageData or RenderData)

The background decorator can now blend a texture as well as the color gradient. Currently, at fragments where the texture is (0,0,0,0), it will still use the gradient. Also fixes ProcessorDecoratorBackground::addProperties which did not override AbstractProcessorDecorator::addProperties before due to signature mismatch.
parent 180238b4
......@@ -22,15 +22,37 @@
//
// ================================================================================================
uniform bool _backgroundHasTexture;
uniform vec4 _backgroundColor1;
uniform vec4 _backgroundColor2;
uniform sampler2D _backgroundTexture;
void renderBackground(in vec2 texCoords, out vec4 outColor) {
outColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
if(_backgroundHasTexture) {
outColor = texture(_backgroundTexture, texCoords);
if(outColor.a == 0.0)
outColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
}
else {
outColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
}
gl_FragDepth = 1.0;
}
vec4 blendBackground(in vec2 texCoords, in vec4 outColor) {
vec4 backgroundColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
vec4 backgroundColor;
if(_backgroundHasTexture) {
backgroundColor = texture(_backgroundTexture, texCoords);
if(dot(backgroundColor,backgroundColor) == 0.0)
backgroundColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
}
else
backgroundColor = mix(_backgroundColor1, _backgroundColor2, 0.5 * (texCoords.x + texCoords.y));
return vec4(mix(backgroundColor.rgb, outColor.rgb, outColor.a), backgroundColor.a);
}
\ No newline at end of file
......@@ -25,14 +25,20 @@
#include "processordecoratorbackground.h"
#include "cgt/shadermanager.h"
#include "cgt/textureunit.h"
#include "core/properties/propertycollection.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/renderdata.h"
namespace campvis {
ProcessorDecoratorBackground::ProcessorDecoratorBackground()
: AbstractProcessorDecorator()
, _backgroundColor1("backgroundColor1", "Background Color 1", cgt::vec4(.9f, .9f, .9f, 1), cgt::vec4(0.f), cgt::vec4(1.f))
, _backgroundColor2("backgroundColor2", "Background Color 2", cgt::vec4(.6f, .6f, .6f, 1), cgt::vec4(0.f), cgt::vec4(1.f))
, _backgroundTexture("backgroundTexture", "Background Texture", "", DataNameProperty::READ)
{
}
......@@ -40,14 +46,43 @@ namespace campvis {
}
void ProcessorDecoratorBackground::addProperties(HasPropertyCollection* propCollection) {
void ProcessorDecoratorBackground::addProperties(AbstractProcessor* propCollection) {
propCollection->addProperty(_backgroundColor1);
propCollection->addProperty(_backgroundColor2);
propCollection->addProperty(_backgroundTexture);
}
void ProcessorDecoratorBackground::renderProlog(const DataContainer& dataContainer, cgt::Shader* shader) {
ImageRepresentationGL::ScopedRepresentation bg(dataContainer, _backgroundTexture.getValue(), true);
ScopedTypedData<RenderData> bgRd(dataContainer, _backgroundTexture.getValue(), true);
bool hasBackgroundTexture = false;
if (bg) {
hasBackgroundTexture = true;
_bgTexUnit = std::make_shared<cgt::TextureUnit>(); // reserve a texture unit
bg->bind(shader, *_bgTexUnit, "_backgroundTexture", "_backgroundTextureParams");
}
else if (bgRd) {
if (auto imageData = bgRd->getColorTexture(0)) {
auto imageRep = imageData->getRepresentation<ImageRepresentationGL>();
if (imageRep) {
hasBackgroundTexture = true;
_bgTexUnit = std::make_shared<cgt::TextureUnit>(); // reserve a texture unit
imageRep->bind(shader, *_bgTexUnit, "_backgroundTexture", "_backgroundTextureParams");
}
}
}
shader->setUniform("_backgroundHasTexture", hasBackgroundTexture);
shader->setUniform("_backgroundColor1", _backgroundColor1.getValue());
shader->setUniform("_backgroundColor2", _backgroundColor2.getValue());
}
}
void ProcessorDecoratorBackground::renderEpilog(cgt::Shader * shader)
{
// free the texture unit
_bgTexUnit = nullptr;
}
}
\ No newline at end of file
......@@ -27,6 +27,11 @@
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/datanameproperty.h"
namespace cgt {
class TextureUnit;
}
namespace campvis {
......@@ -36,13 +41,17 @@ namespace campvis {
virtual ~ProcessorDecoratorBackground();
protected:
void addProperties(HasPropertyCollection* propCollection);
void addProperties(AbstractProcessor* propCollection) override;
virtual void renderProlog(const DataContainer& dataContainer, cgt::Shader* shader) override;
virtual void renderProlog(const DataContainer& dataContainer, cgt::Shader* shader);
virtual void renderEpilog(cgt::Shader* shader) override;
Vec4Property _backgroundColor1;
Vec4Property _backgroundColor2;
DataNameProperty _backgroundTexture;
std::shared_ptr<cgt::TextureUnit> _bgTexUnit;
};
}
......
......@@ -82,7 +82,6 @@ namespace campvis {
addProperty(p_enableScribbling, VALID);
addDecorator(new ProcessorDecoratorBackground());
decoratePropertyCollection(this);
p_seProperties.addPropertyCollection(*_sliceRenderer);
_sliceRenderer->p_lqMode.setVisible(false);
......@@ -110,6 +109,8 @@ namespace campvis {
_sliceRenderer->setViewportSizeProperty(&p_smallRenderSize);
_raycaster.setViewportSizeProperty(&p_largeRenderSize);
decoratePropertyCollection(this);
addProperty(p_smallRenderSize, VALID);
addProperty(p_largeRenderSize, VALID);
......
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