Merge branch 'feature/milkyway-galaxy' into integration/FXAA_Vol_Milkway

This commit is contained in:
Jonathas Costa
2019-08-19 15:41:54 -04:00
16 changed files with 864 additions and 329 deletions

View File

@@ -27,6 +27,7 @@ asset.require('util/default_joystick')
asset.require('util/webgui')
asset.request('customization/globebrowsing')
asset.request('customization/volumes')
-- Keybindings that are specific for this scene
local Keybindings = {

View File

@@ -0,0 +1,41 @@
-- asset.require('../examples/volume/generated/cartesian.asset')
local assetHelper = asset.require("util/asset_helper")
local transforms = asset.require("scene/solarsystem/sun/transforms")
local data = asset.syncedResource({
Name = "Milkyway Volume Data",
Type = "HttpSynchronization",
Identifier = "milkyway_volume_data",
Version = 1
})
local MilkyWayVolumeGalaxy = {
Identifier = "Milky Way Volume",
Parent = transforms.SolarSystemBarycenter.Identifier,
Renderable = {
Type = "RenderableGalaxy",
StepSize = 0.01,
AbsorptionMultiply = 75,
EmissionMultiply = 200,
Translation = {0.2, 0, 0},
Volume = {
Type = "Volume",
Filename = data .. "/MilkyWayRGBAVolume1024x1024x128.raw",
Dimensions = {1024, 1024, 128},
Size = {1.2E21, 1.2E21, 0.15E21}
},
Points = {
Type = "Points",
Filename = data .. "/MilkyWayPoints.off",
EnabledPointsRatio = 0.3,
Texture = data .. "/halo.png"
}
},
GUI = {
Path = "/Milky Way"
}
}
local objects = { MilkyWayVolumeGalaxy }
assetHelper.registerSceneGraphNodesAndExport(asset, objects)

View File

@@ -42,9 +42,21 @@ set(SOURCE_FILES
)
source_group("Source Files" FILES ${SOURCE_FILES})
set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/galaxyraycast.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_ge.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/raycasterbounds_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/raycasterbounds_vs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})
create_new_module(
"Galaxy"
galaxy
STATIC
${HEADER_FILES} ${SOURCE_FILES}
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
)

View File

