diff --git a/include/openspace/rendering/planets/renderableplanet.h b/include/openspace/rendering/planets/renderableplanet.h index f0cc725b87..2d3684552a 100644 --- a/include/openspace/rendering/planets/renderableplanet.h +++ b/include/openspace/rendering/planets/renderableplanet.h @@ -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; diff --git a/shaders/pscstandard_fs.glsl b/shaders/pscstandard_fs.glsl index 8842f959a1..b4ae6a4131 100644 --- a/shaders/pscstandard_fs.glsl +++ b/shaders/pscstandard_fs.glsl @@ -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); } diff --git a/src/rendering/planets/renderableplanet.cpp b/src/rendering/planets/renderableplanet.cpp index 958507d87d..817cf1acd4 100644 --- a/src/rendering/planets/renderableplanet.cpp +++ b/src/rendering/planets/renderableplanet.cpp @@ -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 '" <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();