libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
255 stars 82 forks source link

DirectionalLight extension for "top-down" view #68

Open adam-law opened 9 years ago

adam-law commented 9 years ago

Hi,

I either don't understand the concept or it's not possible right now, but I would like to use the effect of a DirectionalLight to be the sun for a world in a top-down view. Additionally, an argument to set its "position" (I understand this is not a positional light) over the scene would be great, to simulate the transit through of a body like the sun over periods of time.

Thanks.

rinold commented 9 years ago

No it's not possible in box2lights now, but you can check the pseudo3d branch - it was specially created for "top-down" 2d world support, but unfortunatelly it's only in development stage, and I have no time to work on it as I wanted to currently...

UPD. It has no downlodable jars, and you will need to build it from source. UPD2. Not shure if it will work with latest libgdx, but this could be fixed.

adam-law commented 9 years ago

ah, was it related to that great piece of work you did with shadow lengths? by the way, I hope it's related, but is there a way then that I can "lighten up" the dimness? When box2dlights is active it seems to set things to "night". I understand this is to contrast with the created lights, but if there is a way to control how dark it is then it may work for as a substitute for a topdown sun. I was thinking it was setAmbientLight(), but regardless of the values I put in, it's still "nighttime".

Edit: I think I may need to open another issue for ambient lighting? I took some time to try out all constructors, in a world without box2d bodies to collide with, and the whole scene is just "dark" / unlit, no matter what the setting is for ambient lighting.

rinold commented 9 years ago

Sorry for a very very late reply... Got much overhead last months :) I've checked the pseudo3d branch and it's currently missing such DirectionalLight implementation.

I'll try to complete it and merge it to pseudo3d branch in a few days.

adam-law commented 9 years ago

that's okay, things like this are worth the wait :)

does the pseudo3d branch conflict with anything from the main box2dlights? if not, why can't they be merged if it will add such nice new features?

rinold commented 9 years ago

I've just added the P3dDirectionalLight to pseudo3d branch. You can set the direction in the same way as in usual box2dlights and you can also use the:

    float degrees = 70f;
    dirLight.setHeight(degrees);

to set the degree of this light from horizont - the 90f means it's absolutely on top of world and shadows should disappear, while moving over the 90f will flip the shadows direction automatically.

UPD. Regarding the merging - I think that will be a bit hard, as they use different algorithms for shadow calculations and rendering...

adam-law commented 9 years ago

I understand, w/o looking at the source, I can only imagine the difficulty. I guess it won't be so much of a problem if the pseudo branch is always in pace with the main project. Thanks for the info, and for implementing this :)

adam-law commented 9 years ago

Something gave me pause in trying out the p3d branch. It was mentioned on issue #40 that p3d doesn't work for colors?

I've found that current implementation is a bit awful :) it doesn't work for colored lights as usual box2dlight do.

rinold commented 9 years ago

It works currently - you can check the video on the branch page. However, it has only point and directional lights currently, and also with high chances there might be some bugs in it :) As it's hanging in development I really not sure about using it in production, but from other side if no one will try to use it, it will be hard to find out what needs to be fixed or emhaced :)

adam-law commented 9 years ago

very nice. I'll give it a shot. Just wondering though, even if nothing new is added, will p3d always be in step with an update to the main box2dlights? I could be wrong, but I see both are at 1.4.0. Lastly I built p3d from the provided pom. I assume this is the correct way? It had really old references in it, so I was wondering if this was an obsolete method. I didn't have Java 6 in the system, so I had to bump stuff up to build successfully under Java 7/8.

thanks.

kdenzel commented 4 years ago

Hello there, i made a fork and updated the code especially the directional lights code and light class. I changed it for my personal needs. Here is my Repo. Pushed it on the master branch. Dunno if that was a good idea to do so. Only used the directional light class for 3D, all the other light classes work the same as Version 1.6-SNAPSHOT at the current time.

crykn commented 4 years ago

Hey @kdenzel, it seems like you changed the line endings in the files you edited. This makes it very difficult to compare the differences between your repo and the master branch. Could you change the line endings on your end? Your IDE should provide some tools for you to make that easier.

kdenzel commented 4 years ago

Oh sorry, i messed up with whitespaces. But there is a little Trick: when you enter the url to compare the files, you can enter in the URL the get Parameter w=1 see here

crykn commented 4 years ago

You never stop learning.

Box2d-lights isn't really my area of expertise, but judging by the comments here and in the other issue those changes in the initial pseudo3d branch seemed to be well appreciated. If you would be willing to create a PR for your changes, maybe another member of the team finds the time to review it.