@@ -35,9 +35,9 @@ namespace {
constexpr const char* GlslRaycastPath =
"${MODULES}/galaxy/shaders/galaxyraycast.glsl";
constexpr const char* GlslBoundsVsPath =
"${MODULES}/galaxy/shaders/raycasterbounds.vs";
"${MODULES}/galaxy/shaders/raycasterbounds_vs.glsl";
constexpr const char* GlslBoundsFsPath =
"${MODULES}/galaxy/shaders/raycasterbounds.fs";
"${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl";
} // namespace
namespace openspace {
@@ -55,14 +55,8 @@ void GalaxyRaycaster::initialize() {
void GalaxyRaycaster::renderEntryPoints(const RenderData& data,
ghoul::opengl::ProgramObject& program)
{
program.setUniform("modelTransform", _modelTransform);
program.setUniform("modelViewTransform", glm::mat4(modelViewTransform(data)));
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
program.setUniform("blendMode", static_cast<unsigned int>(1));
program.setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f));
program.setUniform("objpos", glm::vec4(data.modelTransform.translation, 0.f));
program.setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix()));
program.setUniform("scaling", glm::vec2(1.f, 0.f));
// Cull back face
glEnable(GL_CULL_FACE);
@@ -76,14 +70,8 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data,
ghoul::opengl::ProgramObject& program)
{
// Uniforms
program.setUniform("modelTransform", _modelTransform);
program.setUniform("modelViewTransform", glm::mat4(modelViewTransform(data)));
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
program.setUniform("blendMode", static_cast<unsigned int>(1));
program.setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f));
program.setUniform("objpos", glm::vec4(data.modelTransform.translation, 0.f));
program.setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix()));
program.setUniform("scaling", glm::vec2(1.f, 0.f));
// Cull front face
glEnable(GL_CULL_FACE);
@@ -96,6 +84,16 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data,
glCullFace(GL_BACK);
}
glm::dmat4 GalaxyRaycaster::modelViewTransform(const RenderData& data) {
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) *
glm::dmat4(_modelTransform);
return data.camera.combinedViewMatrix() * modelTransform;
}
void GalaxyRaycaster::preRaycast(const RaycastData& data,
ghoul::opengl::ProgramObject& program)
{
@@ -107,9 +105,17 @@ void GalaxyRaycaster::preRaycast(const RaycastData& data,
const std::string opacityCoefficientUniformName = "opacityCoefficient" +
std::to_string(data.id);
const std::string absorptionMultiplyUniformName = "absorptionMultiply" +
std::to_string(data.id);
const std::string emissionMultiplyUniformName = "emissionMultiply" +
std::to_string(data.id);
program.setUniform(volumeAspectUniformName, _aspect);
program.setUniform(stepSizeUniformName, _stepSize);
program.setUniform(opacityCoefficientUniformName, _opacityCoefficient);
program.setUniform(absorptionMultiplyUniformName, _absorptionMultiply);
program.setUniform(emissionMultiplyUniformName, _emissionMultiply);
_textureUnit = std::make_unique<ghoul::opengl::TextureUnit>();
_textureUnit->activate();
@@ -122,35 +128,14 @@ void GalaxyRaycaster::postRaycast(const RaycastData&, ghoul::opengl::ProgramObje
}
bool GalaxyRaycaster::isCameraInside(const RenderData& data, glm::vec3& localPosition) {
// Camera rig position in world coordinates.
const glm::vec4 rigWorldPos = glm::vec4(data.camera.positionVec3(), 1.0);
//rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y);
//glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix());
// Camera position in world coordinates.
const glm::vec4 camWorldPos = rigWorldPos;
const glm::vec3 objPos = static_cast<glm::vec3>(data.modelTransform.translation);
const glm::mat4 modelTransform = glm::translate(_modelTransform, objPos);
float divisor = 1.f;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (abs(modelTransform[i][j] > divisor)) {
divisor = modelTransform[i][j];
}
}
}
const glm::mat4 scaledModelTransform = modelTransform / divisor;
const glm::vec4 modelPos = (glm::inverse(scaledModelTransform) / divisor) *
camWorldPos;
glm::vec4 modelPos = glm::inverse(modelViewTransform(data)) *
glm::vec4(0.f, 0.f, 0.f, 1.f);
localPosition = (glm::vec3(modelPos) + glm::vec3(0.5));
return (localPosition.x > 0 && localPosition.y > 0 &&
localPosition.z > 0 && localPosition.x < 1 &&
localPosition.y < 1 && localPosition.z < 1);
return (localPosition.x > 0 && localPosition.x < 1 &&
localPosition.y > 0 && localPosition.y < 1 &&
localPosition.z > 0 && localPosition.z < 1);
}
std::string GalaxyRaycaster::boundsVertexShaderPath() const {
@@ -181,6 +166,14 @@ void GalaxyRaycaster::setOpacityCoefficient(float opacityCoefficient) {
_opacityCoefficient = opacityCoefficient;
}
void GalaxyRaycaster::setAbsorptionMultiplier(float absorptionMultiply) {
_absorptionMultiply = absorptionMultiply;
}
void GalaxyRaycaster::setEmissionMultiplier(float emissionMultiply) {
_emissionMultiply = emissionMultiply;
}
void GalaxyRaycaster::setTime(double time) {
_time = time;
}

View File

@@ -71,14 +71,20 @@ public:
void setTime(double time);
void setStepSize(float stepSize);
void setOpacityCoefficient(float opacityCoefficient);
void setAbsorptionMultiplier(float absorptionMultiply);
void setEmissionMultiplier(float emissionMultiply);
private:
glm::dmat4 modelViewTransform(const RenderData& data);
BoxGeometry _boundingBox;
float _stepSize;
glm::mat4 _modelTransform;
glm::vec3 _aspect;
double _time;
float _opacityCoefficient;
float _absorptionMultiply;
float _emissionMultiply;
ghoul::opengl::Texture& _texture;
std::unique_ptr<ghoul::opengl::TextureUnit> _textureUnit;

View File

@@ -32,6 +32,7 @@
#include <openspace/rendering/renderable.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/boxgeometry.h>
#include <openspace/util/distanceconstants.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/glm.h>
#include <ghoul/filesystem/filesystem.h>
@@ -45,20 +46,49 @@
#include <fstream>
namespace {
constexpr const char* GlslRayCastPath = "${MODULES}/toyvolume/shaders/rayCast.glsl";
constexpr const char* GlslBoundsVsPath = "${MODULES}/toyvolume/shaders/boundsVs.glsl";
constexpr const char* GlslBoundsFsPath = "${MODULES}/toyvolume/shaders/boundsFs.glsl";
constexpr const char* GlslRaycastPath =
"${MODULES}/galaxy/shaders/galaxyraycast.glsl";
constexpr const char* GlslBoundsVsPath =
"${MODULES}/galaxy/shaders/raycasterbounds_vs.glsl";
constexpr const char* GlslBoundsFsPath =
"${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl";
constexpr const char* _loggerCat = "Renderable Galaxy";
constexpr const std::array<const char*, 3> UniformNamesPoints = {
"modelMatrix", "cameraViewProjectionMatrix", "eyePosition"
};
constexpr const std::array<const char*, 5> UniformNamesBillboards = {
"modelMatrix", "cameraViewProjectionMatrix",
"cameraUp", "eyePosition", "psfTexture"
};
constexpr openspace::properties::Property::PropertyInfo VolumeRenderingEnabledInfo = {
"VolumeRenderingEnabled",
"Volume Rendering",
"" // @TODO Missing documentation
};
constexpr openspace::properties::Property::PropertyInfo StarRenderingEnabledInfo = {
"StarRenderingEnabled",
"Star Rendering",
"" // @TODO Missing documentation
};
constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = {
"StepSize",
"Step Size",
"" // @TODO Missing documentation
};
constexpr openspace::properties::Property::PropertyInfo PointStepSizeInfo = {
"PointStepSize",
"Point Step Size",
constexpr openspace::properties::Property::PropertyInfo AbsorptionMultiplyInfo = {
"AbsorptionMultiply",
"Absorption Multiplier",
"" // @TODO Missing documentation
};
constexpr openspace::properties::Property::PropertyInfo EmissionMultiplyInfo = {
"EmissionMultiply",
"Emission Multiplier",
"" // @TODO Missing documentation
};
@@ -74,8 +104,14 @@ namespace {
"" // @TODO Missing documentation
};
constexpr openspace::properties::Property::PropertyInfo StarRenderingMethodInfo = {
"StarRenderingMethod",
"Star Rendering Method",
"This value determines which rendering method is used for visualization of the stars."
};
constexpr openspace::properties::Property::PropertyInfo EnabledPointsRatioInfo = {
"NEnabledPointsRatio",
"EnabledPointsRatio",
"Enabled points",
"" // @TODO Missing documentation
};
@@ -85,15 +121,69 @@ namespace openspace {
RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _stepSize(StepSizeInfo, 0.012f, 0.0005f, 0.05f)
, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f)
, _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(10.f))
, _volumeRenderingEnabled(VolumeRenderingEnabledInfo, true)
, _starRenderingEnabled(StarRenderingEnabledInfo, true)
, _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f)
, _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f)
, _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f)
, _starRenderingMethod(StarRenderingMethodInfo, properties::OptionProperty::DisplayType::Dropdown)
, _enabledPointsRatio(EnabledPointsRatioInfo, 0.5f, 0.01f, 1.0f)
, _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f))
, _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f))
, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f)
{
dictionary.getValue("VolumeRenderingEnabled", _volumeRenderingEnabled);
dictionary.getValue("StarRenderingEnabled", _starRenderingEnabled);
dictionary.getValue("StepSize", _stepSize);
dictionary.getValue("AbsorptionMultiply", _absorptionMultiply);
dictionary.getValue("EmissionMultiply", _emissionMultiply);
dictionary.getValue("StarRenderingMethod", _starRenderingMethod);
dictionary.getValue("EnabledPointsRatio", _enabledPointsRatio);
dictionary.getValue("Translation", _translation);
dictionary.getValue("Rotation", _rotation);
dictionary.getValue("StepSize", _stepSize);
if (dictionary.hasKeyAndValue<bool>(VolumeRenderingEnabledInfo.identifier)) {
_volumeRenderingEnabled = dictionary.value<bool>(VolumeRenderingEnabledInfo.identifier);
}
if (dictionary.hasKeyAndValue<bool>(StarRenderingEnabledInfo.identifier)) {
_starRenderingEnabled = static_cast<bool>(StarRenderingEnabledInfo.identifier);
}
if (dictionary.hasKeyAndValue<double>(StepSizeInfo.identifier)) {
_stepSize = static_cast<float>(dictionary.value<double>(StepSizeInfo.identifier));
}
if (dictionary.hasKeyAndValue<double>(AbsorptionMultiplyInfo.identifier)) {
_absorptionMultiply = static_cast<float>(dictionary.value<double>(AbsorptionMultiplyInfo.identifier));
}
if (dictionary.hasKeyAndValue<double>(EmissionMultiplyInfo.identifier)) {
_emissionMultiply = static_cast<float>(dictionary.value<double>(EmissionMultiplyInfo.identifier));
}
_starRenderingMethod.addOptions({
{ 0, "Points" },
{ 1, "Billboards" }
});
if (dictionary.hasKey(StarRenderingMethodInfo.identifier)) {
const std::string starRenderingMethod = dictionary.value<std::string>(
StarRenderingMethodInfo.identifier
);
if (starRenderingMethod == "Points") {
_starRenderingMethod = 0;
}
else if (starRenderingMethod == "Billboards") {
_starRenderingMethod = 1;
}
}
if (dictionary.hasKeyAndValue<glm::vec3>(TranslationInfo.identifier)) {
_translation = dictionary.value<glm::vec3>(TranslationInfo.identifier);
}
if (dictionary.hasKeyAndValue<glm::vec3>(RotationInfo.identifier)) {
_rotation = dictionary.value<glm::vec3>(RotationInfo.identifier);
}
if (!dictionary.hasKeyAndValue<ghoul::Dictionary>("Volume")) {
LERROR("No volume dictionary specified.");
@@ -132,7 +222,19 @@ namespace openspace {
} else {
LERROR("No points filename specified.");
}
pointsDictionary.getValue("Scaling", _pointScaling);
if (pointsDictionary.hasKeyAndValue<double>(EnabledPointsRatioInfo.identifier)) {
_enabledPointsRatio = static_cast<float>(pointsDictionary.value<double>(EnabledPointsRatioInfo.identifier));
}
std::string pointSpreadFunctionTexturePath;
if (pointsDictionary.getValue("Texture", pointSpreadFunctionTexturePath)) {
_pointSpreadFunctionTexturePath = absPath(pointSpreadFunctionTexturePath);
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(_pointSpreadFunctionTexturePath);
}
else {
LERROR("No points filename specified.");
}
}
void RenderableGalaxy::initializeGL() {
@@ -140,7 +242,7 @@ void RenderableGalaxy::initializeGL() {
_aspect = static_cast<glm::vec3>(_volumeDimensions);
_aspect /= std::max(std::max(_aspect.x, _aspect.y), _aspect.z);
volume::RawVolumeReader<glm::tvec4<GLfloat>> reader(
volume::RawVolumeReader<glm::tvec4<GLubyte>> reader(
_volumeFilename,
_volumeDimensions
);
@@ -149,10 +251,10 @@ void RenderableGalaxy::initializeGL() {
_texture = std::make_unique<ghoul::opengl::Texture>(
_volumeDimensions,
ghoul::opengl::Texture::Format::RGBA,
GL_RGBA32F,
GL_FLOAT,
GL_RGBA,
GL_UNSIGNED_BYTE,
ghoul::opengl::Texture::FilterMode::Linear,
ghoul::opengl::Texture::WrappingMode::Clamp);
ghoul::opengl::Texture::WrappingMode::ClampToEdge);
_texture->setPixelData(reinterpret_cast<char*>(
_volume->data()),
@@ -178,91 +280,131 @@ void RenderableGalaxy::initializeGL() {
onEnabledChange(onChange);
addProperty(_volumeRenderingEnabled);
addProperty(_starRenderingEnabled);
addProperty(_stepSize);
addProperty(_pointStepSize);
addProperty(_absorptionMultiply);
addProperty(_emissionMultiply);
addProperty(_starRenderingMethod);
addProperty(_enabledPointsRatio);
addProperty(_translation);
addProperty(_rotation);
addProperty(_enabledPointsRatio);
// initialize points.
std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary);
if (!_pointsFilename.empty()) {
_pointsProgram = global::renderEngine.buildRenderProgram(
"Galaxy points",
absPath("${MODULE_GALAXY}/shaders/points_vs.glsl"),
absPath("${MODULE_GALAXY}/shaders/points_fs.glsl")
);
_billboardsProgram = global::renderEngine.buildRenderProgram(
"Galaxy billboard",
absPath("${MODULE_GALAXY}/shaders/billboard_vs.glsl"),
absPath("${MODULE_GALAXY}/shaders/billboard_fs.glsl"),
absPath("${MODULE_GALAXY}/shaders/billboard_ge.glsl")
);
std::vector<glm::vec3> pointPositions;
std::vector<glm::vec3> pointColors;
if (!_pointSpreadFunctionTexturePath.empty()) {
_pointSpreadFunctionTexture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_pointSpreadFunctionTexturePath)
);
int64_t nPoints;
pointFile.seekg(0, std::ios::beg); // read heder.
pointFile.read(reinterpret_cast<char*>(&nPoints), sizeof(int64_t));
if (_pointSpreadFunctionTexture) {
LDEBUG(fmt::format(
"Loaded texture from '{}'",
absPath(_pointSpreadFunctionTexturePath)
));
_pointSpreadFunctionTexture->uploadTexture();
}
_pointSpreadFunctionTexture->setFilter(
ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
);
_nPoints = static_cast<size_t>(nPoints);
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(
_pointSpreadFunctionTexturePath
);
}
size_t nFloats = _nPoints * 7;
ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCachePoints, UniformNamesPoints);
ghoul::opengl::updateUniformLocations(*_billboardsProgram, _uniformCacheBillboards, UniformNamesBillboards);
std::vector<float> pointData(nFloats);
pointFile.seekg(sizeof(int64_t), std::ios::beg); // read past heder.
pointFile.read(reinterpret_cast<char*>(pointData.data()), nFloats * sizeof(float));
pointFile.close();
_pointsProgram->setIgnoreUniformLocationError(
ghoul::opengl::ProgramObject::IgnoreError::Yes
);
float maxdist = 0;
GLint positionAttrib = _pointsProgram->attributeLocation("in_position");
GLint colorAttrib = _pointsProgram->attributeLocation("in_color");
for (size_t i = 0; i < _nPoints; ++i) {
float x = pointData[i * 7 + 0];
float y = pointData[i * 7 + 1];
float z = pointData[i * 7 + 2];
float r = pointData[i * 7 + 3];
float g = pointData[i * 7 + 4];
float b = pointData[i * 7 + 5];
maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z)));
//float a = pointData[i * 7 + 6]; alpha is not used.
std::ifstream pointFile(_pointsFilename, std::ios::in);
pointPositions.emplace_back(x, y, z);
pointColors.emplace_back(r, g, b);
std::vector<glm::vec3> pointPositions;
std::vector<glm::vec3> pointColors;
int64_t nPoints;
// Read header for OFF (Object File Format)
std::string line;
std::getline(pointFile, line);
// Read point count
std::getline(pointFile, line);
std::istringstream iss(line);
iss >> nPoints;
// Prepare point reading
_nPoints = static_cast<size_t>(nPoints);
float maxdist = 0;
// Read points
float x, y, z, r, g, b, a;
for (size_t i = 0; i < static_cast<size_t>(_nPoints * _enabledPointsRatio.maxValue()) + 1; ++i) {
std::getline(pointFile, line);
std::istringstream issp(line);
issp >> x >> y >> z >> r >> g >> b >> a;
//Convert klioparsec to meters
glm::vec3 position = glm::vec3(x, y, z);
position *= (openspace::distanceconstants::Parsec * 100);
maxdist = std::max(maxdist, glm::length(position));
pointPositions.emplace_back(position);
pointColors.emplace_back(r, g, b);
}
pointFile.close();
std::cout << maxdist << std::endl;
glGenVertexArrays(1, &_pointsVao);
glGenBuffers(1, &_positionVbo);
glGenBuffers(1, &_colorVbo);
glBindVertexArray(_pointsVao);
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
glBufferData(GL_ARRAY_BUFFER,
pointPositions.size() * sizeof(glm::vec3),
pointPositions.data(),
GL_STATIC_DRAW
);
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
glBufferData(GL_ARRAY_BUFFER,
pointColors.size() * sizeof(glm::vec3),
pointColors.data(),
GL_STATIC_DRAW
);
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
glEnableVertexAttribArray(colorAttrib);
glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
std::cout << maxdist << std::endl;
glGenVertexArrays(1, &_pointsVao);
glGenBuffers(1, &_positionVbo);
glGenBuffers(1, &_colorVbo);
glBindVertexArray(_pointsVao);
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
glBufferData(GL_ARRAY_BUFFER,
pointPositions.size() * sizeof(glm::vec3),
pointPositions.data(),
GL_STATIC_DRAW
);
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
glBufferData(GL_ARRAY_BUFFER,
pointColors.size() * sizeof(glm::vec3),
pointColors.data(),
GL_STATIC_DRAW
);
_pointsProgram = global::renderEngine.buildRenderProgram(
"Galaxy points",
absPath("${MODULE_GALAXY}/shaders/points.vs"),
absPath("${MODULE_GALAXY}/shaders/points.fs")
);
_pointsProgram->setIgnoreUniformLocationError(
ghoul::opengl::ProgramObject::IgnoreError::Yes
);
GLint positionAttrib = _pointsProgram->attributeLocation("inPosition");
GLint colorAttrib = _pointsProgram->attributeLocation("inColor");
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
glEnableVertexAttribArray(colorAttrib);
glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void RenderableGalaxy::deinitializeGL() {
@@ -289,9 +431,10 @@ void RenderableGalaxy::update(const UpdateData& data) {
transform = glm::rotate(transform, eulerRotation.z, glm::vec3(0, 0, 1));
glm::mat4 volumeTransform = glm::scale(transform, _volumeSize);
_pointTransform = glm::scale(transform, _pointScaling);
_pointTransform = transform;
//_pointTransform = glm::scale(transform, _pointScaling);
const glm::vec4 translation = glm::vec4(_translation.value(), 0.0);
const glm::vec4 translation = glm::vec4(_translation.value()*_volumeSize, 0.0);
// Todo: handle floating point overflow, to actually support translation.
@@ -301,49 +444,201 @@ void RenderableGalaxy::update(const UpdateData& data) {
_raycaster->setStepSize(_stepSize);
_raycaster->setAspect(_aspect);
_raycaster->setModelTransform(volumeTransform);
// @EMIL: is this correct? ---abock
_raycaster->setAbsorptionMultiplier(_absorptionMultiply);
_raycaster->setEmissionMultiplier(_emissionMultiply);
_raycaster->setTime(data.time.j2000Seconds());
}
}
void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
RaycasterTask task { _raycaster.get(), data };
// Render the volume
if (_raycaster && _volumeRenderingEnabled) {
RaycasterTask task { _raycaster.get(), data };
const glm::vec3 position = data.camera.positionVec3();
const float length = safeLength(position);
const glm::vec3 galaxySize = _volumeSize;
const glm::vec3 position = data.camera.positionVec3();
const float length = safeLength(position);
const glm::vec3 galaxySize = _volumeSize;
const float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z);
const float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z);
const float lowerRampStart = maxDim * 0.02f;
const float lowerRampEnd = maxDim * 0.5f;
const float lowerRampStart = maxDim * 0.02f;
const float lowerRampEnd = maxDim * 0.5f;
const float upperRampStart = maxDim * 2.f;
const float upperRampEnd = maxDim * 10.f;
const float upperRampStart = maxDim * 2.f;
const float upperRampEnd = maxDim * 10.f;
float opacityCoefficient = 1.f;
float opacityCoefficient = 1.f;
if (length < lowerRampStart) {
opacityCoefficient = 0.f; // camera really close
} else if (length < lowerRampEnd) {
opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart);
} else if (length < upperRampStart) {
opacityCoefficient = 1.f; // sweet spot (max)
} else if (length < upperRampEnd) {
opacityCoefficient = 1.f - (length - upperRampStart) /
(upperRampEnd - upperRampStart); //fade out
} else {
opacityCoefficient = 0;
if (length < lowerRampStart) {
opacityCoefficient = 0.f; // camera really close
} else if (length < lowerRampEnd) {
opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart);
} else if (length < upperRampStart) {
opacityCoefficient = 1.f; // sweet spot (max)
} else if (length < upperRampEnd) {
opacityCoefficient = 1.f - (length - upperRampStart) /
(upperRampEnd - upperRampStart); //fade out
} else {
opacityCoefficient = 0;
}
_opacityCoefficient = opacityCoefficient;
ghoul_assert(
_opacityCoefficient >= 0.f && _opacityCoefficient <= 1.f,
"Opacity coefficient was not between 0 and 1"
);
if (opacityCoefficient > 0) {
_raycaster->setOpacityCoefficient(_opacityCoefficient);
tasks.raycasterTasks.push_back(task);
}
}
_opacityCoefficient = opacityCoefficient;
ghoul_assert(
_opacityCoefficient >= 0.f && _opacityCoefficient <= 1.f,
"Opacity coefficient was not between 0 and 1"
);
if (opacityCoefficient > 0) {
_raycaster->setOpacityCoefficient(_opacityCoefficient);
tasks.raycasterTasks.push_back(task);
// Render the stars
if (_starRenderingEnabled) {
if (_starRenderingMethod == 1) {
renderBillboards(data);
}
else {
renderPoints(data);
}
}
}
void RenderableGalaxy::renderPoints(const RenderData& data) {
if (_pointsProgram) {
// Saving current OpenGL state
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
GLboolean depthMask;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDepthMask(false);
glDisable(GL_DEPTH_TEST);
_pointsProgram->activate();
glm::dmat4 modelMatrix =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)));
glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix());
glm::dmat4 cameraViewProjectionMatrix = projectionMatrix *
data.camera.combinedViewMatrix();
_pointsProgram->setUniform(_uniformCachePoints.modelMatrix, modelMatrix);
_pointsProgram->setUniform(
_uniformCachePoints.cameraViewProjectionMatrix,
cameraViewProjectionMatrix
);
glm::dvec3 eyePosition = glm::dvec3(
glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0)
);
_pointsProgram->setUniform(_uniformCachePoints.eyePosition, eyePosition);
glBindVertexArray(_pointsVao);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(_nPoints * _enabledPointsRatio));
glBindVertexArray(0);
_pointsProgram->deactivate();
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Restores OpenGL blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
glDepthMask(depthMask);
}
}
void RenderableGalaxy::renderBillboards(const RenderData& data) {
if (_billboardsProgram) {
// Saving current OpenGL state
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
GLboolean depthMask;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDepthMask(false);
glDisable(GL_DEPTH_TEST);
_billboardsProgram->activate();
glm::dmat4 modelMatrix =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)));
glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix());
glm::dmat4 cameraViewProjectionMatrix = projectionMatrix *
data.camera.combinedViewMatrix();
_billboardsProgram->setUniform(_uniformCacheBillboards.modelMatrix, modelMatrix);
_billboardsProgram->setUniform(
_uniformCacheBillboards.cameraViewProjectionMatrix,
cameraViewProjectionMatrix
);
glm::dvec3 eyePosition = glm::dvec3(
glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0)
);
_billboardsProgram->setUniform(_uniformCacheBillboards.eyePosition, eyePosition);
glm::dvec3 cameraUp = data.camera.lookUpVectorWorldSpace();
_billboardsProgram->setUniform(_uniformCacheBillboards.cameraUp, cameraUp);
ghoul::opengl::TextureUnit psfUnit;
psfUnit.activate();
_pointSpreadFunctionTexture->bind();
_billboardsProgram->setUniform(_uniformCacheBillboards.psfTexture, psfUnit);
glBindVertexArray(_pointsVao);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(_nPoints * _enabledPointsRatio));
glBindVertexArray(0);
_billboardsProgram->deactivate();
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Restores OpenGL blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
glDepthMask(depthMask);
}
}
@@ -354,37 +649,4 @@ float RenderableGalaxy::safeLength(const glm::vec3& vector) const {
return glm::length(vector / maxComponent) * maxComponent;
}
/*void RenderableGalaxy::postRender(const RenderData& data) {
_raycaster->setStepSize(_pointStepSize);
_pointsProgram->activate();
setPscUniforms(*_pointsProgram.get(), data.camera, data.position);
OsEng.ref().renderEngine().preRaycast(*_pointsProgram);
glm::mat4 modelMatrix = _pointTransform;
glm::mat4 viewMatrix = data.camera.viewMatrix();
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
_pointsProgram->setUniform("model", modelMatrix);
_pointsProgram->setUniform("view", viewMatrix);
_pointsProgram->setUniform("projection", projectionMatrix);
float emittanceFactor = _opacityCoefficient * static_cast<glm::vec3>(_volumeSize).x;
_pointsProgram->setUniform("emittanceFactor", emittanceFactor);
glBindVertexArray(_pointsVao);
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDrawArrays(GL_POINTS, 0, _nPoints * _enabledPointsRatio);
glBindVertexArray(0);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
OsEng.ref().renderEngine().postRaycast(*_pointsProgram);
}*/
} // namespace openspace

