TarVK / pixi-shadows

Adds dynamic shadows to PixiJS
https://tarvk.github.io/pixi-shadows/dist/
MIT License
52 stars 13 forks source link

allow for light with crisp edges #15

Closed amir-arad closed 1 year ago

amir-arad commented 2 years ago

for my game's needs I want to be able to have the light's borders very sharp. right now there's a gradient, so even if I turn shadow.intensity to 10, it's not a clear cut circle but has gradient edges.

I would love to be able to PR this myself. I have no knowledge of glsl so i'm guessing that I should add gradientFactor and change the calculation to something like:

if (objectDistance > pointDistance || objectDistance >= lightRange) {
  intensity = 1.0 - (distance / lightRange) * gradientFactor;

WDYT?

TarVK commented 2 years ago

Yes when I looked back at the code, I was very surprised to see that the light falloff is baked in. I can have a look at this in the near future, since it should be very easy to create some parameter for this. I don't know about the details from the top of my head though.

TarVK commented 1 year ago

I created a PR for a simple implementation: https://github.com/TarVK/pixi-shadows/pull/16 What do you think?

Preferably we would allow the user to also choose for different fall-off types. Using cubic light fall-off with different constants for each of the terms is relatively common I think. This would be a easy solution, where the user can provide the 3 factors, then the range can be figured out from these factors, or we leave it to the user to match them properly. Alternatively we could allow users to provide custom GLSL code to have fine control over the fall-off.

As a side note: I have to admit this existing code really is a mess. It contains a lot of strange cases, and I don't even remember what they are for myself. I think I just kept on adding arbitrary "nice to have" things, without thinking them through. Realistically I don't think I will invest any considerable amount of time into this project in the near future, as I have different projects with higher priority, but I'm somewhat considering whether to redo this project from scratch.

amir-arad commented 1 year ago

the PR looks great for my case.

As a side note: I have to admit this existing code really is a mess. It contains a lot of strange cases, and I don't even remember what they are for myself. I think I just kept on adding arbitrary "nice to have" things, without thinking them through. Realistically I don't think I will invest any considerable amount of time into this project in the near future, as I have different projects with higher priority, but I'm somewhat considering whether to redo this project from scratch.

That would be a pity I think. I found this project because I am looking for a field-of-view for top-down radar system with obstructions and this is by far the closest and most elegant I found (my use case will require more features that probably bring no value to light/shadow simulation). I see how some parts here are cumbersome but It's worth maintaining IMO. just a matter of understanding the use case(s) and focusing.

Thank you for the plugin and the support in adapting to pixi6 anyways, I didn't know anything about pixi filters or glsl and I've enjoyed learning it through your code.

TarVK commented 1 year ago

I will definitely keep this online, and if anyone feels like improving it (like you did) I will definitely help integrate that. What I meant was that really this project could start with a clean code base and a rework entirely. After that, it would probably be released under the same name, but a different major version number. However, such a redesign is something I have no time for at this moment. But I indeed think the project can still be useful for some people as it is :)

amir-arad commented 1 year ago

@TarVK Thank you for this project.

I learned a lot from it. eventually I ended up computing the field of view outside of pixi anyways, because I needed the logic part to know what is in the FOV and what is not.

TarVK commented 1 year ago

Sounds like that makes a lot of sense for your application. I'm sorry you couldn't use this plugin in the end, but thanks a lot for your contributions!