libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
256 stars 81 forks source link

Directional Light has a top and bottom #61

Open acegiak opened 9 years ago

acegiak commented 9 years ago

When using DirectionalLight in a game with panning camera and wide box2d world DirectionalLight is not vertically infinite. It ends at +50y and -50y

Other lights outside this range continue to act as normal.

amygdalascreenshot1432611006922 amygdalascreenshot1432611298333

rinold commented 9 years ago

As I know the Directional light is limited by screen size dependent values which are set or updated when calling the:

rayHandler.setCombinedMatrix(...);

And there are no other limitations for this light. Could you please share some code regarding the usage of box2dlights and the DirectionalLight?

acegiak commented 9 years ago

Yeah, I had a look through the DirectionalLight class before posting here and saw the way it should be getting the dimensions from the camera but that doesn't appear to be what's happening.

The key box2dlights and DirectionalLight code sections are here:

private void initiateLighting() {
        if (Amygdala.lighting) {
            rayHandler = new RayHandler(world);
            rayHandler.setCombinedMatrix(camera);
            rayHandler.setBlur(true);
            rayHandler.setBlurNum(1);
            rayHandler.setAmbientLight(DEFAULT_LIGHT_LEVEL);

            sun = new DirectionalLight(rayHandler, Gdx.graphics.getWidth()/2, new Color(1f,1f,1f,SUN_INTENSITY), -90f);
            sun.setActive(true);
            sun.setStaticLight(false);
            sun.setContactFilter(Entity.CATEGORY_LIGHT, (short) 0, Entity.MASK_LIGHT);
        }

    }

And here in our screen's render method:

            if(rayHandler == null){
                initiateLighting();
            }
        rayHandler.setCombinedMatrix(camera);

        rayHandler.updateAndRender();
rinold commented 9 years ago

Oh... I've got it. The issue now is if we will move more correctly with camera position, the shadows from offscreen objects will blink if we move up-down. Need to think regarding something like fixed pseudo-position for DirectionalLight...

BTW, is your world limited by Y axis?

acegiak commented 9 years ago

our player can theoretically move infinitely on the Y axis but the platforms are not so we could, for instance, after level generation, supply a max and min Y value to the rayhandler or directionallight outside of which there would not be anything to cast shadows or have shadows cast on it.

One of the things I was trying to work out if I could do myself was pass a rectangle with the level bounds to the directionallight but I don't have a deep enough understanding of the raytracing for that.

mk-5 commented 6 years ago

I have same issue. I solved it by changing Directional Light direction from -90f to -91f - for me that's helped.