-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to set the length of shadows #40
Comments
Hi there, thank you for your idea/question. It's looks like an interesting feature but currently I don't see how it could be implemented, the reason is - for such tall dependent shadow effect the light should be able to acquire from each fixture it's "tall" and currently I don't see where it could be stored, except the user data, which often is used for the different purposes. Still before any final answer I'll need to check if the ray-casting could handle such cases at all, cause I'm not 100% sure regarding the current implementation. |
Ohh yes, that indeed sounds like an issue. But is there no attribute within box2d fixtures or bodies (beside the user data), which we could use to store that "height" additional value? |
I was thinking about that. How about optionally using the user data to store the "tall" value of the object, if you want shadows with different length. In that case you can't use the user data for something else, but since it's optionally you can choose not to use it as well... |
I also was thinking about that, however it will be a rare case, in most of engines the userData is often used to connect physics body with other engine elements (like graphical objects). But I will try to see what we can do. |
Thank you very much for your efforts! |
Hi @haimat, I have a question - as I understand the "tall" is not enough, we will need a lights "height" position also? Or in your idea of implementation all lights are on the same height? Also, it's quite hard for me, as I'm not expert, but seems I was able to find some way to do it: This is draft implementation of shadows for Directional lights. Will try other light too, but it will be even harder :) Need to find a way to handle ray collision overlapping, e.g. if the light is blocked by fixture, but the fixture next to it is far enough to drop the shadow from this light also... it's a pain my head :) sorry for my english, btw. |
Wow, that looks already awesome -- great work! Now if you could manage to get that working for point lights too, I would be super happy :-) To your question: Of course you are right, to be more realistic we would need not only the height of the fixture ("tall"), but also the height of the light source. This would be nice, but having only one value to control the length of the shadow would be better then what we have now. So in other words: having both, "object height" (tall) and "light height" would be great, but having only "object height" (one valiue) would also be fine! |
Experimental feature (libgdx#40) Only PolygonShapes currently drop dynamic shadow
Hi @haimat, Just interesting, is it possible for you to link not the pre-build jar library but add the box2dlight source project as dependency? |
You mean for testing your changes? |
That would be great! You can use my fork, its could be found by referenced commit above. Current implementation looks good on screenshots, but isn't optimised and I feel its buggy. To use limited height lights you need do 3 things:
And currently it works only for PolygonShape fixtures, tell me what other Shape types you are using to prioritise the implementation for real testing :-) |
So, I did what you suggested, using your fork and enabling the new pseudo-3d feature. It does work partially: when the fixture is within the point light range, then it seems to work fine. However, when I move the light away from the fixture, then the shadow becomes bright, like light. Hard to explain, so have a look at these screenshots. |
Oh... could you please share your sample box2dlights setup configuration in your project and sample height values for this issue? |
|
Seems I've messed up some blending and we had different ambient light set. On my (0f, 0f, 0f, 0.5f) this wasn't visible - both blendings gave the same good result. I've pushed the possible fix, give it a try when you have chance! And also, thanks for your time :) |
Working on libgdx#40
I've tried to do more testing this time :) you can sync with new version and look at it again. |
Working on libgdx#40
+ minor re-factoring for libgdx#40
Ohh... I've added the userData field to LightData - it solves one general limitation:
So you still could use custom data even with pseudo-3d mode enabled, just adds a bit more pain in getting it later :) Don't know why I haven't thought about it earlier. |
+minor re-factoring for libgdx#40
I've updated code, should fix this issue. Btw, non-convex polygons still are not supported correctly, but should work fine with convex shapes. |
Thank you very much. It's already looking awesome! There are two things I noticed though:
For the 2nd point I also think the the inside of the poygon should be in shadow if the polygon fixture height is > then the light source height. What do you think about that? |
I will check the inside case later. For now I've fixed some shadow length computation, and it will be great if you will try following mode: rayHandler.setPseudo3dLight(true, true); The second param if true - enables some shadow color interpolation, which looks a bit different - but I don't know which is better :) Regarding to shadowing the polygon in case of light height < then fixture height sounds reasonably. I will check it also. |
I have tried the new parameter to interpolate the shadows. |
Hi @haimat, I've found that current implementation is a bit awful :) it doesn't work for colored lights as usual box2dlight do. I need to re-implement the core, and also due to memory and performance optimization I'm going to move all the code related to this feature to a separate sub-package. The following development will continue on the libgdx "pseudo3d" branch and I will talk with libgdx team if its possible to move box2dlights nightlies build to this branch also so that you could easily update and test it during development via Gradle and smoothly move onto it when it will be merged to master branch. Also after the first commit to the "pseudo3d" branch it will be better to create issues/enhancements in a separate threads. P.S. This will take some time, but hope soon you will be able to use it again and it will be event better :) |
Thank you very much for your feedback. So will you answer here in this thread when you have a new version ready for testing, or somewhere else? |
Yes, I will notify you in this thread :) |
Hi, have there been further updates regarding the pseudo 3d lights? |
I'm quite a busy currently on my job, having a few free time. Even now at holiday I'm writing this from work :) you can check it's current status at box2dlights "pseudo3d" branch, unfortunately there is no built jar could be provided currently, but you can still try it from sources. |
This should be in Libgdx official release good job guys! |
Any plan of a pull request to join it to the master branch? :D |
It might be, but currently the pseudo3d branch is "28 commits behind master" which sounds a bit frightening for the merge :) This will take much work... |
Oohh... this can be sooo great if integrated in the master branch >_< |
That looks so promising and interesting feature. Any hope to see it merged with master someday? |
Hi, i'm quite new to github and box 2d lights. How can i implement your code with existing box 2d light library? I took the code from https://github.com/rinold/box2dlights, but i didn't see pointlight.setHeight or pseudo3d. Any help is appreciated. |
It's on the 'pseudo3d' branch at the moment. |
Thanks. I have few questions related box 2d directional light and shadowing. I'm using a conelight and a directional light with changing alpha to simulate day and night cycles. When i set conelight active, i'm facing flickering light borders. It does'not look so good. Do you have any idea how can it be solved? Another issue is, i set |
You can try to increase the rays number for the lights - it's usually the second argument in co structor (called 'rays') to reduce flickering. Regarding to the pseudo3d lights you should use the box2dlights.p3d.P3dLightManager (pseudo3d ray handler analogue) to handle the P3d lights. Sorry for any inconveniences, but I'm currently writing from phone, having no access to my laptop (hope will get back in a week), thus unfortunatelly can't show code examples now. |
I'm afraid to ask but... I guess this pseudo3d branch is dead? given the number of updates lately... |
Hopeful for this addition to the main branch. This'll really add icing to the cake |
How can I integrate this branch with my Android Studio with LibGDX project? |
Unfortunately, for now the only way is to download it's sources and build jar on your own, or add downloaded project as dependency. |
Hi @rinold, i needed this pseudo3d from a top down persective and i felt so free to take your code, edit it and merge it with the current box2d-lights Version. Good work. I only used the directional light. You can visit the code on my github repo. Maybe it is to specific for my needs but it works in my case. Maybe we can merge this feature into the 1.6 version? If you run the tests (maybe you have to change the resource paths in the Test class) you can see a full sun cyclus when activated the directional light. |
Currently in box2dlights a box2d body either casts a shadow or not, there is no in-between. However, in my application I need to specify the length of the shadow for each object, depending on the objects height (in order to simulate a 3d effect).
For example, if the object that would cast the shadow is tall then the shadow is long. But if the object is small, not as tall as the light source height, then the shadow would be shorter.
Would it be hard to implement such a feature in box2dlights?
The text was updated successfully, but these errors were encountered: