Material only applies to inside?

Hello everyone!



I have a small problem with light and materials right now. I'm creating a box and assign texture and material to it. The texture is visible from the outside as it should, but the material only seems to be applied to the insde.



I already searched the forum for this and found one answer, that suggested to use a ZBuffer. However, I'm already using that.



Here is the basic code:


public class Demo extends BasicGameState {
   
   InputHandler            input;
   Skybox                  skybox;
   DisplaySystem            display;
   Camera                  cam;
   LightState               sun;
   DirectionalLight         sunlight;
   
   Node                  hero;
   Level                  level;

   public Demo(String name) {
      super(name);
      
      display = DisplaySystem.getDisplaySystem();
      cam = display.getRenderer().getCamera();
      
      // Z-Buffer
      ZBufferState zbuf = display.getRenderer().createZBufferState();
      zbuf.setEnabled(true);
      zbuf.setFunction(ZBufferState.CF_LEQUAL);
      rootNode.setRenderState(zbuf);      
      
      // Skybox (Weltraum)
      skybox = Util.getSkybox("data/skycubes/cosmo1.jpg");
      if(skybox == null) System.exit(0);
       
        rootNode.attachChild(skybox);
       
        // Level
      level = new Level();
      if(!level.load("data/levels/demo/demo-level.xml")) System.exit(0);
      
      rootNode.attachChild(level);
      
      // Globales Licht
      sunlight = level.sunlight;
      sun = display.getRenderer().createLightState();
      sun.setGlobalAmbient(new ColorRGBA(50,50,50,255));
      //sun.setTwoSidedLighting(true);
      sun.attach(sunlight);
      rootNode.setRenderState(sun);         
            
      rootNode.updateRenderState();
      rootNode.updateGeometricState(0, true);
      
      KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
      
      input = new FirstPersonHandler(cam, 15.0f, 0.8f);
      display.getRenderer().enableStatistics(true);
   }
   
   public void update(float tpf) {
      
      if(input != null) input.update(tpf);
      
      skybox.setLocalTranslation(cam.getLocation());
      
      rootNode.updateGeometricState(tpf, true);
      
      if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) System.exit(0);
      
      super.update(tpf);
   }

   public void cleanup() {
      
      super.cleanup();
   }

}



Can anyone give me a hint?

could it be that the normals in your importet model are the wrong way around ?

Thanks for your answer!



I create a "standard" jME box: com.jme.scene.shape.Box



         Box box = new Box(boxName, boxStart, boxEnd);
         
         // Textur festlegen
         if(textures.containsKey(boxTex)) {
            box.setRenderState(textures.get(boxTex));
         }
         
         // Material festlegen
         if(materials.containsKey(boxMat)) {
            box.setRenderState(materials.get(boxMat));
         }
         
         box.setModelBound(new BoundingBox());
         box.updateModelBound();   
         //box.updateRenderState();      
         
         this.attachChild(box);



I suppose from that class the normals are the right way around?

Yes it is. No clue how it got changed in my code, mysterious. Well, my mistake anyway.

Thanks for your help again, everyone.

  1. yourMaterial.setMaterialFace(MaterialState.MF_FRONT_AND_BACK) should do what you need.
  2. Use TextureManager for textures. It has built-in caching, so you probably won't need to maintain your own texture cache.

Thanks a lot! That solved my problem. :slight_smile:

But it is weird that the standard value of materialFace seems to be MF_BACK rather than MF_FRONT.

default should be MF_FRON - see MaterialState.defaultMaterialFace