mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 20:39:08 -06:00
Changing the hardcoded bv-color map to a transfer function based map
This commit is contained in:
Submodule ext/ghoul updated: d9f7c14081...2d0bdf40b6
@@ -60,9 +60,14 @@ private:
|
||||
bool loadCachedFile(const std::string& file);
|
||||
bool saveCachedFile(const std::string& file) const;
|
||||
|
||||
properties::StringProperty _pointSpreadFunctionTexturePath;
|
||||
ghoul::opengl::Texture* _pointSpreadFunctionTexture;
|
||||
bool _pointSpreadFunctionTextureIsDirty;
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
bool _textureIsDirty;
|
||||
ghoul::opengl::Texture* _colorTexture;
|
||||
bool _colorTextureIsDirty;
|
||||
|
||||
|
||||
properties::OptionProperty _colorOption;
|
||||
bool _dataIsDirty;
|
||||
|
||||
@@ -95,6 +95,7 @@ namespace modelgeometry {
|
||||
namespace renderablestars {
|
||||
const std::string keyFile = "File";
|
||||
const std::string keyTexture = "Texture";
|
||||
const std::string keyColorMap = "ColorMap";
|
||||
} // namespace renderablestars
|
||||
|
||||
namespace renderablevolumegl {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
const float k = 10.0;
|
||||
const float FLT_MAX = 1e38; // Not max but large enough for the purpose
|
||||
|
||||
float log10( float x ) {
|
||||
float log10(float x) {
|
||||
return log(x) / log(10);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ const int COLOROPTION_COLOR = 0;
|
||||
const int COLOROPTION_VELOCITY = 1;
|
||||
const int COLOROPTION_SPEED = 2;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D psfTexture;
|
||||
uniform sampler1D colorTexture;
|
||||
uniform vec3 Color;
|
||||
|
||||
uniform int colorOption;
|
||||
@@ -47,73 +48,21 @@ layout(location = 4) in vec2 texCoord;
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// @BUG If c is uninitialized, the flickering bug is present, if it is initialized
|
||||
// to 0, those stars disappear completely ---abock
|
||||
|
||||
vec3 bv2rgb(float bv) // RGB <0,1> <- BV <-0.4,+2.0> [-]
|
||||
{
|
||||
float t = 0.0;
|
||||
vec3 c = vec3(0.0);
|
||||
|
||||
bv = clamp(bv, -0.4, 2.0);
|
||||
|
||||
if ((bv >= -0.4) && (bv < 0.0)) {
|
||||
t = (bv+0.40)/(0.00+0.40);
|
||||
c.r = 0.61+(0.11*t)+(0.1*t*t);
|
||||
}
|
||||
else if ((bv >= 0.0) && (bv < 0.4)) {
|
||||
t = (bv-0.0)/(0.4-0.0);
|
||||
c.r = 0.83+(0.17*t);
|
||||
}
|
||||
else if ((bv >= 0.4) && (bv < 2.1)) {
|
||||
t = (bv-0.4)/(2.1-0.4);
|
||||
c.r = 1.00;
|
||||
}
|
||||
|
||||
if ((bv >= -0.4) && (bv < 0.0)) {
|
||||
t = (bv+0.4)/(0.4);
|
||||
c.g = 0.70+(0.07*t)+(0.1*t*t);
|
||||
}
|
||||
else if ((bv >= 0.0) && (bv < 0.4)) {
|
||||
t = bv/0.40;
|
||||
c.g = 0.87+(0.11*t);
|
||||
}
|
||||
else if ((bv >= 0.4) && (bv < 1.6)) {
|
||||
t = (bv-0.4)/(1.6-0.4);
|
||||
c.g = 0.98-(0.16*t);
|
||||
}
|
||||
else if ((bv >= 1.60) && (bv < 2.00)) {
|
||||
t = (bv-1.6)/(2.0-1.6);
|
||||
c.g = 0.82-(0.5*t*t);
|
||||
}
|
||||
|
||||
if ((bv >= -0.40) && (bv < 0.4)) {
|
||||
t = (bv+0.40)/(0.4+0.4);
|
||||
c.b=1.00;
|
||||
}
|
||||
else if ((bv >= 0.4) && (bv < 1.5)) {
|
||||
t = (bv-0.4)/(1.5-0.4);
|
||||
c.b = 1.0-(0.47*t)+(0.1*t*t);
|
||||
}
|
||||
else if ((bv >= 1.5) && (bv < 1.94)) {
|
||||
t = (bv-1.5)/(1.94-1.5);
|
||||
c.b = 0.63-(0.6*t*t);
|
||||
}
|
||||
|
||||
return c;
|
||||
vec4 bv2rgb(float bv) {
|
||||
// BV is [-0.4,2.0]
|
||||
float t = (bv + 0.4) / (2.0 + 0.4);
|
||||
return texture(colorTexture, t);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
void main() {
|
||||
// Something in the color calculations need to be changed because before it was dependent
|
||||
// on the gl blend functions since the abuffer was not involved
|
||||
|
||||
vec4 color = vec4(0.0);
|
||||
switch (colorOption) {
|
||||
case COLOROPTION_COLOR:
|
||||
color = vec4(bv2rgb(ge_brightness[0]), 1.0);
|
||||
color = bv2rgb(ge_brightness[0].x);
|
||||
break;
|
||||
case COLOROPTION_VELOCITY:
|
||||
color = vec4(abs(ge_velocity), 0.5);
|
||||
@@ -127,8 +76,8 @@ void main(void)
|
||||
|
||||
// color.rgb = 1/ color.rgb;
|
||||
// color.a = 1-color.a;
|
||||
framebuffer_output_color = texture(texture1, texCoord)*color;
|
||||
//framebuffer_output_color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
framebuffer_output_color = texture(psfTexture, texCoord) * color;
|
||||
// framebuffer_output_color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// framebuffer_output_color = vec4(ge_velocity, 1.0);
|
||||
|
||||
|
||||
@@ -43,8 +43,12 @@
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#ifdef GHOUL_USE_DEVIL
|
||||
#include <ghoul/io/texture/texturereaderdevil.h>
|
||||
#else
|
||||
#include <ghoul/io/texture/texturereaderfreeimage.h>
|
||||
#endif // GHOUL_USE_DEVIL
|
||||
#include <ghoul/io/texture/texturereadercmap.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
@@ -136,7 +140,9 @@ bool RenderEngine::initialize()
|
||||
ghoul::io::TextureReader::addReader(new ghoul::io::impl::TextureReaderDevIL);
|
||||
#else
|
||||
ghoul::io::TextureReader::addReader(new ghoul::io::impl::TextureReaderFreeImage);
|
||||
#endif
|
||||
#endif // GHOUL_USE_DEVIL
|
||||
|
||||
ghoul::io::TextureReader::addReader(new ghoul::io::impl::TextureReaderCMAP);
|
||||
|
||||
#if ABUFFER_IMPLEMENTATION == ABUFFER_FRAMEBUFFER
|
||||
_abuffer = new ABufferFramebuffer();
|
||||
|
||||
@@ -75,9 +75,12 @@ namespace openspace {
|
||||
|
||||
RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _texture(nullptr)
|
||||
, _textureIsDirty(true)
|
||||
, _pointSpreadFunctionTexturePath("psfTexture", "Point Spread Function Texture")
|
||||
, _pointSpreadFunctionTexture(nullptr)
|
||||
, _pointSpreadFunctionTextureIsDirty(true)
|
||||
, _colorTexturePath("colorTexture", "ColorBV Texture")
|
||||
, _colorTexture(nullptr)
|
||||
, _colorTextureIsDirty(true)
|
||||
, _colorOption("colorOption", "Color Option")
|
||||
, _dataIsDirty(true)
|
||||
, _spriteSize("spriteSize", "Sprite Size", 0.0000005f, 0.f, 1.f)
|
||||
@@ -89,10 +92,11 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
, _vbo(0)
|
||||
{
|
||||
std::string texturePath = "";
|
||||
if (dictionary.hasKey(constants::renderablestars::keyTexture)) {
|
||||
dictionary.getValue(constants::renderablestars::keyTexture, texturePath);
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
}
|
||||
dictionary.getValue(constants::renderablestars::keyTexture, texturePath);
|
||||
_pointSpreadFunctionTexturePath = absPath(texturePath);
|
||||
|
||||
dictionary.getValue(constants::renderablestars::keyColorMap, texturePath);
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
bool success = dictionary.getValue(constants::renderablestars::keyFile, _speckFile);
|
||||
if (!success) {
|
||||
@@ -110,8 +114,11 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
|
||||
addProperty(_spriteSize);
|
||||
|
||||
addProperty(_pointSpreadFunctionTexturePath);
|
||||
_pointSpreadFunctionTexturePath.onChange([&]{ _pointSpreadFunctionTextureIsDirty = true;});
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange([&]{ _textureIsDirty = true;});
|
||||
_colorTexturePath.onChange([&]{ _colorTextureIsDirty = true; });
|
||||
}
|
||||
|
||||
bool RenderableStars::isReady() const {
|
||||
@@ -125,11 +132,14 @@ bool RenderableStars::initialize() {
|
||||
"${SHADERS}/star_vs.glsl",
|
||||
"${SHADERS}/star_fs.glsl",
|
||||
"${SHADERS}/star_ge.glsl");
|
||||
//_program = ghoul::opengl::ProgramObject::Build("Star",
|
||||
// "${SHADERS}/star_vs.glsl",
|
||||
// "${SHADERS}/star_fs.glsl");
|
||||
if (!_program)
|
||||
return false;
|
||||
_program->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; });
|
||||
completeSuccess &= loadData();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
completeSuccess &= (_pointSpreadFunctionTexture != nullptr);
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
@@ -140,8 +150,8 @@ bool RenderableStars::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
delete _pointSpreadFunctionTexture;
|
||||
_pointSpreadFunctionTexture = nullptr;
|
||||
|
||||
delete _program;
|
||||
_program = nullptr;
|
||||
@@ -160,6 +170,8 @@ void RenderableStars::render(const RenderData& data) {
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
_program->setIgnoreUniformLocationError(true);
|
||||
//_program->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
//_program->setUniform("ModelTransform", glm::mat4(1.f));
|
||||
_program->setUniform("model", modelMatrix);
|
||||
_program->setUniform("view", viewMatrix);
|
||||
_program->setUniform("projection", projectionMatrix);
|
||||
@@ -171,14 +183,24 @@ void RenderableStars::render(const RenderData& data) {
|
||||
|
||||
_program->setUniform("spriteSize", _spriteSize);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_program->setUniform("texture1", unit);
|
||||
ghoul::opengl::TextureUnit psfUnit;
|
||||
psfUnit.activate();
|
||||
if (_pointSpreadFunctionTexture)
|
||||
_pointSpreadFunctionTexture->bind();
|
||||
_program->setUniform("psfTexture", psfUnit);
|
||||
|
||||
ghoul::opengl::TextureUnit colorUnit;
|
||||
colorUnit.activate();
|
||||
if (_colorTexture)
|
||||
_colorTexture->bind();
|
||||
_program->setUniform("colorTexture", colorUnit);
|
||||
|
||||
glBindVertexArray(_vao);
|
||||
const GLsizei nStars = static_cast<GLsizei>(_fullData.size() / _nValuesPerStar);
|
||||
//glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glDrawArrays(GL_POINTS, 0, nStars);
|
||||
//glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
||||
glBindVertexArray(0);
|
||||
_program->setIgnoreUniformLocationError(false);
|
||||
_program->deactivate();
|
||||
@@ -268,18 +290,32 @@ void RenderableStars::update(const UpdateData& data) {
|
||||
_dataIsDirty = false;
|
||||
}
|
||||
|
||||
if (_textureIsDirty) {
|
||||
LDEBUG("Reloading texture");
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
if (_pointSpreadFunctionTextureIsDirty) {
|
||||
LDEBUG("Reloading Point Spread Function texture");
|
||||
delete _pointSpreadFunctionTexture;
|
||||
_pointSpreadFunctionTexture = nullptr;
|
||||
if (_pointSpreadFunctionTexturePath.value() != "") {
|
||||
_pointSpreadFunctionTexture = ghoul::io::TextureReader::loadTexture(absPath(_pointSpreadFunctionTexturePath));
|
||||
if (_pointSpreadFunctionTexture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_pointSpreadFunctionTexturePath) << "'");
|
||||
_pointSpreadFunctionTexture->uploadTexture();
|
||||
}
|
||||
}
|
||||
_textureIsDirty = false;
|
||||
_pointSpreadFunctionTextureIsDirty = false;
|
||||
}
|
||||
|
||||
if (_colorTextureIsDirty) {
|
||||
LDEBUG("Reloading Color Texture");
|
||||
delete _colorTexture;
|
||||
_colorTexture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_colorTexture = ghoul::io::TextureReader::loadTexture(absPath(_colorTexturePath));
|
||||
if (_colorTexture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_colorTexture->uploadTexture();
|
||||
}
|
||||
}
|
||||
_colorTextureIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user