Setting globe color

classic Classic list List threaded Threaded
9 messages Options
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Setting globe color

Using osgEarth 3.0, I'm trying to change the globe color programmatically as follows:

Color globeColor = Color(0.5, 0.5, 0.5);
mapNode->getTerrainOptions().setColor(globeColor);


However, it doesn't have any effect and the globe color is still white.

Am I doing something wrong or do I have to resort to shaders to change the default globe color?

Thanks

Shayne
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

For a sanity check, I added the following to my .earth file

<map>
     <options>
        <terrain>     
                   
            <color>#ff0000</color>
        </terrain>
    </options>
</map>

This also has no effect in changing the globe color...

2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

In reply to this post by 2LR
Just another follow up to my first post...

My goal in changing the globe color to something other than white was to reduce the brightness of the displayed maps so I could see my annotations and symbology better on the globe.

I was able to achieve this via shaders by doing the following:

namespace // vert and frag shaders for dimming the maps on the globe
{
        const char* globeVS =
                "#version " GLSL_VERSION_STR "\n"
                "out vec2 globe_texcoord; \n"
                "uniform mat4 oe_layer_texMatrix; \n"
                "vec4 oe_layer_tilec; \n"
                "void globe_VS(inout vec4 vertex) \n"
                "{ \n"
                "    globe_texcoord = (oe_layer_texMatrix*oe_layer_tilec).st; \n"
                "} \n";

        const char* globeFS =
                "#version " GLSL_VERSION_STR "\n"
                "in vec2 globe_texcoord; \n"
                "uniform sampler2D globe_tex; \n"
                "uniform vec4 globe_color; \n"
                "void globe_FS(inout vec4 out_color) \n"
                "{ \n"
                "    vec4 color = texture(globe_tex, globe_texcoord); \n"
                "    out_color = color * globe_color; \n"
                "} \n";
}

void Maps::initialize(MapNode* mapNode)
{
        _mapNode = mapNode;

        osg::StateSet* st = _mapNode->getTerrainEngine()->getSurfaceStateSet();
        VirtualProgram* vp = VirtualProgram::getOrCreate(st);
        vp->setFunction("globe_VS", globeVS, ShaderComp::LOCATION_VERTEX_MODEL);
        vp->setFunction("globe_FS", globeFS, ShaderComp::LOCATION_FRAGMENT_COLORING);
        st->addUniform(new osg::Uniform("globe_color", osg::Vec4(0.25, 0.25, 0.25, 1.0)));
        .
        .
        .
}


This works perfectly like I want it to and dims the background image texture by 75%. Unfortunately, I can no longer pick my annotations with RTTPicker. Not sure why. For some reason, introducing the shaders breaks the RTTPicker.

Any ideas on why this is happening?

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

In reply to this post by 2LR
Curious. Your earth file yields a red globe with osgEarth 3.1. Any chance you can try that?

Glenn Waldron / Pelican Mapping
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

I can certainly try 3.1 when time permits, however, our current situation allows for us to use 3.0 right now.

If possible, can you try 3.0 to see if you see the problem there? That would verify whether or not it's a problem in 3.0 in general or a problem with my particular build...
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

In reply to this post by gwaldron
Glenn,

Per your recommendation, I did try changing the globe color via the earth file and it appears to work in 3.1.

However, I'm still unable to change the globe color programmatically.

I'm using the following code in an attempt to change globe color inside my program...

Color globeColor = Color(1.0, 0.0, 0.0);
TerrainOptionsAPI terrOptions = mapNode->getTerrainOptions();
mapNode->getTerrainOptions().setColor(globeColor);

Can you or anyone else tell me if this is the correct way to do this?
marcoma9023 marcoma9023
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color


Hi, I also had this need.

Now I have solved it in the following way:

osgEarth::Drivers::MPTerrainEngine::MPTerrainEngineOptions mapNodeOptions;
mapNodeOptions.color() = osgEarth::Symbology::Color(204 / 255.0f, 197 / 255.0f, 123 / 255.0f, 1.0);
osg::ref_ptr<MapNode> mapNode = new osgEarth::MapNode(earthMap, mapNodeOptions);

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

In reply to this post by 2LR
Shayne,
There is no way to sent the color after the MapNode has been created. That's a feature we could add though .. just open a GitHub ticket and we'll put it on the list.
Glenn Waldron / Pelican Mapping
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: Setting globe color

Okay. That explains why my code didn't work. I will submit a ticket...

For now, I will set the globe color via the earth file.

The next question...

Is there a way to blend the map texture with the globe color? This would allow me to dim the map by reducing the globe color intensity. Right now, it appears that the blend mode is "replace" when a map texture is rendered on the globe.

As a side note, I did this successfully with a shader (see my previous post above) but it broke the RTTPicker.