A texture map that is only visible in dark parts of a sphere

hey there,



i now have my pretty earth (from space) with its map and fixed pipe bump mapping (my avatar). now, as it should be, the “night” side of the earth is black, but i want it to show the following texture:



http://www.hemmy.net/2007/03/29/city-lights-on-earth-from-space/



to look like in this video:



MOD link missing: http://youtube.com/watch?v=pQsZhoQekAM



that means that diffuse und bump map texture have to be invisible in shadow and the lightsMap has to be invisible in light …



hope you know what i mean.



thats how its done until now:


    // get the heightmap that is used for bumpmapping
    Texture tex =
        TextureCache.getInstance().getTexture(
            getClass().getClassLoader().getResource("themes/startheme/earthBump4096.dds"), game, true).getTexture();

    tex.setWrap(Texture.WM_WRAP_S_WRAP_T);
    tex.setApply(Texture.AM_COMBINE);
    tex.setCombineFuncRGB(Texture.ACF_DOT3_RGB);
    tex.setCombineSrc0RGB(Texture.ACS_TEXTURE);
    tex.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);

    ts.setTexture(tex, 0);

    // get the texture that shows the surface
    Texture tex2 =
        TextureCache.getInstance().getTexture(getClass().getClassLoader().getResource("themes/startheme/earthMap4096.dds"),
            game, true).getTexture();
    tex2.setApply(Texture.AM_COMBINE);
    tex2.setWrap(Texture.WM_WRAP_S_WRAP_T);
    tex2.setCombineFuncRGB(Texture.ACF_MODULATE);
    tex2.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
    tex2.setCombineSrc1RGB(Texture.ACS_TEXTURE);
    ts.setTexture(tex2, 1);



thx in advance,
Andy

Hi, you need to interpolate the night texture to the day texture using the result from the DOT3 (lighting) operation in the previous unit. Use the INTERPOLATE Combine function.

hey, thank you so far, but i dont seem to get it right …



thats the relevant code for the creation of the earth:




    // create a FloatBuffer and set it up
    FloatBuffer tBuf = earth.getTextureBuffer(0, 0);
    tBuf.clear();
    tBuf.put(0).put(5);
    tBuf.put(0).put(0);
    tBuf.put(5).put(0);
    tBuf.put(5).put(5);

    // create a Material State and set the color
    MaterialState ms = TaskQueueUtil.getMaterialState(game);
    ms.setAmbient(ColorRGBA.white);
    ms.setDiffuse(ColorRGBA.white);

    // create the BumpMapController that manages the bumpmapping effect
    c = new BumpMapColorController(earth);
    earth.addController(c);
    earth.setRenderState(ms);

    // create the TextureState for the texture we use for the earths landmasses
    TextureState ts = TaskQueueUtil.getTextureState(game);

    // get the heightmap that is used for bumpmapping
    Texture tex =
        TextureCache.getInstance().getTexture(
            getClass().getClassLoader().getResource("themes/startheme/earthBump4096.dds"), game, true, true).getTexture();

    tex.setWrap(Texture.WM_WRAP_S_WRAP_T);
    tex.setApply(Texture.AM_COMBINE);
    tex.setCombineFuncRGB(Texture.ACF_DOT3_RGB);
    tex.setCombineSrc0RGB(Texture.ACS_TEXTURE);
    tex.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);

    ts.setTexture(tex, 0);

    // get the texture that shows the surface
    Texture tex2 =
        TextureCache.getInstance().getTexture(
            getClass().getClassLoader().getResource("themes/startheme/earthMap4096.dds"), game, true, true).getTexture();
    tex2.setApply(Texture.AM_COMBINE);
    tex2.setWrap(Texture.WM_WRAP_S_WRAP_T);
    tex2.setCombineFuncRGB(Texture.ACF_MODULATE);
    tex2.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
    tex2.setCombineSrc1RGB(Texture.ACS_TEXTURE);
    ts.setTexture(tex2, 1);

     // get the texture that shows city lights
     Texture tex3 =
     TextureCache.getInstance().getTexture(getClass().getClassLoader().getResource("themes/startheme/lightsMap2048.dds"),
     game, true, true).getTexture();
     tex3.setApply(Texture.AM_COMBINE);
     tex3.setWrap(Texture.WM_WRAP_S_WRAP_T);
     tex3.setCombineFuncRGB(Texture.ACF_INTERPOLATE);
     tex2.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
     tex2.setCombineSrc1RGB(Texture.ACS_TEXTURE);
     ts.setTexture(tex3, 2);

    // edit the texturecoordinates accordingly
    earth.copyTextureCoords(0, 0, 1);
    // set up the renderstate
    earth.setRenderState(ts);

    // create the ZBufferState
    ZBufferState buf = TaskQueueUtil.getZBufferState(game);
    buf.setEnabled(true);
    buf.setFunction(ZBufferState.CF_LEQUAL);

    // set render state
    earth.setRenderState(buf);



and the light:



    // detach everything from the lightState
    lightState.detachAll();
    lightState.setSeparateSpecular(true);

    // create and set up a DirectionalLight
    DirectionalLight dl = new DirectionalLight();
    dl.setEnabled(true);
    dl.setDiffuse(ColorRGBA.white);
    dl.setAmbient(ColorRGBA.black);
    dl.setDirection(new Vector3f(0, 0, 1));


    // create a new LightNode ...
    lightNode = new LightNode("light", lightState);
    lightNode.setCullMode(SceneElement.CULL_NEVER);
    lightNode.setLight(dl);
    // ... and set the rootNode as target, so everything is influenced by the light
    lightNode.setTarget(rootNode);
    lightNode.setLocalTranslation(new Vector3f(-180f, 60f, -50f));



now that the ambient light is black, i cant see anything on the dark side of the earth, if i make it another color, the normal surface texture appears in some form, but not the city lights. how would i have to set the material colors and light colors? do i apply the city lights texture correctly?

First of all, you have a mistake:


tex3.setCombineFuncRGB(Texture.ACF_INTERPOLATE);
tex2.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
tex2.setCombineSrc1RGB(Texture.ACS_TEXTURE);

You are modifying tex2 instead of tex3 in the last 2 calls.

The interpolation code needs to be as follows:

tex3.setCombineFuncRGB(Texture.ACF_INTERPOLATE);
tex3.setCombineSrc0RGB(Texture.ACS_TEXTURE);
tex3.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
tex3.setCombineSrc2RGB(Texture.ACS_PREVIOUS);


You interpolate the nightmap toward the lit colormap using the colormap's intensity (which is premultiplied with the lighting)
Ideally you would want to interpolate using the unmodified lighting but this might be difficult (or even impossible) to do in fixed-function multitexturing.