gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.48k stars 774 forks source link

hillshade support in ContourMap #836

Closed kinsung closed 7 years ago

kinsung commented 7 years ago

How to support hillshade in osgearth ContourMap? I modify ContourMap.frag.glsl file as below, it does not work.

#version $GLSL_VERSION_STR
$GLSL_DEFAULT_PRECISION_FLOAT

#pragma vp_entryPoint oe_contour_fragment
#pragma vp_location   fragment_coloring
#pragma vp_order      0.2

varying vec4 oe_layer_tilec;
uniform sampler1D oe_contour_xfer;
uniform float oe_contour_opacity;
uniform float oe_contour_min;
uniform float oe_contour_range;

float oe_terrain_getElevation(in vec2 uv);

void oe_contour_fragment( inout vec4 color )
{
    float height = oe_terrain_getElevation(oe_layer_tilec.st);
    float height_normalized = (height-oe_contour_min)/oe_contour_range;
    float lookup = clamp( height_normalized, 0.0, 1.0 );
    vec4 texel = texture1D( oe_contour_xfer, lookup );

    float x = oe_layer_tilec.st.x;
    float y = oe_layer_tilec.st.y;
    float delta = 1.0f;
    float left   = oe_terrain_getElevation( vec2(x - delta, y) );
    float right  = oe_terrain_getElevation(vec2(x + delta, y) );
    float bottom = oe_terrain_getElevation(vec2(x, y - delta) );
    float top    = oe_terrain_getElevation(vec2(x, y + delta) );
    vec2 gradient = vec2( (right - left) / (2*delta), (top - bottom) / (2*delta));

    vec3 lightDir = normalize(vec3(gl_LightSource[0].position));
    vec2 L =  (lightDi.x, lightDir.y);
    float brightness = dot(gradient, L);

    color.rgb = mix(color.rgb * brightness, texel.rgb, texel.a * oe_contour_opacity);
}
gwaldron commented 7 years ago

You do not need special shader code for this - you just need a light source. For example:

osgearth_viewer contourmap.earth --sky