View File

@@ -29,7 +29,13 @@
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/properties/optionproperty.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/uniformcache.h>
namespace ghoul::opengl {
class ProgramObject;
} // namespace ghoul::opengl
namespace openspace {
@@ -40,7 +46,7 @@ struct RenderData;
class RenderableGalaxy : public Renderable {
public:
RenderableGalaxy(const ghoul::Dictionary& dictionary);
explicit RenderableGalaxy(const ghoul::Dictionary& dictionary);
virtual ~RenderableGalaxy() = default;
void initializeGL() override;
@@ -50,28 +56,47 @@ public:
void update(const UpdateData& data) override;
private:
void renderPoints(const RenderData& data);
void renderBillboards(const RenderData& data);
float safeLength(const glm::vec3& vector) const;
glm::vec3 _volumeSize;
glm::vec3 _pointScaling;
properties::BoolProperty _volumeRenderingEnabled;
properties::BoolProperty _starRenderingEnabled;
properties::FloatProperty _stepSize;
properties::FloatProperty _pointStepSize;
properties::FloatProperty _absorptionMultiply;
properties::FloatProperty _emissionMultiply;
properties::OptionProperty _starRenderingMethod;
properties::FloatProperty _enabledPointsRatio;
properties::Vec3Property _translation;
properties::Vec3Property _rotation;
properties::FloatProperty _enabledPointsRatio;
std::unique_ptr<ghoul::opengl::Texture> _pointSpreadFunctionTexture;
std::unique_ptr<ghoul::filesystem::File> _pointSpreadFunctionFile;
std::string _volumeFilename;
glm::ivec3 _volumeDimensions;
std::string _pointsFilename;
std::string _pointSpreadFunctionTexturePath;
std::unique_ptr<GalaxyRaycaster> _raycaster;
std::unique_ptr<volume::RawVolume<glm::tvec4<GLfloat>>> _volume;
std::unique_ptr<volume::RawVolume<glm::tvec4<GLubyte>>> _volume;
std::unique_ptr<ghoul::opengl::Texture> _texture;
glm::mat4 _pointTransform;
glm::vec3 _aspect;
float _opacityCoefficient;
std::unique_ptr<ghoul::opengl::ProgramObject> _pointsProgram;
std::unique_ptr<ghoul::opengl::ProgramObject> _billboardsProgram;
UniformCache(
modelMatrix, cameraViewProjectionMatrix, eyePosition
) _uniformCachePoints;
UniformCache(
modelMatrix, cameraViewProjectionMatrix,
cameraUp, eyePosition, psfTexture
) _uniformCacheBillboards;
std::vector<float> _pointsData;
size_t _nPoints;
GLuint _pointsVao;
GLuint _positionVbo;

View File

@@ -22,32 +22,29 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "fragment.glsl"
#include "floatoperations.glsl"
#include "PowerScaling/powerScaling_vs.hglsl"
uniform sampler2D psfTexture;
in vec3 inPosition;
in vec3 inColor;
in vec4 vs_position;
in vec2 psfCoords;
in vec3 ge_color;
in float ge_screenSpaceDepth;
out vec3 vsPosition;
out vec3 vsColor;
Fragment getFragment() {
Fragment frag;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
vec4 textureColor = texture(psfTexture, 0.5*psfCoords + 0.5);
vec4 fullColor = vec4(ge_color*textureColor.a, textureColor.a);
if (fullColor.a == 0) {
discard;
}
frag.color = fullColor;
frag.depth = ge_screenSpaceDepth;
frag.gPosition = vs_position;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
void main() {
vec4 p = vec4(inPosition, 1.0);
vec4 worldPosition = model * vec4(inPosition, 1.0);
worldPosition.w = 0.0;
vec4 position = worldPosition; //pscTransform(worldPosition, model);
position = pscTransform(position, mat4(1.0));
vsPosition = position.xyz;
position = projection * view * position;
gl_Position = z_normalization(position);
vsColor = inColor;
return frag;
}

View File

@@ -0,0 +1,101 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "floatoperations.glsl"
#include "PowerScaling/powerScalingMath.hglsl"
uniform dvec3 eyePosition;
uniform dvec3 cameraUp;
uniform dmat4 cameraViewProjectionMatrix;
uniform dmat4 modelMatrix;
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
in vec4 vs_gPosition[];
in vec3 vs_color[];
out vec4 vs_position;
out vec2 psfCoords;
flat out vec3 ge_color;
flat out float ge_screenSpaceDepth;
const double PARSEC = 3.08567756E16;
void main() {
vs_position = gl_in[0].gl_Position; // in object space
ge_color = vs_color[0];
double scaleMultiply = 8.0;
dvec4 dpos = dvec4(vs_position);
dpos.xyz *= scaleMultiply;
dpos = modelMatrix * dpos;
dpos /= PARSEC;
//It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way
dpos.x += 8000;
scaleMultiply *= 4.0;
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
vec4 bottomLeftVertex, bottomRightVertex, topLeftVertex, topRightVertex;
dvec3 normal = normalize(eyePosition - dpos.xyz);
dvec3 newRight = normalize(cross(cameraUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight;
scaledUp = scaleMultiply * newUp;
bottomLeftVertex = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
//dvec4 dposCamera = cameraViewProjectionMatrix * dpos;
//ge_screenSpaceDepth = float(length(eyePosition - dposCamera.xyz)/PARSEC);
ge_screenSpaceDepth = bottomLeftVertex.w;
topRightVertex = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
bottomRightVertex = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
topLeftVertex = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Build primitive
gl_Position = topLeftVertex;
psfCoords = vec2(-1.0, 1.0);
EmitVertex();
gl_Position = bottomLeftVertex;
psfCoords = vec2(-1.0, -1.0);
EmitVertex();
gl_Position = topRightVertex;
psfCoords = vec2(1.0, 1.0);
EmitVertex();
gl_Position = bottomRightVertex;
psfCoords = vec2(1.0, -1.0);
EmitVertex();
EndPrimitive();
}

View File

@@ -22,22 +22,15 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
#version __CONTEXT__
in vec3 vPosition;
in vec4 worldPosition;
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;
uniform uint blendMode;
out vec3 vs_color;
void main() {
vs_color = in_color;
Fragment getFragment() {
vec4 position = worldPosition;
float depth = pscDepth(position);
Fragment frag;
frag.color = vec4((vPosition + 0.5), 1.0);
frag.depth = depth;
frag.blend = blendMode;
return frag;
gl_Position = vec4(in_position, 1.0);
}

View File

@@ -1,93 +1,80 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
uniform float maxStepSize#{id} = 0.1;
uniform vec3 aspect#{id} = vec3(1.0);
uniform float opacityCoefficient#{id} = 1.0;
uniform float opacityCoefficient#{id} = 1.0;
uniform float absorptionMultiply#{id} = 50.0;
uniform float emissionMultiply#{id} = 1500.0;
uniform sampler3D galaxyTexture#{id};
void sample#{id}(vec3 samplePos,
vec3 dir,
inout vec3 accumulatedColor,
inout vec3 accumulatedAlpha,
inout float maxStepSize)
{
vec3 dir,
inout vec3 accumulatedColor,
inout vec3 accumulatedAlpha,
inout float maxStepSize)
{
vec3 aspect = aspect#{id};
maxStepSize = maxStepSize#{id} / length(dir / aspect);
vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz);
float STEP_SIZE = maxStepSize#{id};
//Early ray termination on black parts of the data
vec3 normalizedPos = (samplePos*2.0)-1.0;
if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){
return;
}
float STEP_SIZE = maxStepSize#{id}*0.5;
//float STEP_SIZE = 1 / 256.0;
vec3 alphaTint = vec3(0.3, 0.54, 0.85);
vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz);
// Source textures currently are square-rooted to avoid dithering in the shadows.
// So square them back
sampledColor = sampledColor*sampledColor;
// fudge for the dust "spreading"
sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id};
sampledColor.a = pow(sampledColor.a, 0.7);
//sampledColor.rgba = min(vec4(1.0), sampledColor.rgba);
//sampledColor.a = clamp(sampledColor.a * 10000000000.0, 0.0, 1.0);
//sampledColor.a = exp(-sampledColor.a);
//
// absorption probability
float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id};
vec3 absorption = alphaTint * scaled_density;
//sampledColor.rgb = pow(sampledColor.rgb, vec3(10.0));
//sampledColor.a = pow(sampledColor.a, 10.0);
//sampledColor.a = pow(sampledColor.a, 100000000.0);
sampledColor.rgb *= 500.0;
sampledColor.a = sampledColor.a * 0.3; //1.0;
// extinction
vec3 extinction = exp(-absorption);
accumulatedColor.rgb *= extinction;
//float emissionCoefficient = 80;
//float absorptionCoefficient = 1;
// sampledColor = clamp(sampledColor, 0.0, 1.0);
// emission
accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id};
//backColor = vec3(1.0) - pow(vec3(1.0) - backColor, vec3(STEP_SIZE));
/*if (sampledColor.a > 1.0) {
sampledColor.a = 1.0;
//accumulatedColor = vec3(1.0, 0.0, 0.0);
//accumulatedAlpha = vec3(1.0, 1.0, 1.0);
//return;
}*/
//sampledColor.a = 1.2;
//sampledColor.a *= 0.00001;
vec3 backColor = sampledColor.rgb;
vec3 backAlpha = sampledColor.a * alphaTint;
backColor *= STEP_SIZE * opacityCoefficient#{id};
backAlpha *= STEP_SIZE * opacityCoefficient#{id};
backColor = clamp(backColor, 0.0, 1.0);
backAlpha = clamp(backAlpha, 0.0, 1.0);
vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha;
accumulatedColor += oneMinusFrontAlpha * backColor;
accumulatedAlpha += oneMinusFrontAlpha * backAlpha;
}
//accumulatedColor += oneMinusFrontAlpha * sampledColor.rgb;
accumulatedAlpha += oneMinusFrontAlpha * sampledColor.rgb;
}
float stepSize#{id}(vec3 samplePos, vec3 dir) {
float stepSize#{id}(vec3 samplePos, vec3 dir) {
return maxStepSize#{id} * length(dir * 1.0 / aspect#{id});
}
}

