mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-21 10:28:44 -05:00
Merged.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -61,7 +61,7 @@ namespace {
|
||||
const char* keyShadowGroup = "Shadow_Group";
|
||||
const char* keyShadowSource = "Source";
|
||||
const char* keyShadowCaster = "Caster";
|
||||
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo ColorTextureInfo = {
|
||||
"ColorTexture",
|
||||
"Color Base Texture",
|
||||
@@ -413,11 +413,26 @@ glm::dmat4 RenderablePlanet::computeModelTransformMatrix(const openspace::Transf
|
||||
glm::dmat4(transformData.rotation) * // Spice rotation
|
||||
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(transformData.scale)));
|
||||
|
||||
// scale the planet to appropriate size since the planet is a unit sphere
|
||||
//glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
//earth needs to be rotated for that to work.
|
||||
glm::dmat4 rot = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(1, 0, 0));
|
||||
glm::dmat4 roty = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(0, -1, 0));
|
||||
glm::dmat4 rot = glm::rotate(
|
||||
glm::dmat4(1.0),
|
||||
glm::half_pi<double>(),
|
||||
glm::dvec3(1, 0, 0)
|
||||
);
|
||||
glm::dmat4 roty = glm::rotate(
|
||||
glm::dmat4(1.0),
|
||||
glm::half_pi<double>(),
|
||||
glm::dvec3(0, -1, 0)
|
||||
);
|
||||
//glm::dmat4 rotProp = glm::rotate(
|
||||
// glm::dmat4(1.0),
|
||||
// glm::radians(static_cast<double>(_rotation)), glm::dvec3(0, 1, 0)
|
||||
//);
|
||||
|
||||
return modelTransform * rot * roty;
|
||||
return modelTransform = modelTransform * rot * roty /** rotProp*/;
|
||||
}
|
||||
|
||||
void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask) {
|
||||
@@ -435,8 +450,20 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask)
|
||||
);
|
||||
_programObject->setUniform("ModelTransform", glm::mat4(modelTransform));
|
||||
|
||||
// Normal Transformation
|
||||
//glm::mat4 translateObjTrans = glm::translate(glm::mat4(1.0), data.position.vec3());
|
||||
//glm::mat4 translateCamTrans = glm::translate(
|
||||
// glm::mat4(1.0),
|
||||
// -data.camera.position().vec3()
|
||||
//);
|
||||
//float scaleFactor = data.camera.scaling().x * powf(10.0, data.camera.scaling().y);
|
||||
//glm::mat4 scaleCamTrans = glm::scale(glm::mat4(1.0), glm::vec3(scaleFactor));
|
||||
|
||||
// glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans *
|
||||
// translateCamTrans * translateObjTrans * glm::mat4(modelTransform);
|
||||
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
|
||||
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
_programObject->setUniform("_hasHeightMap", _hasHeightTexture);
|
||||
_programObject->setUniform("_heightExaggeration", _heightExaggeration);
|
||||
@@ -476,23 +503,49 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask)
|
||||
shadowDataArray.reserve(_shadowConfArray.size());
|
||||
|
||||
for (const auto & shadowConf : _shadowConfArray) {
|
||||
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!! We need to move this to view space...
|
||||
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!
|
||||
// We need to move this to view space...
|
||||
// Getting source and caster:
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(shadowConf.source.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(
|
||||
shadowConf.source.first,
|
||||
"SUN",
|
||||
"GALACTIC",
|
||||
{},
|
||||
_time,
|
||||
lt
|
||||
);
|
||||
sourcePos *= 1000.0; // converting to meters
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(
|
||||
shadowConf.caster.first,
|
||||
"SUN",
|
||||
"GALACTIC",
|
||||
{},
|
||||
_time,
|
||||
lt
|
||||
);
|
||||
casterPos *= 1000.0; // converting to meters
|
||||
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(casterPos.x, casterPos.y, casterPos.z);
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
|
||||
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
|
||||
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
|
||||
float sc_length = glm::length(sourceCasterVec);
|
||||
glm::vec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
|
||||
float d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
float xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
float rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(
|
||||
casterPos.x,
|
||||
casterPos.y,
|
||||
casterPos.z
|
||||
);
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all
|
||||
// calculations in World Coordinates):
|
||||
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
|
||||
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
|
||||
float sc_length = glm::length(sourceCasterVec);
|
||||
glm::vec3 planetCaster_proj =
|
||||
(glm::dot(planetCasterVec, sourceCasterVec) /
|
||||
(sc_length*sc_length)) * sourceCasterVec;
|
||||
float d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
float xp_test =
|
||||
shadowConf.caster.second * sc_length /
|
||||
(shadowConf.source.second + shadowConf.caster.second);
|
||||
float rp_test =
|
||||
shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) /
|
||||
xp_test;
|
||||
|
||||
double casterDistSun = glm::length(casterPos);
|
||||
float planetDistSun = glm::length(data.position.vec3());
|
||||
|
||||
@@ -502,12 +555,13 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask)
|
||||
if ( ((d_test - rp_test) < _planetRadius) &&
|
||||
(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 = sourceCasterVec;
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = sourceCasterVec;
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu =
|
||||
shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = glm::vec3(casterPos);
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
@@ -563,7 +617,9 @@ void RenderablePlanet::update(const UpdateData& data) {
|
||||
void RenderablePlanet::loadTexture() {
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(
|
||||
absPath(_colorTexturePath)
|
||||
);
|
||||
if (_texture) {
|
||||
if (_texture->numberOfChannels() == 1) {
|
||||
_texture->setSwizzleMask({ GL_RED, GL_RED, GL_RED, GL_RED });
|
||||
@@ -572,7 +628,8 @@ void RenderablePlanet::loadTexture() {
|
||||
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
|
||||
_texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than
|
||||
// linear
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
@@ -582,12 +639,16 @@ void RenderablePlanet::loadTexture() {
|
||||
if (_hasNightTexture) {
|
||||
_nightTexture = nullptr;
|
||||
if (_nightTexturePath.value() != "") {
|
||||
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath));
|
||||
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(
|
||||
absPath(_nightTexturePath)
|
||||
);
|
||||
if (_nightTexture) {
|
||||
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
|
||||
_nightTexture->uploadTexture();
|
||||
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
//_nightTexture->setFilter(
|
||||
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
|
||||
//);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -595,14 +656,19 @@ void RenderablePlanet::loadTexture() {
|
||||
if (_hasHeightTexture) {
|
||||
_heightMapTexture = nullptr;
|
||||
if (_heightMapTexturePath.value() != "") {
|
||||
_heightMapTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_heightMapTexturePath));
|
||||
_heightMapTexture = ghoul::io::TextureReader::ref().loadTexture(
|
||||
absPath(_heightMapTexturePath)
|
||||
);
|
||||
if (_heightMapTexture) {
|
||||
LDEBUG("Loaded texture from '" << _heightMapTexturePath << "'");
|
||||
_heightMapTexture->uploadTexture();
|
||||
_heightMapTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
//_nightTexture->setFilter(
|
||||
// ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
|
||||
//);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace openspace
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user