ABuffer bugfix, now supporting multiple (3+) volumes

This commit is contained in:
Jonas Strandstedt
2014-07-14 11:58:12 -04:00
parent 114af3fb5b
commit bd38dd124e
4 changed files with 32 additions and 18 deletions

View File

@@ -32,6 +32,7 @@
#define SHOWFUNC
// #define JITTERING
#define SHOWENLIL
#define PSCDEPTH 1
#define ZDEPTH 2
@@ -171,13 +172,15 @@ vec4 calculate_final_color(uint frag_count) {
ABufferStruct_t endFrag = fragments[i+1];
int type = int(_type_(startFrag));
if(type == 0)
if(type == 0) {
//blendStep(final_color, _col_(startFrag), stepSize);
final_color = blend(final_color, _col_(startFrag));
} else {
currentVolumeBitmask = currentVolumeBitmask ^ (1 << (type-1));
}
#if MAX_VOLUMES > 0
currentVolumeBitmask = currentVolumeBitmask ^ type;
if(currentVolumeBitmask != 0) {
int volID = type -1;
float p = 0.0f;

View File

@@ -32,7 +32,6 @@ uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
uniform float time;
out vec3 vPosition;
out vec3 worldPosition;

View File

@@ -180,6 +180,7 @@ int ABuffer::addSamplerfile(const std::string& filename) {
_samplers.push_back("");
// ID is one more than "actual" position since ID=0 is considered geometry
//return 1 << (_samplers.size()-1);
return _samplers.size();
}
@@ -306,13 +307,15 @@ std::string ABuffer::openspaceHeaders() {
std::string ABuffer::openspaceSamplerCalls() {
std::string samplercalls;
for (int i = 1; i < 2; ++i) {
for (int i = 0; i < _samplers.size(); ++i) {
auto found1 = _samplers.at(i).find_first_not_of("vec4 ");
auto found2 = _samplers.at(i).find_first_of("(",found1);
if(found1 != std::string::npos && found2 != std::string::npos) {
std::string functionName = _samplers.at(i).substr(found1, found2 - found1);
samplercalls += "if((currentVolumeBitmask & (1 << " + std::to_string(i) + ")) == "+std::to_string(i+1)+") {\n";
if(i == 0)
samplercalls += "#ifdef SHOWENLIL\n";
samplercalls += "if((currentVolumeBitmask & (1 << " + std::to_string(i) + ")) == "+std::to_string(1 << i)+") {\n";
samplercalls += " vec4 c = " + functionName + "(final_color,volume_position[" + std::to_string(i) + "]);\n";
// samplercalls += " if(c.a < 0.1) { \n";
// samplercalls += " if( volumeStepSize[" + std::to_string(i) + "] < 16.0*volumeStepSizeOriginal[" + std::to_string(i) + "]) \n";
@@ -326,6 +329,8 @@ std::string ABuffer::openspaceSamplerCalls() {
// samplercalls += " blendStep(final_color, c, stepSize);\n";
samplercalls += " volume_position[" + std::to_string(i) + "] += volume_direction[" + std::to_string(i) + "]*volumeStepSize[" + std::to_string(i) + "];\n";
samplercalls += "}\n";
if(i == 0)
samplercalls += "#endif\n";
}

View File

@@ -61,6 +61,7 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary):
_transferFunction = nullptr;
_transferFunctionFile = nullptr;
_transferFunctionPath = "";
if (dictionary.hasKey("TransferFunction")) {
std::string transferFunctionPath = "";
if(dictionary.getValue("TransferFunction", transferFunctionPath)) {
@@ -120,22 +121,28 @@ RenderableVolumeGL::~RenderableVolumeGL() {
}
bool RenderableVolumeGL::initialize() {
assert(_filename != "");
// assert(_filename != "");
// ------ VOLUME READING ----------------
_volume = loadVolume(_filename, _hintsDictionary);
_volume->uploadTexture();
_transferFunction = loadTransferFunction(_transferFunctionPath);
_transferFunction->uploadTexture();
// TODO: fix volume an transferfunction names
OsEng.renderEngine().abuffer()->addVolume(_volumeName, _volume);
OsEng.renderEngine().abuffer()->addTransferFunction(_transferFunctionName, _transferFunction);
_id = OsEng.renderEngine().abuffer()->addSamplerfile(_samplerFilename);
if(_filename != "") {
_volume = loadVolume(_filename, _hintsDictionary);
_volume->uploadTexture();
OsEng.renderEngine().abuffer()->addVolume(_volumeName, _volume);
}
auto textureCallback = [this](const ghoul::filesystem::File& file) {
_updateTransferfunction = true;
};
_transferFunctionFile->setCallback(textureCallback);
if(_transferFunctionPath != "") {
_transferFunction = loadTransferFunction(_transferFunctionPath);
_transferFunction->uploadTexture();
OsEng.renderEngine().abuffer()->addTransferFunction(_transferFunctionName, _transferFunction);
auto textureCallback = [this](const ghoul::filesystem::File& file) {
_updateTransferfunction = true;
};
_transferFunctionFile->setCallback(textureCallback);
}
// add the sampler and get the ID
_id = OsEng.renderEngine().abuffer()->addSamplerfile(_samplerFilename);
_box = new sgct_utils::SGCTBox(1.0f, sgct_utils::SGCTBox::Regular);
OsEng.configurationManager().getValue("RaycastProgram", _boxProgram);