mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-10 23:38:38 -05:00
Merge pull request #1231 from OpenSpace/issue/1160
Added scaling properties to eclipses.
This commit is contained in:
@@ -60,11 +60,14 @@
|
||||
#include <modules/atmosphere/rendering/atmospheredeferredcaster.h>
|
||||
|
||||
#include <modules/atmosphere/rendering/renderableatmosphere.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -111,6 +114,37 @@ namespace {
|
||||
|
||||
constexpr const float ATM_EPS = 2.f;
|
||||
constexpr const float KM_TO_M = 1000.f;
|
||||
|
||||
|
||||
void createRenderQuad(GLuint* vao, GLuint* vbo, GLfloat size) {
|
||||
glGenVertexArrays(1, vao);
|
||||
glGenBuffers(1, vbo);
|
||||
glBindVertexArray(*vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, *vbo);
|
||||
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y z w
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
-size, size, 0.0f, 1.0f,
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 4,
|
||||
nullptr
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -169,12 +203,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
renderData.camera.sgctInternal.projectionMatrix()
|
||||
) * renderData.camera.combinedViewMatrix();
|
||||
|
||||
if (!isAtmosphereInFrustum(
|
||||
MV,
|
||||
tPlanetPosWorld,
|
||||
(_atmosphereRadius + ATM_EPS)*KM_TO_M)
|
||||
)
|
||||
{
|
||||
const float totalAtmosphere = (_atmosphereRadius + ATM_EPS)* KM_TO_M;
|
||||
if (!isAtmosphereInFrustum(MV, tPlanetPosWorld, totalAtmosphere)) {
|
||||
program.setUniform(_uniformCache.cullAtmosphere, 1);
|
||||
}
|
||||
else {
|
||||
@@ -290,6 +320,32 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
);
|
||||
casterPos *= KM_TO_M; // converting to meters
|
||||
|
||||
const std::string source = shadowConf.source.first;
|
||||
SceneGraphNode* sourceNode =
|
||||
global::renderEngine.scene()->sceneGraphNode(source);
|
||||
const std::string caster = shadowConf.caster.first;
|
||||
SceneGraphNode* casterNode =
|
||||
global::renderEngine.scene()->sceneGraphNode(caster);
|
||||
|
||||
const double sourceRadiusScale = std::max(
|
||||
glm::compMax(sourceNode->scale()),
|
||||
1.0
|
||||
);
|
||||
|
||||
const double casterRadiusScale = std::max(
|
||||
glm::compMax(casterNode->scale()),
|
||||
1.0
|
||||
);
|
||||
|
||||
if ((sourceNode == nullptr) || (casterNode == nullptr)) {
|
||||
LERRORC(
|
||||
"AtmosphereDeferredcaster",
|
||||
"Invalid scenegraph node for the shadow's caster or shadow's "
|
||||
"receiver."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// First we determine if the caster is shadowing the current planet
|
||||
// (all calculations in World Coordinates):
|
||||
glm::dvec3 planetCasterVec =
|
||||
@@ -300,9 +356,11 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
glm::dot(planetCasterVec, sourceCasterVec) /
|
||||
(sc_length*sc_length)) * sourceCasterVec;
|
||||
double d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
double xp_test = shadowConf.caster.second *
|
||||
sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
double rp_test = shadowConf.caster.second *
|
||||
double xp_test = shadowConf.caster.second * casterRadiusScale *
|
||||
sc_length /
|
||||
(shadowConf.source.second * sourceRadiusScale +
|
||||
shadowConf.caster.second * casterRadiusScale);
|
||||
double rp_test = shadowConf.caster.second * casterRadiusScale *
|
||||
(glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
double casterDistSun = glm::length(casterPos - sunPosWorld);
|
||||
@@ -314,12 +372,12 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
shadowData.isShadowing = false;
|
||||
|
||||
if (((d_test - rp_test) < (_atmospherePlanetRadius * KM_TO_M)) &&
|
||||
//if (((d_test - rp_test) < (_atmosphereRadius * KM_TO_M)) &&
|
||||
(casterDistSun < planetDistSun)) {
|
||||
(casterDistSun < planetDistSun))
|
||||
{
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.rs = shadowConf.source.second * sourceRadiusScale;
|
||||
shadowData.rc = shadowConf.caster.second * casterRadiusScale;
|
||||
shadowData.sourceCasterVec = glm::normalize(sourceCasterVec);
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length /
|
||||
@@ -331,7 +389,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
|
||||
const std::string uniformVarName("shadowDataArray[");
|
||||
unsigned int counter = 0;
|
||||
for (const ShadowRenderingStruct & sd : shadowDataArray) {
|
||||
for (const ShadowRenderingStruct& sd : shadowDataArray) {
|
||||
std::stringstream ss;
|
||||
ss << uniformVarName << counter << "].isShadowing";
|
||||
program.setUniform(ss.str(), sd.isShadowing);
|
||||
@@ -464,30 +522,24 @@ void AtmosphereDeferredcaster::setSunRadianceIntensity(float sunRadiance) {
|
||||
_sunRadianceIntensity = sunRadiance;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(
|
||||
const glm::vec3& rayScattCoeff)
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(glm::vec3 rayScattCoeff)
|
||||
{
|
||||
_rayleighScatteringCoeff = std::move(rayScattCoeff);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setOzoneExtinctionCoefficients(
|
||||
const glm::vec3& ozoneExtCoeff)
|
||||
{
|
||||
void AtmosphereDeferredcaster::setOzoneExtinctionCoefficients(glm::vec3 ozoneExtCoeff) {
|
||||
_ozoneExtinctionCoeff = std::move(ozoneExtCoeff);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMieScatteringCoefficients(
|
||||
const glm::vec3& mieScattCoeff)
|
||||
{
|
||||
void AtmosphereDeferredcaster::setMieScatteringCoefficients(glm::vec3 mieScattCoeff) {
|
||||
_mieScatteringCoeff = std::move(mieScattCoeff);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMieExtinctionCoefficients(const glm::vec3& mieExtCoeff)
|
||||
{
|
||||
void AtmosphereDeferredcaster::setMieExtinctionCoefficients(glm::vec3 mieExtCoeff) {
|
||||
_mieExtinctionCoeff = std::move(mieExtCoeff);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setEllipsoidRadii(const glm::dvec3& radii) {
|
||||
void AtmosphereDeferredcaster::setEllipsoidRadii(glm::dvec3 radii) {
|
||||
_ellipsoidRadii = std::move(radii);
|
||||
}
|
||||
|
||||
@@ -496,7 +548,7 @@ void AtmosphereDeferredcaster::setHardShadows(bool enabled) {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setShadowConfigArray(
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray)
|
||||
std::vector<ShadowConfiguration> shadowConfigArray)
|
||||
{
|
||||
_shadowConfArray = std::move(shadowConfigArray);
|
||||
}
|
||||
@@ -1210,36 +1262,6 @@ void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
|
||||
LDEBUG("Ended precalculations for Atmosphere effects...");
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::createRenderQuad(GLuint* vao, GLuint* vbo, GLfloat size) {
|
||||
glGenVertexArrays(1, vao);
|
||||
glGenBuffers(1, vbo);
|
||||
glBindVertexArray(*vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, *vbo);
|
||||
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y z w
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
-size, size, 0.0f, 1.0f,
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 4,
|
||||
nullptr
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg)
|
||||
{
|
||||
|
||||
@@ -79,12 +79,12 @@ public:
|
||||
void setMieHeightScale(float mieHeightScale);
|
||||
void setMiePhaseConstant(float miePhaseConstant);
|
||||
void setSunRadianceIntensity(float sunRadiance);
|
||||
void setRayleighScatteringCoefficients(const glm::vec3& rayScattCoeff);
|
||||
void setOzoneExtinctionCoefficients(const glm::vec3& ozoneExtCoeff);
|
||||
void setMieScatteringCoefficients(const glm::vec3& mieScattCoeff);
|
||||
void setMieExtinctionCoefficients(const glm::vec3& mieExtCoeff);
|
||||
void setEllipsoidRadii(const glm::dvec3& radii);
|
||||
void setShadowConfigArray(const std::vector<ShadowConfiguration>& shadowConfigArray);
|
||||
void setRayleighScatteringCoefficients(glm::vec3 rayScattCoeff);
|
||||
void setOzoneExtinctionCoefficients(glm::vec3 ozoneExtCoeff);
|
||||
void setMieScatteringCoefficients(glm::vec3 mieScattCoeff);
|
||||
void setMieExtinctionCoefficients(glm::vec3 mieExtCoeff);
|
||||
void setEllipsoidRadii(glm::dvec3 radii);
|
||||
void setShadowConfigArray(std::vector<ShadowConfiguration> shadowConfigArray);
|
||||
void setHardShadows(bool enabled);
|
||||
void enableSunFollowing(bool enable);
|
||||
|
||||
@@ -99,7 +99,6 @@ private:
|
||||
void deleteUnusedComputationTextures();
|
||||
void executeCalculations(GLuint quadCalcVAO, GLenum drawBuffers[1],
|
||||
GLsizei vertexSize);
|
||||
void createRenderQuad(GLuint* vao, GLuint* vbo, GLfloat size);
|
||||
void step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
int layer, bool doCalculation = true);
|
||||
void checkFrameBufferState(const std::string& codePosition) const;
|
||||
|
||||
@@ -130,7 +130,7 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows], co
|
||||
return vec4(0.2, 0.2, 0.2, 1.0);
|
||||
}
|
||||
else {
|
||||
return butterworthFunc(length_d, r_u_pi, 4.0);
|
||||
return butterworthFunc(length_d, r_u_pi, 2.0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -138,7 +138,8 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows], co
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
}
|
||||
else {
|
||||
return vec4(vec3(length_d/r_p_pi), 1.0);
|
||||
//return vec4(vec3(length_d/r_p_pi), 1.0);
|
||||
return butterworthFunc(length_d, r_u_pi, 2.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows],
|
||||
return vec4(0.2, 0.2, 0.2, 1.0);
|
||||
#else
|
||||
// butterworthFunc
|
||||
return vec4(vec3(sqrt(r_u_pi / (r_u_pi + pow(length_d, 8.0)))), 1.0);
|
||||
return vec4(vec3(sqrt(r_u_pi / (r_u_pi + pow(length_d, 2.0)))), 1.0);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -24,19 +24,21 @@
|
||||
|
||||
#include <modules/globebrowsing/src/renderableglobe.h>
|
||||
|
||||
#include <modules/debugging/rendering/debugrenderer.h>
|
||||
#include <modules/globebrowsing/src/basictypes.h>
|
||||
#include <modules/globebrowsing/src/gpulayergroup.h>
|
||||
#include <modules/globebrowsing/src/layer.h>
|
||||
#include <modules/globebrowsing/src/layergroup.h>
|
||||
#include <modules/globebrowsing/src/renderableglobe.h>
|
||||
#include <modules/globebrowsing/src/tileprovider.h>
|
||||
#include <modules/debugging/rendering/debugrenderer.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/performance/performancemanager.h>
|
||||
#include <openspace/performance/performancemeasurement.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
@@ -518,8 +520,8 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
FloatProperty(OrenNayarRoughnessInfo, 0.f, 0.f, 1.f),
|
||||
IntProperty(NActiveLayersInfo, 0, 0, OpenGLCap.maxTextureUnits() / 3)
|
||||
})
|
||||
, _shadowMappingPropertyOwner({ "ShadowMapping" })
|
||||
, _debugPropertyOwner({ "Debug" })
|
||||
, _shadowMappingPropertyOwner({ "ShadowMapping" })
|
||||
, _grid(DefaultSkirtedGridSegments, DefaultSkirtedGridSegments)
|
||||
, _leftRoot(Chunk(LeftHemisphereIndex))
|
||||
, _rightRoot(Chunk(RightHemisphereIndex))
|
||||
@@ -774,7 +776,6 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask
|
||||
if (distanceToCamera < distance) {
|
||||
try {
|
||||
// Before Shadows
|
||||
//renderChunks(data, rendererTask);
|
||||
_globeLabelsComponent.draw(data);
|
||||
|
||||
if (_hasShadows && _shadowComponent.isEnabled()) {
|
||||
@@ -2058,25 +2059,45 @@ void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& prog
|
||||
lt
|
||||
);
|
||||
casterPos *= KM_TO_M; // converting to meters
|
||||
// psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(
|
||||
// casterPos.x,
|
||||
// casterPos.y,
|
||||
// casterPos.z
|
||||
// );
|
||||
|
||||
const std::string source = shadowConf.source.first;
|
||||
SceneGraphNode* sourceNode = global::renderEngine.scene()->sceneGraphNode(source);
|
||||
const std::string caster = shadowConf.caster.first;
|
||||
SceneGraphNode* casterNode = global::renderEngine.scene()->sceneGraphNode(caster);
|
||||
|
||||
const double sourceRadiusScale = std::max(
|
||||
glm::compMax(sourceNode->scale()),
|
||||
1.0
|
||||
);
|
||||
|
||||
const double casterRadiusScale = std::max(
|
||||
glm::compMax(casterNode->scale()),
|
||||
1.0
|
||||
);
|
||||
|
||||
if ((sourceNode == nullptr) || (casterNode == nullptr)) {
|
||||
LERRORC(
|
||||
"Renderableglobe",
|
||||
"Invalid scenegraph node for the shadow's caster or shadow's receiver."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all
|
||||
// calculations in World Coordinates):
|
||||
const glm::dvec3 planetCasterVec = casterPos - data.modelTransform.translation;
|
||||
const glm::dvec3 sourceCasterVec = casterPos - sourcePos;
|
||||
|
||||
const double sc_length = glm::length(sourceCasterVec);
|
||||
const glm::dvec3 planetCaster_proj =
|
||||
(glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) *
|
||||
sourceCasterVec;
|
||||
const double d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
const double xp_test = shadowConf.caster.second * sc_length /
|
||||
(shadowConf.source.second + shadowConf.caster.second);
|
||||
const double rp_test = shadowConf.caster.second *
|
||||
|
||||
const double d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
const double xp_test = shadowConf.caster.second * casterRadiusScale *
|
||||
sc_length / (shadowConf.source.second * sourceRadiusScale +
|
||||
shadowConf.caster.second * casterRadiusScale);
|
||||
const double rp_test = shadowConf.caster.second * casterRadiusScale *
|
||||
(glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
const glm::dvec3 sunPos = SpiceManager::ref().targetPosition(
|
||||
@@ -2099,13 +2120,13 @@ void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& prog
|
||||
(casterDistSun < planetDistSun))
|
||||
{
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = glm::normalize(sourceCasterVec);
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length /
|
||||
(shadowData.rs - shadowData.rc);
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second * sourceRadiusScale;
|
||||
shadowData.rc = shadowConf.caster.second * casterRadiusScale;
|
||||
shadowData.sourceCasterVec = glm::normalize(sourceCasterVec);
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length /
|
||||
(shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = casterPos;
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
@@ -2115,15 +2136,16 @@ void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& prog
|
||||
unsigned int counter = 0;
|
||||
for (const ShadowRenderingStruct& sd : shadowDataArray) {
|
||||
constexpr const char* NameIsShadowing = "shadowDataArray[{}].isShadowing";
|
||||
constexpr const char* NameXp = "shadowDataArray[{}].xp";
|
||||
constexpr const char* NameXu = "shadowDataArray[{}].xu";
|
||||
constexpr const char* NameRc = "shadowDataArray[{}].rc";
|
||||
constexpr const char* NameSource = "shadowDataArray[{}].sourceCasterVec";
|
||||
constexpr const char* NamePos = "shadowDataArray[{}].casterPositionVec";
|
||||
constexpr const char* NameXp = "shadowDataArray[{}].xp";
|
||||
constexpr const char* NameXu = "shadowDataArray[{}].xu";
|
||||
constexpr const char* NameRc = "shadowDataArray[{}].rc";
|
||||
constexpr const char* NameSource = "shadowDataArray[{}].sourceCasterVec";
|
||||
constexpr const char* NamePos = "shadowDataArray[{}].casterPositionVec";
|
||||
|
||||
programObject.setUniform(
|
||||
fmt::format(NameIsShadowing, counter), sd.isShadowing
|
||||
);
|
||||
|
||||
if (sd.isShadowing) {
|
||||
programObject.setUniform(fmt::format(NameXp, counter), sd.xp);
|
||||
programObject.setUniform(fmt::format(NameXu, counter), sd.xu);
|
||||
|
||||
Reference in New Issue
Block a user