Add transferFunction to dataplane

This commit is contained in:
Sebastian Piwell
2016-04-26 14:50:50 -04:00
parent f6a6245795
commit b67180e325
9 changed files with 34 additions and 8 deletions

BIN
data/colormap_parula.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

BIN
data/colormap_parula.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

View File

@@ -41,6 +41,7 @@ namespace openspace {
TransferFunction(const std::string& filepath, TfChangedCallback tfChangedCallback = TfChangedCallback());
void setPath(const std::string& filepath);
ghoul::opengl::Texture& getTexture();
void bind();
void update();
glm::vec4 sample(size_t t);
size_t width();

View File

@@ -93,7 +93,7 @@ void CygnetPlane::render(const RenderData& data){
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", transform);
_shader->setUniform("background", _backgroundValue);
// _shader->setUniform("background", _backgroundValue);
// _shader->setUniform("top", _topColor.value());
// _shader->setUniform("mid", _midColor.value());
@@ -102,11 +102,22 @@ void CygnetPlane::render(const RenderData& data){
setPscUniforms(*_shader.get(), data.camera, position);
ghoul::opengl::TextureUnit tfUnit;
if(_transferFunction){
tfUnit.activate();
_transferFunction->bind();
_shader->setUniform("tf", tfUnit);
}
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_shader->setUniform("texture1", unit);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
@@ -145,13 +156,12 @@ void CygnetPlane::update(const UpdateData& data){
if(loadTexture())
_futureObject = nullptr;
}
if(_transferFunction)
_transferFunction->update();
}
void CygnetPlane::createPlane(){
GLUquadricObj *Cylinder; // Create pointer for our cylinder
Cylinder = gluNewQuadric();
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer

View File

@@ -107,6 +107,8 @@ bool DataPlane::initialize(){
updateTexture();
std::string tfPath = "${OPENSPACE_DATA}/colormap_parula.jpg";
_transferFunction = std::make_shared<TransferFunction>(tfPath);
// std::cout << "Creating Colorbar" << std::endl;
// _colorbar = std::make_shared<ColorBar>();
// if(_colorbar){

View File

@@ -36,6 +36,8 @@ ISWACygnet::ISWACygnet(const ghoul::Dictionary& dictionary)
, _shader(nullptr)
, _texture(nullptr)
, _memorybuffer("")
,_transferFunction(nullptr)
,_tfTexture(nullptr)
{
_data = std::make_shared<Metadata>();

View File

@@ -44,6 +44,7 @@
#include <modules/iswa/util/iswamanager.h>
#include <ghoul/misc/dictionary.h>
#include <openspace/rendering/renderable.h>
#include <openspace/rendering/transferfunction.h>
namespace openspace{
@@ -106,6 +107,8 @@ protected:
std::chrono::milliseconds _lastUpdateRealTime;
int _minRealTimeUpdateInterval;
std::shared_ptr<TransferFunction> _transferFunction;
int _id;
};

View File

@@ -23,8 +23,9 @@
****************************************************************************************/
uniform float time;
uniform sampler2D texture1;
uniform sampler2D tf;
uniform float background;
// uniform float background;
in vec2 vs_st;
in vec4 vs_position;
@@ -37,8 +38,10 @@ Fragment getFragment() {
float depth = pscDepth(position);
vec4 diffuse;
diffuse = texture(texture1, vec2(vs_st.s, 1-vs_st.t));
//float v = texture(texture1, vec2(vs_st.s, 1-vs_st.t)).r;
// diffuse = texture(tf, vec2(1-vs_st.s, 0));
// diffuse = texture(tf, texture(texture1, vec2(vs_st.s,1-vs_st.t)).r);
float v = texture(texture1, vec2(vs_st.s, 1-vs_st.t)).r;
diffuse = texture(tf, vec2(v,0));
// if (diffuse.a <= 0.05)
// discard;

View File

@@ -224,4 +224,9 @@ size_t TransferFunction::width() {
update();
return _texture->width();
}
void TransferFunction::bind() {
update();
_texture->bind();
}
}