Dark scene with light (29 posts)

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    I am using the following codes, but still, the scene is too dark. I am using Lighting materials for boxes, but not even all surfaces have light on them. I also tried AmbientLight which had the same results. What should I do?

    DirectionalLight sun=new DirectionalLight();
    sun.setDirection(new Vector3f(-0f,-0.1f,0.5f));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);

  • Profile picture of wezrule wezrule201p said 9 months, 2 weeks ago:

    im assuming this is a scene from blender? Try computing the normals again, that should fix the “some surfaces do not have lighting on them”.

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    I am only using Geometry Boxes, no models.

  • Profile picture of tralala tralala24p said 9 months, 2 weeks ago:

    dont use directional light.

    private SpotLight playerLight = new SpotLight();
    
          AmbientLight al = new AmbientLight();
          al.setColor(ColorRGBA.White.mult(1f));
          getRootNode().addLight(al);
          playerLight.setSpotRange(40);
          playerLight.setSpotInnerAngle(10 * FastMath.DEG_TO_RAD);
          playerLight.setSpotOuterAngle(15 * FastMath.DEG_TO_RAD);
          playerLight.setPosition(getCam().getLocation());
          playerLight.setDirection(getCam().getDirection());
          playerLight.setColor(ColorRGBA.White.mult(1.5f));
          getRootNode().addLight(playerLight);
    
    @Override
          public void simpleUpdate(float tpf)
          {
             playerLight.setPosition(player.getPosition());
             Vector3f direction = player.getForward().subtractLocal(player.getPosition());
             playerLight.setDirection(direction);
          }
    
  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    Thanks a lot :) I figured out that it doesn’t work with boxes because I tried it with another program where light works well and the box had the same effect. Thanks a lot.

  • Profile picture of pspeed pspeed821p said 9 months, 2 weeks ago:

    memonick said:
    I am using the following codes, but still, the scene is too dark. I am using Lighting materials for boxes, but not even all surfaces have light on them. I also tried AmbientLight which had the same results. What should I do?

    DirectionalLight sun=new DirectionalLight();
    sun.setDirection(new Vector3f(-0f,-0.1f,0.5f));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);

    I think with these settings, only one side of your box (and the top but just barely) are getting sun.

    Have you tried using a directional light and also an ambient light? The directional light will only light surfaces facing the light and the ambient light can be used to round out the lighting on the other faces.

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    @pspeed, I tried, but the same result.

    @tralala, where do I put your code? I can’t seem to figure out where to put private…Spotlight();

  • Profile picture of pspeed pspeed821p said 9 months, 2 weeks ago:

    My understanding is that you are worried that some side of your boxes aren’t lit. SpotLight won’t help with that… and may make it worse.

    Can you show me your ambient light setup? (Though I’ve had trouble getting it to work, too.)

    Edit: actually I just tried an ambient light in my scene and it’s working fine… don’t know what I did wrong before. It should help you if setup properly.

  • Profile picture of pspeed pspeed821p said 9 months, 2 weeks ago:

    Here are some exaggerated settings that should definitely light all sides of your boxes:

            DirectionalLight light = new DirectionalLight();
            light.setDirection( new Vector3f( 1, -1, -2 ).normalize() );
            light.setColor( ColorRGBA.White.mult(2) );
    
            rootNode.addLight( light ); 
    
            AmbientLight amb = new AmbientLight();
            amb.setColor( ColorRGBA.Red );
            rootNode.addLight( amb );
    
  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0f,2f,-2f).normalizeLocal());
    rootNode.addLight(sun);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);

    This does not work right. I really don’t know what to do. What did you do?

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    I just noticed that the materials show with the color of the light. And you suggestion shows only one side.

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:
    package Platform;
    import com.jme3.app.SimpleApplication;
    import com.jme3.bullet.BulletAppState;
    import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
    import com.jme3.bullet.collision.shapes.CollisionShape;
    import com.jme3.bullet.control.CharacterControl;
    import com.jme3.bullet.control.RigidBodyControl;
    import com.jme3.bullet.util.CollisionShapeFactory;
    import com.jme3.input.ChaseCamera;
    import com.jme3.input.KeyInput;
    import com.jme3.input.controls.ActionListener;
    import com.jme3.input.controls.KeyTrigger;
    import com.jme3.light.AmbientLight;
    import com.jme3.light.DirectionalLight;
    import com.jme3.material.Material;
    import com.jme3.math.ColorRGBA;
    import com.jme3.math.FastMath;
    import com.jme3.math.Vector3f;
    import com.jme3.scene.Geometry;
    import com.jme3.scene.shape.Box;
    public class Main extends SimpleApplication
      implements ActionListener {
      private Geometry green;
      private BulletAppState bulletAppState;
      private RigidBodyControl f;
      private CharacterControl player;
      private Vector3f walkDirection = new Vector3f();
      private boolean left = false, right = false, up = false, down = false;
      public static void main(String[] args) {
        Main app = new Main();
        app.start();
      }
      //private SpotLight playerLight = new SpotLight();
      public void simpleInitApp(){
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        flyCam.setEnabled(false);
        setUpKeys();
        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 0f, 1);
        player = new CharacterControl(capsuleShape, 0.05f);
        player.setJumpSpeed(20);
        player.setFallSpeed(30);
        player.setGravity(30);
        player.setPhysicsLocation(new Vector3f(0, 10, 0));
        Box box2 = new Box( new Vector3f(0,0,0), 1,1,1);
        green = new Geometry("Box", box2);
        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setColor("Color", ColorRGBA.Green);
        green.setMaterial(mat2);
        rootNode.attachChild(green);
        bulletAppState.getPhysicsSpace().add(player);
        SimpleLevel l = new SimpleLevel();
        int block;
        block = l.blocknumber;
        for (int i = 1; i < block; i++){
            l.geom[i].setMaterial(assetManager.loadMaterial( "Materials/Ground.j3m"));
            CollisionShape sceneShape2 = CollisionShapeFactory.createMeshShape(l.geom[i]);
            f = new RigidBodyControl(sceneShape2, 0);
            l.geom[i].addControl(f);
            rootNode.attachChild(l.geom[i]);
            bulletAppState.getPhysicsSpace().add(f);
        }
        DirectionalLight light = new DirectionalLight();
        light.setDirection( new Vector3f( 1, 1, -2 ).normalize() );
        light.setColor( ColorRGBA.White.mult(2) );
        rootNode.addLight( light );
        AmbientLight amb = new AmbientLight();
        amb.setColor( ColorRGBA.Red );
        rootNode.addLight( amb );
      }
      private void setUpKeys() {
        inputManager.addMapping("Lefts",  new KeyTrigger(KeyInput.KEY_A));
        inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
        inputManager.addMapping("Jumps",  new KeyTrigger(KeyInput.KEY_SPACE));
        inputManager.addListener(this, "Lefts");
        inputManager.addListener(this, "Rights");
        inputManager.addListener(this, "Jumps");
      }
      public void onAction(String binding, boolean value, float tpf) {
        if (binding.equals("Lefts")) {
          left = value;
        } else if (binding.equals("Rights")) {
          right = value;
        } else if (binding.equals("Jumps")) {
          player.jump();
        }
      }
      @Override
      public void simpleUpdate(float tpf) {
        ChaseCamera bluechase = new ChaseCamera(cam, green);
        bluechase.setDefaultHorizontalRotation(1.5f);
        bluechase.setLookAtOffset(new Vector3f(3, 0, 0));
        bluechase.setChasingSensitivity(0f);
        green.addControl(bluechase);
        green.setLocalTranslation(player.getPhysicsLocation());
        Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
        Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
        walkDirection.set(0, 0, 0);
        if (left)  { walkDirection.addLocal(camLeft); }
        if (right) { walkDirection.addLocal(camLeft.negate()); }
        player.setWalkDirection(walkDirection);
        cam.setLocation(player.getPhysicsLocation());
      }
    }

    This is the whole program, maybe you can see something I can’t.

  • Profile picture of memonick memonick39p said 9 months, 2 weeks ago:

    Tested in another program with the same result.

  • Profile picture of pspeed pspeed821p said 9 months, 2 weeks ago:

    Is this the box that you are trying to ligiht?

        Box box2 = new Box( new Vector3f(0,0,0), 1,1,1);
        green = new Geometry("Box", box2);
        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setColor("Color", ColorRGBA.Green);
        green.setMaterial(mat2);
        rootNode.attachChild(green);
    

    …because it is not using a lighting material.

    I’d expect it to show up solid green.

  • Profile picture of pspeed pspeed821p said 9 months, 2 weeks ago:

    Also note: your light is pointing up and not down:

    light.setDirection( new Vector3f( 1, 1, -2 ).normalize() );