Skip to content
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

Add a way to use a mathematically defined PointLight2D texture #3444

Closed
nabfrew opened this issue Oct 19, 2021 · 6 comments
Closed

Add a way to use a mathematically defined PointLight2D texture #3444

nabfrew opened this issue Oct 19, 2021 · 6 comments

Comments

@nabfrew
Copy link

nabfrew commented Oct 19, 2021

Describe the project you are working on

A 2D drag and drop building game.

Describe the problem or limitation you are having in your project

I find it a bit clunky tweaking the light shape, switching back and forth between editing and re-importing importing images.

If the image textures cover a large area, they can be cumbersome as they get in the way of re-arranging other sprites as well.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Being able to define a light with an image offers a lot of flexibility, but there are usually simple radial shapes you want for lights that can easily be mathematically defined and tweaked with a couple of parameters. This way the effect can be seen in real-time in the editor as you adjust the parameters.

I would like to instead of adding a texture, select a predefined mathematical function and tweak it's parameters. I'm focused here on PointLight2D as I work in 2D, I don't know how lights work in 3D or weather this is applicable there as well.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Hopefully it can be accomplished with the same PointLight2D node, and selecting, say 'Gaussian' instead of Texture from the drop-down menu.

Some useful presets might be:

  • An inverse square drop-off in intensity. This would need an inner saturation radius as a parameter, and some scaling factor to adjust the sharpness of the drop-off.
  • A radial Gaussian drop-off in intensity, with a parameter to adjust the sharpness of the drop-off.
  • No drop-off. Same intensity all the way to the edge of the screen.
  • A plateau with a cut-off at fixed radius. A parameter could define how sharp the cut-off is.

For each of these, the following could apply:

  • The peak intensity could be normalised to 1, and scaled by the light energy property.
  • A parameter limiting the light to within a certain angle might be useful as well (like a lampshade effect). An additional parameter could define if the angle cut-off is sharp or diffuse.

If this enhancement will not be used often, can it be worked around with a few lines of script?

These shapes can be created easily enough with image textures. But with a slower workflow, relying on other image editing software, and doesn't allow real-time feedback on the effect of changes.

Is there a reason why this should be core and not an add-on in the asset library?

I'm not sure. I suppose a node type could be created that generates the textures from the parameters on the fly? The large textures would still get in the way in the editor, and I suspect it could be done more efficiently in core, but I'm no expert. In any case, I think a lot of people would enjoy having this out of the box.

@AaronRecord
Copy link

Would godotengine/godot#53234 work (using radial gradients)?

@nabfrew
Copy link
Author

nabfrew commented Oct 19, 2021

To a large extent, yes. It looks like it would make PointLight2D a lot easier to work with.

@Calinou
Copy link
Member

Calinou commented Oct 19, 2021

See also #723 (which is only for 3D).

@Calinou Calinou changed the title Mathematically defined point lights. Add a way to use a mathematically defined PointLight2D texture Oct 19, 2021
@Xrayez
Copy link
Contributor

Xrayez commented Oct 19, 2021

Goost has LightTexture class which allows to generate radial gradient textures by default (which extends godotengine/godot#53234, also available in Goost).

image

@djrain
Copy link

djrain commented Oct 21, 2021

A while ago I was working on a plugin for exactly this kind of thing. The idea was to replicate Unity's Point and Freeform lights. I did make some decent progress on both of those.

Screen.Recording.2020-11-20.at.6.54.14.PM.mov

This shader solution worked great for sprites, but for Light2D you have to use an extra viewport which is rather cumbersome especially since they are/were buggy. So I never really got it quite fleshed out.

I also experimented with a core "PointLightTexture" which did the same thing in C++. This could be super handy for generating static textures in editor, but animating these kinds of textures on the CPU is very slow. It can be fast enough for small pixel art at least. Perhaps a more elegant shader solution could be implemented in core somehow.

@Calinou
Copy link
Member

Calinou commented Mar 24, 2022

This is now implemented by GradientTexture2D (which supports linear and radial gradients), closing. GradientTexture2D will be available in 4.0 and 3.5.

@Calinou Calinou closed this as completed Mar 24, 2022
@Calinou Calinou added this to the 3.x milestone Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants