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

Spherical Area Light Fall-Off Attenuation #728

Closed
adriansnetlis opened this issue Jul 2, 2018 · 3 comments
Closed

Spherical Area Light Fall-Off Attenuation #728

adriansnetlis opened this issue Jul 2, 2018 · 3 comments

Comments

@adriansnetlis
Copy link

adriansnetlis commented Jul 2, 2018

So currently this is how inverse squared calculation looks:
attenuation = 1.0 / pow(distance / the_distance_number_in_light_settings, 2); (it may look a bit different, but that's the math.
However, this does not provide the best results possible. Real lights have radius.
Sourcing for this(https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/), you can calculate spherical area light attenuation by this calculation:
attenuation = 1.0 / pow(distance / radius + 1.0, 2);
If one wanted to keep the distance setting, radius can be multiplied by the distance number in light settings.
This is not very costly calculation by itself, however, the source provides even additional optimizations for deferred rendering.

Now adding "radius" option in light settings and switching to this equation could provide pretty nice results.

@panzergame
Copy link
Contributor

Thanks for the detailed report, I leave it to new developer to get experience:
The fragment shader source/blender/gpu/shaders/gpu_shader_material.glslneed to be modified by adding a new attenuation function and a check added in gpu_material.c to select it.

@lordloki
Copy link
Member

This was already implemented by @DCubix in the ge_brdf branch (eb97104#diff-cd270f0456f47fde6ee278bee899bdb7R1810). Maybe we can commit it to master.
I will test it.

lordloki added a commit that referenced this issue Jul 29, 2018
- Inverse Square Cutoff for Lamps. Describes here:
https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/

Code by @DCubix

For feature request #728
lordloki added a commit that referenced this issue Aug 7, 2018
* UPBGE: Implement new Lamp Falloff

- Inverse Square Cutoff for Lamps. Describes here:
https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/

Original code by @DCubix. Slightly modified by me to add light preview.

New Radius & CutOff parameters exposed in UI when you select "Inverse Square CutOff" falloff type in point and spot lamps

For feature request #728
@lordloki
Copy link
Member

lordloki commented Aug 7, 2018

committed in master. Thanks for testing and proposal

@lordloki lordloki closed this as completed Aug 7, 2018
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

3 participants