[SOLVED]bump mapping and directional light messed up

hey there,



i have a problem with the lights on my earth. when i use a pointlight it all works fine, but does not have the visual effect i want. so i have to use directional light.



when i do so, it all seems fine at the beginning, but as the earth turns around it all becomes grey (black). later when the side of the earth that was in the light at the beginning faces the sun again, it seems to work again. and so it goes on with every turn. to make it more clear, here are two screens:



good:





bad:





the methods that create the earth, the clouds and the light:



  /**
   * creates the clouds hovering over the earth
   */
  private Node createClouds() {
    // create the rotation node for the clouds
    Node rot = new Node();
    rot.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.DEG_TO_RAD * rotCloudsAngle, rotEarthAxis));

    // create the new Sphere that is the clouds
    clouds = new Sphere("clouds", new Vector3f(0, 0, 0), 50, 50, 20.5f);
    clouds.setModelBound(new BoundingSphere());
    clouds.updateModelBound();
    clouds.updateWorldBound();

    // create a FloatBuffer and set it up
    FloatBuffer tBuf = clouds.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 an AlphaState and set it up
    AlphaState as = TaskQueueUtil.getAlphaState(game);
    as.setBlendEnabled(true);
    as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
    as.setDstFunction(AlphaState.SB_ONE_MINUS_SRC_ALPHA);
    as.setTestEnabled(true);
    as.setTestFunction(AlphaState.TF_GREATER);

    // create a texturestate that holds the clouds texture
    TextureState tsTmp =
        TextureCache.getInstance().getTexture(getClass().getClassLoader().getResource("themes/startheme/clouds3.png"),
            game);

    // set the renderStates and renderQueueMode
    clouds.setRenderState(as);
    clouds.setRenderState(tsTmp);
    clouds.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);

    // add the Sphere to the rotation Node
    rot.attachChild(clouds);

    if (logger.isInfoEnabled())
      logger.info("clouds created");

    return rot;
  } // createClouds




 /**
   * creates the earth
   */
  private void createEarth() {
    // create the sphere that represents our earth
    earth = new Sphere("earth", new Vector3f(0, 0, 0), 50, 50, 20.0f);
    // set a Sphere as model bound
    earth.setModelBound(new BoundingSphere());
    // update a few things
    earth.updateModelBound();
    earth.updateWorldBound();

    // 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.setColorMaterial(MaterialState.CM_DIFFUSE);

    // initialize helper nodes
    Node eRotUSD = new Node();
    Node eRot90 = new Node();
    Node eTrans = new Node();
    eRot = new Node();

    // set up the quaternion for rotation
    rotEarth = new Quaternion();
    rotEarthAxis = new Vector3f(0, 0, 1);
    eRot.setLocalRotation(rotEarth.fromAngleAxis(0 * FastMath.DEG_TO_RAD, rotEarthAxis));

    // set the rotation
    eRotUSD.setLocalRotation(new Quaternion().fromAngleAxis(0 * FastMath.DEG_TO_RAD, new Vector3f(0, 0, 1)));
    eRotUSD.attachChild(eRot90);

    // initial rotation by 90 degrees
    eRot90.setLocalRotation(new Quaternion().fromAngleAxis(-110 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0)));
    eRot90.attachChild(eRot);

    // translate the earth to the place where it belongs
    eTrans.setLocalTranslation(new Vector3f(0f, -15f, -20.0f));
    eTrans.attachChild(eRotUSD);

    rootNode.attachChild(eTrans);

    // 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/EarthBump2DOT3.jpg"), 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/EarthMap3.jpg"), 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);

    // 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);

    // attach Spatials to the rotation nodes
    eRot.attachChild(earth);
    eRot.attachChild(createClouds());

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

    if (logger.isInfoEnabled())
      logger.info("earth created");
  } // createEarth





  /**
   * creates the lights in our universe
   */
  private void createLight() {

    // create a new lightState if needed
    if (lightState == null) {
      lightState = TaskQueueUtil.getLightState(game);
    } // if

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

    // create and set up a PointLight
    PointLight dr = new PointLight();
    dr.setEnabled(true);
    dr.setDiffuse(ColorRGBA.white);
    dr.setAmbient(ColorRGBA.blue);
    dr.setLocation(new Vector3f(0f, 0f, 0f));  // will be positioned correctly later
    lightState.setTwoSidedLighting(false);
   
    // Create a Basic Directional Light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(0f, 1f, 0f));
    dl.setDiffuse(ColorRGBA.white);
    dl.setAmbient(ColorRGBA.blue);
    dl.setEnabled(true);
   
    // create a new LightNode ...
    lightNode = new LightNode("light", lightState);
    lightNode.setLight(dl);                                                                                                           // POINTLIGHT WORKS, DIRECTIONALLIGHT DOESNT
    // ... and set the rootNode as target, so everything is influenced by the light
    lightNode.setTarget(rootNode);
    lightNode.setLocalTranslation(new Vector3f(-18f, 9.5f, -5f));

    // Setup the lensflare textures.
    TextureState[] tex = new TextureState[4];
    tex[0] = TaskQueueUtil.getTextureState(game);
    tex[0].setTexture(TextureCache.getInstance().getTexture(
        getClass().getClassLoader().getResource("lensFlare/flare1.png"), game).getTexture());
    tex[0].setEnabled(true);

    tex[1] = TaskQueueUtil.getTextureState(game);
    tex[1].setTexture(TextureCache.getInstance().getTexture(
        getClass().getClassLoader().getResource("lensFlare/flare2.png"), game).getTexture());
    tex[1].setEnabled(true);

    tex[2] = TaskQueueUtil.getTextureState(game);
    tex[2].setTexture(TextureCache.getInstance().getTexture(
        getClass().getClassLoader().getResource("lensFlare/flare3.png"), game).getTexture());
    tex[2].setEnabled(true);

    tex[3] = TaskQueueUtil.getTextureState(game);
    tex[3].setTexture(TextureCache.getInstance().getTexture(
        getClass().getClassLoader().getResource("lensFlare/flare4.png"), game).getTexture());
    tex[3].setEnabled(true);

    // create the LensFlare object
    flare = LensFlareFactory.createBasicLensFlare("flare", tex);
    flare.setRootNode(rootNode);
    rootNode.attachChild(lightNode);

    // attach the lensflare effect to the lightNode
    lightNode.attachChild(flare);

    if (logger.isInfoEnabled())
      logger.info("lights and lensflare created");
  } // createLights



please help?  :|

Andy

bump This has been unanswered for a while now, and I hate to admit I am completely at a loss on the bump mapping topic.

maybe one of the elders (renanse, Mr. Coder, darkfrog, etc.) can help?  :wink:

I'll try to look into this later today.  It would be very helpful if you could zip up your test case and send it to me by email (see my profile)

d … arn



i whipped up a neat little test case so i could send it to you, and guess what, it works in the testcase. so the problem has to lie somwhere within the code that i got rid of for the testcase. i guess i'll have to run a major DIFF  :wink:



i'll post the problem as soon as i found the villain.



regards,

Andy

heh, ok, hopefully it turns out to be something simple. :slight_smile:

well, after checking the changes:



i changed from:



    MaterialState ms = TaskQueueUtil.getMaterialState(game);

    ms.setColorMaterial(MaterialState.CM_DIFFUSE); // <----

    earth.setRenderState(ms);

to:



    MaterialState ms = TaskQueueUtil.getMaterialState(game);

    earth.setRenderState(ms);



thats was it! :slight_smile:



regards,

Andy