mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 11:39:49 -06:00
added the possibility to load a city light/night texture for planets
This commit is contained in:
@@ -64,13 +64,14 @@ private:
|
||||
properties::StringProperty _colorTexturePath;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
ghoul::opengl::Texture* _nightTexture;
|
||||
planetgeometry::PlanetGeometry* _geometry;
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
std::string _nightTexturePath;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
double _time;
|
||||
|
||||
@@ -36,8 +36,10 @@ uniform int shadows;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec2 vs_nightTex;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
@@ -51,6 +53,7 @@ void main()
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(texture1, vs_st);
|
||||
vec4 diffuse2 = texture(nightTex, vs_st);
|
||||
|
||||
if (_performShading) {
|
||||
// directional lighting
|
||||
@@ -62,6 +65,7 @@ void main()
|
||||
vec3 l_pos = vec3(sun_pos); // sun.
|
||||
vec3 l_dir = normalize(l_pos-objpos.xyz);
|
||||
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
|
||||
float darkSide = min(max(5*dot(n,-l_dir), 0.0), 1);
|
||||
|
||||
float shine = 0.0001;
|
||||
|
||||
@@ -76,9 +80,12 @@ void main()
|
||||
spec = specular * pow(intSpec, shine);
|
||||
}
|
||||
*/
|
||||
diffuse = max(intensity * diffuse, ambient);
|
||||
vec4 daytex = max(intensity * diffuse, ambient);
|
||||
vec4 mixtex = mix(diffuse, diffuse2, (1+dot(n,-l_dir))/2);
|
||||
|
||||
diffuse = (daytex*2 + mixtex)/3;
|
||||
|
||||
diffuse[3] = transparency;
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
|
||||
addToBuffer(frag);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,10 @@ namespace openspace {
|
||||
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _nightTexturePath("")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _nightTexture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
@@ -68,8 +70,8 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
ghoul_assert(success,
|
||||
"RenderablePlanet need the '" <<constants::scenegraphnode::keyName<<"' be specified");
|
||||
|
||||
//std::string path;
|
||||
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
std::string path;
|
||||
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
//ghoul_assert(success,
|
||||
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
|
||||
|
||||
@@ -91,8 +93,20 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
std::string texturePath = "";
|
||||
success = dictionary.getValue("Textures.Color", texturePath);
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
//if (success)
|
||||
//_colorTexturePath = path + "/" + texturePath;
|
||||
if (success)
|
||||
_colorTexturePath = path + "/" + texturePath;
|
||||
|
||||
std::string nightTexturePath = "";
|
||||
success = dictionary.getValue("Textures.Night", nightTexturePath);
|
||||
if (success){
|
||||
_nightTexturePath = absPath(nightTexturePath);
|
||||
_nightTexturePath = path + "/" + nightTexturePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_nightTexturePath = absPath(texturePath);
|
||||
_nightTexturePath = path + "/" + texturePath;
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
|
||||
@@ -128,11 +142,14 @@ bool RenderablePlanet::deinitialize() {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
}
|
||||
if(_texture)
|
||||
if (_texture)
|
||||
delete _texture;
|
||||
if (_nightTexture)
|
||||
delete _nightTexture;
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_nightTexture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -181,10 +198,16 @@ void RenderablePlanet::render(const RenderData& data)
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
|
||||
// Bind texture
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
ghoul::opengl::TextureUnit dayUnit;
|
||||
dayUnit.activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("texture1", unit);
|
||||
_programObject->setUniform("texture1", dayUnit);
|
||||
|
||||
// Bind possible night texture
|
||||
ghoul::opengl::TextureUnit nightUnit;
|
||||
nightUnit.activate();
|
||||
_nightTexture->bind();
|
||||
_programObject->setUniform("nightTex", nightUnit);
|
||||
|
||||
// render
|
||||
_geometry->render();
|
||||
@@ -202,8 +225,18 @@ void RenderablePlanet::update(const UpdateData& data){
|
||||
void RenderablePlanet::loadTexture() {
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
delete _nightTexture;
|
||||
_nightTexture = nullptr;
|
||||
if (_nightTexturePath != "") {
|
||||
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath));
|
||||
if (_nightTexture) {
|
||||
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
|
||||
_nightTexture->uploadTexture();
|
||||
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
}
|
||||
}
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
|
||||
_texture->uploadTexture();
|
||||
|
||||
Reference in New Issue
Block a user