Lighting on TriMesh and Obj 3d model

Hello,



I’am new to the JME engine. So iam trying to figure stuff out.

Currently i have come to a point where i can’t find the awnser to :?.





The situation is:

I turn on the lights.

Load a skybox with textures.

Add the rotating cube to the scene.

Then add the (famous) maggie model (obj) to the scene.





my problem i cannot solve is:

The cube turns gray -> when lighting is false it has its color.

Maggie has all weird grey-isch(??) triangles.

Textures on the skybox look awfull. texture format is: 512x512 gradient tga (made in photoshop)





an image of the result:







my code:

lighting:

The Maggie issue is a problem with the OBJ importer, probably winding.  Someone should look at that…  Not sure who will yet though since I'm not sure any of the devs use OBJ format and nobody else seems to be offering a solution here.



The grey cube deal is normal.  If you want vertex coloring AND lighting, you must use a MaterialState with ColorMaterial set to something like CM_DIFFUSE.



The skybox textures probably look bad to you due to them being S3TC compressed.  You can specify not to use compression when you load the textures with the TextureManager using the imageFormat argument and the Image.GUESS_FORMAT_NO_S3TC constant or by setting TextureManager's COMPRESS_BY_DEFAULT field to false.

Thank you for the reply.


  • Textures are exacly the way i like them now.
  • Changed from obj to 3Ds seems good also.



    But for the grey looked cube it seems to stay grey. I added a material state but can't figure it to work.

    The cube current code is :




You are almost there.  Instead of using ms.setDiffuse(xxx) use ms.setColorMaterial(MaterialState.CM_DIFFUSE);  You might also remove the setAmbient(xxx) and instead of CM_DIFFUSE, use CM_AMBIENT_AND_DIFFUSE.

ahh yes that works.



Thank you very much.



I have a small problem,

light problem too.


I'm using a LensFlare.

It has a great look! (GG for the one who did it)


*we can see it's written in french, because i'm french*


but the flare isn't visible from everywhere.




I tried changing the CullMode of other objects and other stuff.

I think i just forget something, but what?

(i'm using a BasicGame)



   protected void initGame() {
      
      
      
        optimizer();       
       
        initLighting();
      
           
               
         terrain = TerrainManager.getTerrainBlock(TerrainManager.TERRAIN_DEPART);
         ciel = new Ciel("ciel",10,10,10);
            
         limite = new LimiteTerrain("limite");
         limite.setLocalScale(5);
          limite.setLocalTranslation(new Vector3f(25, terrain.getHeight(25,25) + 15, 25));
             
         /////////////////////////////////////////////////////////////
         
         
         
         
          ENV.JOUEUR = new Joueur("Player Node",properties.getRenderer(),ENV.CAMERA);
          ENV.JOUEUR.setLocalTranslation(new Vector3f(100,0, 100));
         
          scene_node.attachChild(terrain);
          scene_node.attachChild(ciel);
          scene_node.attachChild(limite);
          scene_node.attachChild(ENV.JOUEUR);
         //scene_node.attachChild(ModelLoader.loadModel(ModelLoader.D_arbre1, "arbre1"));
       
          
      //////////////////////////////////

      desktop_node.attachChild(ENV.DESKTOP);
      desktop_node.setCullMode(Spatial.CULL_NEVER);
      
      
       //////////////////////////////////
      main_node.attachChild(lightNode);
      //main_node.attachChild(scene_node);
      main_node.attachChild(desktop_node);
      main_node.attachChild(mouse_node);
      
      lightNode.attachChild(flare);
      
      main_node.updateGeometricState(0.0f, true);
      main_node.updateRenderState();   
      
      }





private void initLighting() {
            
      PointLight dr = new PointLight();
       dr.setEnabled(true);
       dr.setDiffuse(ColorRGBA.white);
       dr.setAmbient(ColorRGBA.gray);
       dr.setLocation(new Vector3f(0f, 0f, 0f));
       ENV.DISPLAY_LIGHTSTATE.setTwoSidedLighting(true);

       lightNode = new LightNode("light", ENV.DISPLAY_LIGHTSTATE);
       lightNode.setLight(dr);

       Vector3f min2 = new Vector3f( -0.5f, -0.5f, -0.5f);
       Vector3f max2 = new Vector3f(0.5f, 0.5f, 0.5f);
      
       lightNode.setTarget(main_node);
       lightNode.setLocalTranslation(new Vector3f( 100f, 200f, 100f));
      
      
    
         // Setup the lensflare textures.
         TextureState[] tex = new TextureState[4];
         tex[0] = display.getRenderer().createTextureState();
         tex[0].setTexture(
               TextureManager.loadTexture(
               LensFlare.class.getClassLoader().getResource(
               "jmetest/data/texture/flare1.png"),
               Texture.MM_LINEAR_LINEAR,
               Texture.FM_LINEAR,
               Image.RGBA8888,
               1.0f,
               true));
         tex[0].setEnabled(true);
         tex[0].apply();

         tex[1] = display.getRenderer().createTextureState();
         tex[1].setTexture(
               TextureManager.loadTexture(
               LensFlare.class.getClassLoader().getResource(
               "jmetest/data/texture/flare2.png"),
               Texture.MM_LINEAR_LINEAR,
               Texture.FM_LINEAR));
         tex[1].setEnabled(true);
         tex[1].apply();

         tex[2] = display.getRenderer().createTextureState();
         tex[2].setTexture(
               TextureManager.loadTexture(
               LensFlare.class.getClassLoader().getResource(
               "jmetest/data/texture/flare3.png"),
               Texture.MM_LINEAR_LINEAR,
               Texture.FM_LINEAR));
         tex[2].setEnabled(true);
         tex[2].apply();

         tex[3] = display.getRenderer().createTextureState();
         tex[3].setTexture(
               TextureManager.loadTexture(
               LensFlare.class.getClassLoader().getResource(
               "jmetest/data/texture/flare4.png"),
               Texture.MM_LINEAR_LINEAR,
               Texture.FM_LINEAR));
         tex[3].setEnabled(true);
         tex[3].apply();

       flare = LensFlareFactory.createBasicLensFlare("flare", tex);
      
       flare.setLocalTranslation(new Vector3f(-1f,-1f,-1f));
       flare.setRootNode(main_node);
     
      
      }





private void optimizer(){
      
      //Create a ZBuffer to display pixels closest to the camera above farther ones. 
          ZBufferState buf = ENV.DISPLAY_RENDERER.createZBufferState();
          buf.setEnabled(true);
          buf.setFunction(ZBufferState.CF_LEQUAL);
       main_node.setRenderState(buf);
      
       // Time for a little optimization. We don't need to render back face triangles, so lets
        //not. This will give us a performance boost for very little effort.
           CullState cs = ENV.DISPLAY_RENDERER.createCullState();
           cs.setCullMode(CullState.CS_BACK);
        main_node.setRenderState(cs);
       
      }

Thanks about the lensflare. 



You might try putting a small box at the same coordinates as the root of your lensflare to ensure you really should be seeing a flare like you think.


I added the box,

And I see it when i don't see the lensflair.


I would like to have a look in the source but i don't understand
how lights work, with the lightstate and other stuff.

Can someone explain me or a good doc (different from the tutorial)

Hmm, try removing the flare.setRootNode(main_node); line in your code and see if it now shows up properly + when it is behind objects.  Since LensFlare works at a bounding volume level to cull out occluded flares, it may be that it feels it is behind something.  I doubt angle of camera itself has anything to do with it and it works properly in the TestLensFlare demo.


Correct,

I changed the rootnode,

works better, but visible everywhere.