mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 15:29:26 -05:00
PointCloud data rendered and location for volume and pc seems to be correct (need some cleanup). PSFtexture for billboards next thing.
This commit is contained in:
@@ -11,16 +11,17 @@ local MilkyWayVolumeGalaxy = {
|
||||
StepSize = 0.01,
|
||||
AbsorptionMultiply = 10,
|
||||
EmissionMultiply = 100,
|
||||
Translation = {0.17, 0, 0},
|
||||
Translation = {0.2, 0, 0},
|
||||
Volume = {
|
||||
Type = "Volume",
|
||||
Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw",
|
||||
Dimensions = {1024, 1024, 128},
|
||||
Size = {9.2E21, 9.2E21, 1.15E21}
|
||||
Size = {1.2E21, 1.2E21, 0.15E21}
|
||||
},
|
||||
Points = {
|
||||
Type = "Points",
|
||||
Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off"
|
||||
Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off",
|
||||
Scaling = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
GUI = {
|
||||
|
||||
@@ -42,9 +42,18 @@ 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/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}
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,17 +46,19 @@
|
||||
#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";
|
||||
"${MODULES}/galaxy/shaders/raycasterbounds_vs.glsl";
|
||||
constexpr const char* GlslBoundsFsPath =
|
||||
"${MODULES}/galaxy/shaders/raycasterbounds.fs";
|
||||
"${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl";
|
||||
constexpr const char* _loggerCat = "Renderable Galaxy";
|
||||
|
||||
constexpr const std::array<const char*, 5> UniformNames = {
|
||||
"modelMatrix", "cameraUp", "eyePosition", "cameraViewProjectionMatrix",
|
||||
"emittanceFactor"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = {
|
||||
"StepSize",
|
||||
"Step Size",
|
||||
@@ -80,6 +83,12 @@ namespace {
|
||||
"" // @TODO Missing documentation
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo PointScaleFactorInfo = {
|
||||
"PointScaleFactor",
|
||||
"Point Scale Factor",
|
||||
"" // @TODO Missing documentation
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo TranslationInfo = {
|
||||
"Translation",
|
||||
"Translation",
|
||||
@@ -106,14 +115,18 @@ namespace openspace {
|
||||
, _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)
|
||||
//, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f)
|
||||
//, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f)
|
||||
, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f)
|
||||
, _pointScaleFactor(PointScaleFactorInfo, 1.f, 1.f, 64.f)
|
||||
, _enabledPointsRatio(EnabledPointsRatioInfo, 0.02f, 0.001f, 0.1f)
|
||||
, _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))
|
||||
{
|
||||
dictionary.getValue("StepSize", _stepSize);
|
||||
dictionary.getValue("AbsorptionMultiply", _absorptionMultiply);
|
||||
dictionary.getValue("EmissionMultiply", _emissionMultiply);
|
||||
dictionary.getValue("PointStepSize", _pointStepSize);
|
||||
dictionary.getValue("PointScaleFactor", _pointScaleFactor);
|
||||
dictionary.getValue("EnabledPointsRatio", _enabledPointsRatio);
|
||||
dictionary.getValue("Translation", _translation);
|
||||
dictionary.getValue("Rotation", _rotation);
|
||||
|
||||
@@ -129,6 +142,18 @@ namespace openspace {
|
||||
_emissionMultiply = static_cast<float>(dictionary.value<double>(EmissionMultiplyInfo.identifier));
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<double>(PointStepSizeInfo.identifier)) {
|
||||
_pointStepSize = static_cast<float>(dictionary.value<double>(PointStepSizeInfo.identifier));
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<double>(PointScaleFactorInfo.identifier)) {
|
||||
_pointScaleFactor = static_cast<float>(dictionary.value<double>(PointScaleFactorInfo.identifier));
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<double>(EnabledPointsRatioInfo.identifier)) {
|
||||
_enabledPointsRatio = static_cast<float>(dictionary.value<double>(EnabledPointsRatioInfo.identifier));
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<glm::vec3>(TranslationInfo.identifier)) {
|
||||
_translation = dictionary.value<glm::vec3>(TranslationInfo.identifier);
|
||||
}
|
||||
@@ -174,7 +199,6 @@ namespace openspace {
|
||||
} else {
|
||||
LERROR("No points filename specified.");
|
||||
}
|
||||
//pointsDictionary.getValue("Scaling", _pointScaling);
|
||||
}
|
||||
|
||||
void RenderableGalaxy::initializeGL() {
|
||||
@@ -223,13 +247,30 @@ void RenderableGalaxy::initializeGL() {
|
||||
addProperty(_stepSize);
|
||||
addProperty(_absorptionMultiply);
|
||||
addProperty(_emissionMultiply);
|
||||
//addProperty(_pointStepSize);
|
||||
//addProperty(_enabledPointsRatio);
|
||||
addProperty(_pointStepSize);
|
||||
addProperty(_pointScaleFactor);
|
||||
addProperty(_enabledPointsRatio);
|
||||
addProperty(_translation);
|
||||
addProperty(_rotation);
|
||||
|
||||
// initialize points.
|
||||
if (!_pointsFilename.empty()) {
|
||||
_pointsProgram = global::renderEngine.buildRenderProgram(
|
||||
"Galaxy points",
|
||||
absPath("${MODULE_GALAXY}/shaders/points_vs.glsl"),
|
||||
absPath("${MODULE_GALAXY}/shaders/points_fs.glsl"),
|
||||
absPath("${MODULE_GALAXY}/shaders/points_ge.glsl")
|
||||
);
|
||||
|
||||
ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCache, UniformNames);
|
||||
|
||||
_pointsProgram->setIgnoreUniformLocationError(
|
||||
ghoul::opengl::ProgramObject::IgnoreError::Yes
|
||||
);
|
||||
|
||||
GLint positionAttrib = _pointsProgram->attributeLocation("in_position");
|
||||
GLint colorAttrib = _pointsProgram->attributeLocation("in_color");
|
||||
|
||||
std::ifstream pointFile(_pointsFilename, std::ios::in);
|
||||
|
||||
std::vector<glm::vec3> pointPositions;
|
||||
@@ -251,12 +292,18 @@ void RenderableGalaxy::initializeGL() {
|
||||
|
||||
// Read points
|
||||
float x, y, z, r, g, b, a;
|
||||
for (size_t i = 0; i < _nPoints; ++i) {
|
||||
for (size_t i = 0; i < static_cast<size_t>(_nPoints * 0.1) + 1; ++i) {
|
||||
std::getline(pointFile, line);
|
||||
std::istringstream iss(line);
|
||||
iss >> x >> y >> z >> r >> g >> b >> a;
|
||||
maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z)));
|
||||
pointPositions.emplace_back(x, y, z);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -283,19 +330,6 @@ void RenderableGalaxy::initializeGL() {
|
||||
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);
|
||||
@@ -333,7 +367,8 @@ 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()*_volumeSize, 0.0);
|
||||
|
||||
@@ -352,43 +387,136 @@ void RenderableGalaxy::update(const UpdateData& data) {
|
||||
}
|
||||
|
||||
void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
|
||||
RaycasterTask task { _raycaster.get(), data };
|
||||
if (_raycaster) {
|
||||
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);
|
||||
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);
|
||||
|
||||
_pointsProgram->activate();
|
||||
|
||||
glm::dvec3 eyePosition = glm::dvec3(
|
||||
glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0)
|
||||
);
|
||||
_pointsProgram->setUniform(_uniformCache.eyePosition, eyePosition);
|
||||
|
||||
glm::dvec3 cameraUp = data.camera.lookUpVectorWorldSpace();
|
||||
_pointsProgram->setUniform(_uniformCache.cameraUp, cameraUp);
|
||||
|
||||
const glm::dvec3 dtranslation = glm::dvec3((double)_translation.value().x, (double)_translation.value().y, (double)_translation.value().z);
|
||||
|
||||
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();
|
||||
|
||||
|
||||
/*glm::mat4 modelMatrix = _pointTransform;
|
||||
glm::mat4 viewMatrix = data.camera.combinedViewMatrix();
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
_pointsProgram->setUniform("model", modelMatrix);
|
||||
_pointsProgram->setUniform("view", viewMatrix);
|
||||
_pointsProgram->setUniform("projection", projectionMatrix);*/
|
||||
|
||||
/*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(_pointTransform);
|
||||
|
||||
glm::mat4 modelViewTransform = viewMatrix * modelMatrix;
|
||||
|
||||
_pointsProgram->setUniform("modelViewTransform", modelViewTransform);
|
||||
_pointsProgram->setUniform("viewProjection", data.camera.viewProjectionMatrix());*/
|
||||
|
||||
_pointsProgram->setUniform(_uniformCache.modelMatrix, modelMatrix);
|
||||
_pointsProgram->setUniform(
|
||||
_uniformCache.cameraViewProjectionMatrix,
|
||||
cameraViewProjectionMatrix
|
||||
);
|
||||
float emittanceFactor = _opacityCoefficient * static_cast<glm::vec3>(_volumeSize).x;
|
||||
_pointsProgram->setUniform(_uniformCache.emittanceFactor, emittanceFactor);
|
||||
|
||||
/*_pointsProgram->setUniform("scaleFactor", _pointScaleFactor);
|
||||
_pointsProgram->setUniform("emittanceFactor", emittanceFactor);*/
|
||||
|
||||
glBindVertexArray(_pointsVao);
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(_nPoints * _enabledPointsRatio));
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
_pointsProgram->deactivate();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/opengl/uniformcache.h>
|
||||
|
||||
namespace ghoul::opengl {
|
||||
class ProgramObject;
|
||||
} // namespace ghoul::opengl
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -40,7 +45,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;
|
||||
@@ -57,8 +62,9 @@ private:
|
||||
properties::FloatProperty _stepSize;
|
||||
properties::FloatProperty _absorptionMultiply;
|
||||
properties::FloatProperty _emissionMultiply;
|
||||
//properties::FloatProperty _pointStepSize;
|
||||
//properties::FloatProperty _enabledPointsRatio;
|
||||
properties::FloatProperty _pointStepSize;
|
||||
properties::FloatProperty _pointScaleFactor;
|
||||
properties::FloatProperty _enabledPointsRatio;
|
||||
properties::Vec3Property _translation;
|
||||
properties::Vec3Property _rotation;
|
||||
|
||||
@@ -74,6 +80,11 @@ private:
|
||||
float _opacityCoefficient;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _pointsProgram;
|
||||
UniformCache(
|
||||
modelMatrix, cameraUp, eyePosition, cameraViewProjectionMatrix,
|
||||
emittanceFactor
|
||||
) _uniformCache;
|
||||
std::vector<float> _pointsData;
|
||||
size_t _nPoints;
|
||||
GLuint _pointsVao;
|
||||
GLuint _positionVbo;
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
uniform float maxStepSize#{id} = 0.1;
|
||||
uniform vec3 aspect#{id} = vec3(1.0);
|
||||
uniform float opacityCoefficient#{id} = 1.0;
|
||||
uniform float absorptionMultiply#{id} = 50.0;
|
||||
uniform float opacityCoefficient#{id} = 1.0;
|
||||
uniform float absorptionMultiply#{id} = 50.0;
|
||||
uniform float emissionMultiply#{id} = 1500.0;
|
||||
uniform sampler3D galaxyTexture#{id};
|
||||
|
||||
@@ -35,33 +35,39 @@ void sample#{id}(vec3 samplePos,
|
||||
inout vec3 accumulatedAlpha,
|
||||
inout float maxStepSize)
|
||||
{
|
||||
//Speed up and border edge artifact fix
|
||||
vec3 normalizedPos = (samplePos*2.0)-1.0;
|
||||
if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){
|
||||
//accumulatedAlpha = vec3(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 aspect = aspect#{id};
|
||||
maxStepSize = maxStepSize#{id} / length(dir / aspect);
|
||||
|
||||
|
||||
vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz);
|
||||
|
||||
//float STEP_SIZE = maxStepSize#{id}*0.5;
|
||||
float STEP_SIZE = 1 / 256.0;
|
||||
float STEP_SIZE = 1 / 256.0;
|
||||
|
||||
vec3 alphaTint = vec3(0.3, 0.54, 0.85);
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
// absorption probability
|
||||
float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id};
|
||||
vec3 absorption = alphaTint * scaled_density;
|
||||
|
||||
|
||||
// extinction
|
||||
vec3 extinction = exp(-absorption);
|
||||
accumulatedColor.rgb *= extinction;
|
||||
|
||||
|
||||
// emission
|
||||
accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id};
|
||||
|
||||
|
||||
@@ -23,23 +23,34 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "floatoperations.glsl"
|
||||
|
||||
in vec3 vsPosition;
|
||||
in vec3 vsColor;
|
||||
in vec4 vs_position;
|
||||
in vec3 ge_color;
|
||||
in float ge_screenSpaceDepth;
|
||||
|
||||
uniform float emittanceFactor;
|
||||
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
float depth = pscDepth(vec4(vsPosition, 0.0));
|
||||
|
||||
float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth));
|
||||
frag.color = vec4(vsColor.rgb * coefficient, 1.0);
|
||||
//frag.depth = vs_screenSpaceDepth;
|
||||
|
||||
frag.depth = depth;
|
||||
//float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth));
|
||||
float coefficient = exp(1.38 * log(0.2) - 2*log(ge_screenSpaceDepth));
|
||||
frag.color = vec4(ge_color, 1.0)*emittanceFactor;
|
||||
//frag.gPosition = vec4(vs_position, 1.0);
|
||||
//frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
//frag.color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
//frag.depth = depth;
|
||||
//frag.blend = BLEND_MODE_ADDITIVE;
|
||||
|
||||
//float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth));
|
||||
//frag.color = vec4(ge_color.rgb * coefficient, 1.0);
|
||||
frag.depth = ge_screenSpaceDepth;
|
||||
frag.gPosition = vs_position;
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
@@ -24,30 +24,52 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
//#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_color;
|
||||
|
||||
out vec3 vsPosition;
|
||||
out vec3 vsColor;
|
||||
//out vec3 vs_position;
|
||||
out vec3 vs_color;
|
||||
//out float vs_screenSpaceDepth;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
//uniform mat4 model;
|
||||
//uniform mat4 view;
|
||||
//uniform mat4 projection;
|
||||
//uniform float scaleFactor;
|
||||
|
||||
//uniform mat4 viewProjection;
|
||||
//uniform mat4 modelViewTransform;
|
||||
|
||||
void main() {
|
||||
vec4 p = vec4(inPosition, 1.0);
|
||||
|
||||
vec4 worldPosition = model * vec4(inPosition, 1.0);
|
||||
/*vec4 worldPosition = model * vec4(in_position, 1.0);
|
||||
worldPosition.w = 0.0;
|
||||
vec4 position = worldPosition; //pscTransform(worldPosition, model);
|
||||
|
||||
|
||||
position = pscTransform(position, mat4(1.0));
|
||||
vsPosition = position.xyz;
|
||||
vs_position = position.xyz;
|
||||
position = projection * view * position;
|
||||
gl_Position = z_normalization(position);
|
||||
vsColor = inColor;
|
||||
gl_Position = position;*/
|
||||
|
||||
/*vec4 tmp = vec4(inPosition, 0.0);
|
||||
vsPosition = inPosition;
|
||||
vec4 position = pscTransform(tmp, model);
|
||||
position = projection * view * position;
|
||||
gl_Position = z_normalization(position);*/
|
||||
|
||||
//vs_position = (modelViewTransform * vec4(in_position, 1.0)).xyz;
|
||||
//vs_position = in_position;
|
||||
vs_color = in_color;
|
||||
|
||||
/*vec4 positionClipSpace = vec4(projection * view * model * vec4(in_position, 1.0));
|
||||
vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace));
|
||||
vs_screenSpaceDepth = positionScreenSpace.w;*/
|
||||
//vs_screenSpaceDepth = 1.0;
|
||||
|
||||
//gl_PointSize = scaleFactor;
|
||||
//gl_Position = positionScreenSpace;
|
||||
|
||||
// project the position to view space
|
||||
//gl_Position = viewProjection * vec4(vs_position, 1.0);
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
//gl_Position.z = 1.0;
|
||||
}
|
||||
Reference in New Issue
Block a user