View File

@@ -23,21 +23,23 @@
****************************************************************************************/
#include "fragment.glsl"
#include "PowerScaling/powerScaling_fs.hglsl"
in vec3 vsPosition;
in vec3 vsColor;
uniform float emittanceFactor;
#include "floatoperations.glsl"
in vec4 vs_position;
in vec3 vs_color;
in float vs_screenSpaceDepth;
in float vs_starBrightness;
Fragment getFragment() {
Fragment frag;
float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth));
frag.color = vec4(vsColor.rgb * coefficient, 1.0);
vec3 extinction = exp(vec3(0.6, 0.2, 0.3)-vs_color);
vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness, 1.0);
frag.color = fullColor;
frag.depth = pscDepth(vec4(vsPosition, 0.0));
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_position;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;
}

View File

@@ -0,0 +1,66 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;
out vec4 vs_position;
out vec3 vs_color;
out float vs_screenSpaceDepth;
out float vs_starBrightness;
uniform dmat4 cameraViewProjectionMatrix;
uniform dmat4 modelMatrix;
uniform dvec3 eyePosition;
const double PARSEC = 3.08567756E16;
void main() {
vs_position = vec4(in_position, 1.0);
dvec4 dpos = dvec4(vs_position);
double distanceToStar = length((dpos.xyz - eyePosition));
vs_starBrightness = clamp(float(8000*PARSEC/distanceToStar), 0.0, 1.0);
// Discard stars if we are not seing the milky way volume
if(length(vec3(0.0)-eyePosition)<780*PARSEC){
vs_starBrightness = 0.0;
}
else{
dpos.xyz *= 8.0;
dpos = modelMatrix * dpos;
dpos /= PARSEC;
//It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way
dpos.x += 8000;
}
vec4 positionScreenSpace = z_normalization(vec4(cameraViewProjectionMatrix * dpos));
vs_color = in_color;
vs_screenSpaceDepth = positionScreenSpace.w;
gl_Position = positionScreenSpace;
}

