Merge pull request #955 from OpenSpace/integration/FXAA_Vol_Milkway

Integration/fxaa vol milkway
This commit is contained in:
Alexander Bock
2019-08-23 16:37:12 +02:00
committed by GitHub
34 changed files with 895 additions and 567 deletions

View File

@@ -15,6 +15,7 @@ asset.require('scene/solarsystem/planets')
asset.require('scene/solarsystem/planets/mars/moons/phobos')
asset.require('scene/solarsystem/planets/mars/moons/deimos')
asset.require('scene/solarsystem/dwarf_planets/pluto/system')
asset.request('scene/milkyway/milkyway/volume')
assetHelper.requestAll(asset, 'scene/digitaluniverse')
@@ -26,7 +27,7 @@ asset.require('util/default_joystick')
-- Load web gui
asset.require('util/webgui')
asset.request('customization/globebrowsing')
asset.request('customization/volumes')
-- Keybindings that are specific for this scene
local Keybindings = {

View File

@@ -6,7 +6,7 @@ local speck = asset.syncedResource({
Name = "Constellation Speck Files",
Type = "HttpSynchronization",
Identifier = "digitaluniverse_constellations_speck",
Version = 1
Version = 2
})
local constellationsExtragalactic = {

View File

@@ -13,7 +13,7 @@ local speck = asset.syncedResource({
Name = "OB Associations Speck Files",
Type = "HttpSynchronization",
Identifier = "digitaluniverse_obassociations_speck",
Version = 1
Version = 2
})
local object = {

View File

@@ -13,7 +13,7 @@ local speck = asset.syncedResource({
Name = "Stars Speck Files",
Type = "HttpSynchronization",
Identifier = "stars_du",
Version = 1
Version = 3
})
local colorLUT = asset.syncedResource({

View File

@@ -0,0 +1,42 @@
-- 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},
Rotation = {3.1415926, 3.1248, 4.45741},
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

@@ -121,10 +121,8 @@ private:
std::unique_ptr<ghoul::opengl::ProgramObject> _hdrFilteringProgram;
std::unique_ptr<ghoul::opengl::ProgramObject> _tmoProgram;
std::unique_ptr<ghoul::opengl::ProgramObject> _resolveProgram;
std::unique_ptr<ghoul::opengl::ProgramObject> _fxaaProgram;
UniformCache(mainColorTexture, blackoutFactor) _uniformCache;
UniformCache(hdrFeedingTexture, blackoutFactor, hdrExposure, gamma,
Hue, Saturation, Value) _hdrUniformCache;
UniformCache(renderedTexture, inverseScreenSize) _fxaaUniformCache;

View File

@@ -568,8 +568,18 @@ void main() {
// Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords)
// when using their positions later, one must convert them to the planet's coords
// =======================
// Get data from G-Buffer
vec4 normal = texture(mainNormalTexture, texCoord);
// =======================
// Normal is stored in SGCT View Space and transformed to the current object space
vec4 normalViewSpaceAndWaterReflectance = texture(mainNormalTexture, texCoord);
dvec4 normalViewSpace = vec4(normalViewSpaceAndWaterReflectance.xyz, 0.0);
dvec4 normalWorldSpace = dSGCTViewToWorldMatrix * normalViewSpace;
vec4 normal = vec4(dInverseModelTransformMatrix * normalWorldSpace);
normal.xyz = normalize(normal.xyz);
normal.w = normalViewSpaceAndWaterReflectance.w;
// Data in the mainPositionTexture are written in view space (view plus camera rig)
vec4 position = texture(mainPositionTexture, texCoord);

View File

@@ -84,10 +84,11 @@ Fragment getFragment() {
frag.color.rgb = diffuseAlbedo;
}
frag.color.a = opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionCameraSpace;
frag.gNormal = vec4(vs_normalViewSpace, 1.0);
frag.color.a = opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionCameraSpace;
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
frag.disableLDR2HDR = true;
return frag;

View File

@@ -710,14 +710,16 @@ bool RenderableDUMeshes::readSpeckFile() {
continue;
}
if (line.substr(0, 4) != "mesh") {
std::size_t found = line.find("mesh");
if (found == std::string::npos) {
//if (line.substr(0, 4) != "mesh") {
// we read a line that doesn't belong to the header, so we have to jump back
// before the beginning of the current line
file.seekg(position);
break;
}
} else {
if (line.substr(0, 4) == "mesh") {
//if (line.substr(0, 4) == "mesh") {
// mesh lines are structured as follows:
// mesh -t texnum -c colorindex -s style {
// where textnum is the index of the texture;

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

@@ -1,3 +1,5 @@
set(DEFAULT_MODULE ON)
set (OPENSPACE_DEPENDENCIES
volume
space

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,50 @@
#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*, 4> UniformNamesPoints = {
"modelMatrix", "cameraViewProjectionMatrix", "eyePosition",
"opacityCoefficient"
};
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 +105,15 @@ 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 +123,78 @@ 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.");
@@ -104,13 +205,15 @@ namespace openspace {
std::string volumeFilename;
if (volumeDictionary.getValue("Filename", volumeFilename)) {
_volumeFilename = absPath(volumeFilename);
} else {
}
else {
LERROR("No volume filename specified.");
}
glm::vec3 volumeDimensions;
if (volumeDictionary.getValue("Dimensions", volumeDimensions)) {
_volumeDimensions = static_cast<glm::ivec3>(volumeDimensions);
} else {
}
else {
LERROR("No volume dimensions specified.");
}
glm::vec3 volumeSize;
@@ -129,10 +232,27 @@ namespace openspace {
std::string pointsFilename;
if (pointsDictionary.getValue("Filename", pointsFilename)) {
_pointsFilename = absPath(pointsFilename);
} else {
}
else {
LERROR("No points filename specified.");
}
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.");
}
pointsDictionary.getValue("Scaling", _pointScaling);
}
void RenderableGalaxy::initializeGL() {
@@ -140,7 +260,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 +269,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 +298,142 @@ 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 +460,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 +473,223 @@ 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 && _opacityCoefficient > 0.f) {
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 rotMatrix = glm::rotate(
glm::dmat4(1.0),
glm::pi<double>(),
glm::dvec3(1.0, 0.0, 0.0)) *
glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) *
glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)
);
glm::dmat4 modelMatrix =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) * rotMatrix *
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);
_pointsProgram->setUniform(
_uniformCachePoints.opacityCoefficient,
_opacityCoefficient
);
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 rotMatrix = glm::rotate(
glm::dmat4(1.0),
glm::pi<double>(),
glm::dvec3(1.0, 0.0, 0.0)) *
glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) *
glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)
);
glm::dmat4 modelMatrix =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) * rotMatrix *
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 +700,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,48 @@ 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,
opacityCoefficient
) _uniformCachePoints;
UniformCache(
modelMatrix, cameraViewProjectionMatrix,
cameraUp, eyePosition, psfTexture
) _uniformCacheBillboards;
std::vector<float> _pointsData;
size_t _nPoints;
GLuint _pointsVao;
GLuint _positionVbo;