View File

@@ -0,0 +1,46 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "floatoperations.glsl"
#include "fragment.glsl"
in vec3 modelPosition;
in vec4 viewPosition;
Fragment getFragment() {
Fragment frag;
//Early ray termination on black parts of the data
/*vec3 normalizedPos = (modelPosition*2.0)-1.0;
if(abs(modelPosition.x) > 0.9 || abs(modelPosition.y) > 0.9){
frag.color = vec4(0.0, 0.0, 0.0, 1.0);
}
else{*/
vec3 pos = modelPosition + 0.5;
//vec3 posClamp = clamp(pos, vec3(0.0), vec3(1.0));
frag.color = vec4(pos, 1.0);
//}
frag.depth = safeLength(viewPosition);
return frag;
}

View File

@@ -24,23 +24,20 @@
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
layout(location = 0) in vec4 vertPosition;
out vec3 vPosition;
out vec4 worldPosition;
out vec3 modelPosition;
out vec4 viewPosition;
uniform mat4 viewProjection;
uniform mat4 modelTransform;
uniform mat4 modelViewTransform;
void main() {
vPosition = vertPosition.xyz;
modelPosition = vertPosition.xyz;
viewPosition = modelViewTransform*vertPosition;
worldPosition = modelTransform * vec4(vertPosition.xyz, 1.0);
worldPosition.w = 0.0;
vec4 position = pscTransform(worldPosition, mat4(1.0));
gl_Position = z_normalization(viewProjection * position);
// project the position to view space
gl_Position = viewProjection * viewPosition;
gl_Position.z = 0.0;
}

View File

@@ -53,7 +53,9 @@ void main() {
vec2 texCoord = vec2(gl_FragCoord.xy / windowSize);
vec4 exitColorTexture = texture(exitColorTexture, texCoord);
if (exitColorTexture.a < 1.0) {
// if we don't have an exit, discard the ray
if (exitColorTexture.a < 1.0 || exitColorTexture.rgb == vec3(0.0)) {
discard;
}
@@ -66,6 +68,10 @@ void main() {
vec3 entryPos;
float entryDepth;
getEntry(entryPos, entryDepth);
// if we don't have an entry, discard the ray
if (entryPos == vec3(0.0)) {
discard;
}
vec3 position = entryPos;
vec3 diff = exitPos - entryPos;