View File

@@ -23,21 +23,28 @@
****************************************************************************************/
#include "fragment.glsl"
#include "PowerScaling/powerScaling_fs.hglsl"
#include "floatoperations.glsl"
in vec3 vsPosition;
in vec3 vsColor;
uniform float emittanceFactor;
uniform sampler2D psfTexture;
in vec4 vs_position;
in vec2 psfCoords;
in vec3 ge_color;
in float ge_screenSpaceDepth;
Fragment getFragment() {
Fragment frag;
float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth));
frag.color = vec4(vsColor.rgb * coefficient, 1.0);
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 = pscDepth(vec4(vsPosition, 0.0));
frag.depth = ge_screenSpaceDepth;
frag.gPosition = vs_position;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
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

@@ -24,11 +24,13 @@
#version __CONTEXT__
layout(location = 0) in vec4 position;
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;
flat out vec3 vPosition;
out vec3 vs_color;
void main() {
gl_Position = position;
vPosition = position.xyz;
vs_color = in_color;
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

@@ -22,32 +22,27 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "fragment.glsl"
#include "floatoperations.glsl"
#include "PowerScaling/powerScaling_vs.hglsl"
in vec4 vs_position;
in vec3 vs_color;
in float vs_screenSpaceDepth;
in float vs_starBrightness;
in vec3 inPosition;
in vec3 inColor;
uniform float opacityCoefficient;
out vec3 vsPosition;
out vec3 vsColor;
Fragment getFragment() {
Fragment frag;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
float multipliedOpacityCoefficient = clamp(opacityCoefficient*opacityCoefficient*20.0, 0.0, 1.0);
vec3 extinction = exp(vec3(0.6, 0.2, 0.3)-vs_color);
vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness*multipliedOpacityCoefficient, 1.0);
frag.color = fullColor;
frag.depth = vs_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

@@ -24,23 +24,37 @@
#version __CONTEXT__
#include "hdr.glsl"
#include "PowerScaling/powerScaling_vs.hglsl"
layout (location = 0) out vec4 finalColor;
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;
uniform int nAaSamples;
uniform float backgroundConstant;
uniform float backgroundExposure;
uniform sampler2DMS mainColorTexture;
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() {
vec4 color = vec4(0.0);
for (int i = 0; i < nAaSamples; i++) {
color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
}
vs_position = vec4(in_position, 1.0);
dvec4 dpos = dvec4(vs_position);
color /= nAaSamples;
// color.rgb *= blackoutFactor;
finalColor = vec4(HDR(color.rgb * backgroundConstant, backgroundExposure), 1.0);
double distanceToStar = length((dpos.xyz - eyePosition));
vs_starBrightness = clamp(float(8000*PARSEC/distanceToStar), 0.0, 1.0);
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

@@ -22,22 +22,25 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "PowerScaling/powerScaling_fs.hglsl"
#include "floatoperations.glsl"
#include "fragment.glsl"
in vec3 vPosition;
in vec4 worldPosition;
uniform uint blendMode;
in vec3 modelPosition;
in vec4 viewPosition;
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;
//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

@@ -33,7 +33,6 @@
layout(location = 1) in vec2 in_uv;
out vec4 fs_position;
out vec3 fs_normal;
out vec2 fs_uv;
out vec3 ellipsoidNormalCameraSpace;
out vec3 levelWeights;
@@ -126,7 +125,6 @@ void main() {
fs_position = z_normalization(positionClippingSpace);
gl_Position = fs_position;
ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal;
fs_normal = pair.normal;
positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1.0));
#if USE_ECLIPSE_SHADOWS

View File

@@ -34,7 +34,6 @@ layout(location = 1) in vec2 in_uv;
out vec2 fs_uv;
out vec4 fs_position;
out vec3 fs_normal;
out vec3 ellipsoidNormalCameraSpace;
out vec3 levelWeights;
out vec3 positionCameraSpace;
@@ -56,7 +55,6 @@ uniform vec3 p10;
uniform vec3 p01;
uniform vec3 p11;
uniform vec3 patchNormalCameraSpace;
uniform vec3 patchNormalModelSpace;
uniform float chunkMinHeight;
uniform float distanceScaleFactor;
@@ -110,7 +108,6 @@ void main() {
fs_position = z_normalization(positionClippingSpace);
gl_Position = fs_position;
ellipsoidNormalCameraSpace = patchNormalCameraSpace;
fs_normal = patchNormalModelSpace;
positionCameraSpace = p;
#if USE_ECLIPSE_SHADOWS

View File

@@ -129,7 +129,6 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows],
#endif
in vec4 fs_position;
in vec3 fs_normal;
in vec2 fs_uv;
in vec3 ellipsoidNormalCameraSpace;
in vec3 levelWeights;
@@ -138,10 +137,6 @@ in vec3 positionCameraSpace;
#if USE_ACCURATE_NORMALS
in vec3 ellipsoidTangentThetaCameraSpace;
in vec3 ellipsoidTangentPhiCameraSpace;
// Once deferred light calculations are done in view space this can be removed
// so that we only need one normal; in view space.
uniform mat4 invViewModelTransform;
#endif // USE_ACCURATE_NORMALS
#if USE_ECLIPSE_SHADOWS
@@ -152,11 +147,10 @@ in vec3 positionWorldSpace;
Fragment getFragment() {
Fragment frag;
frag.color = vec4(0.3, 0.3, 0.3, 1.0);
vec3 normal = normalize(ellipsoidNormalCameraSpace);
vec3 normalModelSpace = normalize(fs_normal);
#if USE_ACCURATE_NORMALS
normal = getTileNormal(
fs_uv,
@@ -165,9 +159,6 @@ Fragment getFragment() {
normalize(ellipsoidTangentThetaCameraSpace),
normalize(ellipsoidTangentPhiCameraSpace)
);
// Once deferred light calculations are done in view space this can be removed
// so that we only need one normal; in view space.
normalModelSpace = normalize(mat3(invViewModelTransform) * normal);
#endif /// USE_ACCURATE_NORMALS
#if USE_COLORTEXTURE
@@ -243,11 +234,8 @@ Fragment getFragment() {
#else
frag.gNormal.w = 0;
#endif
// Normal is written Object Space.
// Right now the only renderable using this info is the atm and,
// because all calculation for light interactions are done in Object
// Space, we avoid a new computation saving the normals in Object Space.
frag.gNormal.xyz = normalModelSpace;
// Normal is written View Space (Including SGCT View Matrix).
frag.gNormal.xyz = normal;
if (dot(positionCameraSpace, vec3(1.0)) != 0.0) {
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space

View File

@@ -761,8 +761,7 @@ void RenderableGlobe::update(const UpdateData& data) {
ghoul::opengl::updateUniformLocations(
*_localRenderer.program,
_localRenderer.uniformCache,
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace",
"patchNormalCameraSpace" }
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" }
);
}
@@ -1024,27 +1023,6 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&) {
);
}
if (_generalProperties.useAccurateNormals &&
!_layerManager.layerGroup(layergroupid::HeightLayers).activeLayers().empty())
{
// This should not be needed once the light calculations for the atmosphere
// is performed in view space..
_localRenderer.program->setUniform(
"invViewModelTransform",
glm::inverse(
glm::mat4(data.camera.combinedViewMatrix()) *
glm::mat4(_cachedModelTransform)
)
);
_globalRenderer.program->setUniform(
"invViewModelTransform",
glm::inverse(
glm::mat4(data.camera.combinedViewMatrix()) *
glm::mat4(_cachedModelTransform)
)
);
}
constexpr const int ChunkBufferSize = 2048;
std::array<const Chunk*, ChunkBufferSize> global;
int globalCount = 0;
@@ -1274,6 +1252,7 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
// TODO: Patch normal can be calculated for all corners and then linearly
// interpolated on the GPU to avoid cracks for high altitudes.
// JCC: Camera space includes the SGCT View transformation.
const glm::vec3 patchNormalCameraSpace = normalize(
cross(
cornersCameraSpace[Quad::SOUTH_EAST] - cornersCameraSpace[Quad::SOUTH_WEST],
@@ -1281,19 +1260,6 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
)
);
// In order to improve performance, lets use the normal in object space (model space)
// for deferred rendering.
const glm::vec3 patchNormalModelSpace = normalize(
cross(
cornersModelSpace[Quad::SOUTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST],
cornersModelSpace[Quad::NORTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST]
)
);
program.setUniform(
_localRenderer.uniformCache.patchNormalModelSpace,
patchNormalModelSpace
);
program.setUniform(
_localRenderer.uniformCache.patchNormalCameraSpace,
patchNormalCameraSpace
@@ -1598,8 +1564,7 @@ void RenderableGlobe::recompileShaders() {
ghoul::opengl::updateUniformLocations(
*_localRenderer.program,
_localRenderer.uniformCache,
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace",
"patchNormalCameraSpace" }
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" }
);

View File

@@ -104,6 +104,7 @@ Fragment getFragment() {
frag.depth = gs_screenSpaceDepth;
frag.gPosition = vs_position;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
frag.disableLDR2HDR = true;
return frag;
}

View File

@@ -29,7 +29,7 @@
#define ITERATIONS 12
#define SUBPIXEL_QUALITY 0.75f
const float[12] QUALITY = {1.f, 1.f, 1.f, 1.f, 1.f, 1.5f, 2.f, 2.f, 2.f, 2.f, 4.f, 8.f};
const float[12] QUALITY = float[](1.f, 1.f, 1.f, 1.f, 1.f, 1.5f, 2.f, 2.f, 2.f, 2.f, 4.f, 8.f);
// const float[24] QUALITY = {2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 12.f, 12.f, 12.f, 12.f, 14.f, 18.f,
// 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f,
// 18.f, 18.f};

View File

@@ -1,39 +0,0 @@
/*****************************************************************************************
* *
* 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__
in vec4 position;
out vec2 texCoord;
out vec3 vPosition;
out vec4 worldPosition;
void main() {
gl_Position = position;
texCoord = 0.5 + position.xy * 0.5;
vPosition = position.xyz;
worldPosition = position;
}

View File

@@ -1,33 +0,0 @@
/*****************************************************************************************
* *
* 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__
layout (location = 0) out vec4 finalColor;
flat in vec3 vPosition;
void main() {
finalColor = vec4(0.5 * vPosition + 0.5, 1.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;
@@ -73,9 +79,6 @@ void main() {
vec3 direction = normalize(diff);
float raycastDepth = length(diff);
int i, j;
float tmp;
float geoDepth = denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), 0).x);
float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.0, 1.0);
raycastDepth = geoRatio * raycastDepth;
@@ -96,11 +99,14 @@ void main() {
vec3 accumulatedAlpha = vec3(0.0);
for (steps = 0; (accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT ||
accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS; ++steps) {
if (currentDepth + nextStepSize * jitterFactor > raycastDepth) {
aaOpacity -= opacityDecay;
}
for (steps = 0;
(accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT ||
accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS;
++steps)
{
// if (currentDepth + nextStepSize * jitterFactor > raycastDepth) {
// aaOpacity -= opacityDecay;
// }
bool shortStepSize = nextStepSize < raycastDepth / 10000000000.0;
if (shortStepSize) {

View File

@@ -1,43 +0,0 @@
/*****************************************************************************************
* *
* 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__
layout (location = 0) out vec4 finalColor;
uniform float blackoutFactor;
uniform int nAaSamples;
uniform sampler2DMS mainColorTexture;
void main() {
vec4 color = vec4(0.0);
for (int i = 0; i < nAaSamples; i++) {
color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
}
color /= nAaSamples;
color.rgb *= blackoutFactor;
finalColor = vec4(color.rgb, 1.0);
}

View File

@@ -50,10 +50,6 @@
namespace {
constexpr const char* _loggerCat = "FramebufferRenderer";
constexpr const std::array<const char*, 2> UniformNames = {
"mainColorTexture", "blackoutFactor"
};
constexpr const std::array<const char*, 7> HDRUniformNames = {
"hdrFeedingTexture", "blackoutFactor", "hdrExposure", "gamma",
"Hue", "Saturation", "Value"
@@ -320,17 +316,6 @@ void FramebufferRenderer::initialize() {
// Sets back to default FBO
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
_resolveProgram = ghoul::opengl::ProgramObject::Build(
"Framebuffer Resolve",
absPath("${SHADERS}/framebuffer/resolveframebuffer.vert"),
absPath("${SHADERS}/framebuffer/resolveframebuffer.frag")
);
ghoul::opengl::updateUniformLocations(
*_resolveProgram,
_uniformCache,
UniformNames
);
ghoul::opengl::updateUniformLocations(
*_hdrFilteringProgram,
_hdrUniformCache,
@@ -475,15 +460,6 @@ void FramebufferRenderer::update() {
updateDeferredcastData();
}
if (_resolveProgram->isDirty()) {
_resolveProgram->rebuildFromFile();
ghoul::opengl::updateUniformLocations(
*_resolveProgram,
_uniformCache,
UniformNames
);
}
if (_hdrFilteringProgram->isDirty()) {
_hdrFilteringProgram->rebuildFromFile();