Page MenuHome

Full Inverse-Quadratic-Equation Lamp Falloff
ClosedPublic

Authored by Jack Andersen (jackoalan) on Mar 21 2015, 9:48 PM.

Details

Summary

This patch adds a new falloff_type ('Inverse Coefficients') for Lamps in Blender-Internal and GLSL.

The current falloff modes use a formula like this inverse-square one:

I = E × (D^2 / (D^2 + Q × r^2))

While such a formula is simple for 3D-artists to use, it's algebraically cumbersome to work with. Game-designers authoring their own shaders could benefit much more by having direct control of falloff-coefficients:

I = E × (1.0 / (coefC + coefL × r + coefQ × r^2))

In this mode, the distance parameter is unused (except for 'Sphere' mode); instead relying on the designer to mathematically-model the falloff-behavior.

The UI has been patched like so:

Diff Detail

Repository
rB Blender

Event Timeline

Jack Andersen (jackoalan) retitled this revision from to Full Inverse-Quadratic-Equation Lamp Falloff.
Jack Andersen (jackoalan) updated this object.
Jack Andersen (jackoalan) set the repository for this revision to rB Blender.
Jack Andersen (jackoalan) updated this object.

Hi Jack, additional methods can always be useful in *some* cases, but I'm not sure if this really helps much to add more falloff types.

Are there examples elsewhere of this falloff being used to get some advantage? (other rendering engines for eg.)

@Antony Riakiotakis (psy-fi), is working on updates to the viewport and OpenGL rendering.
maybe he has some useful feedback here too.

Absolutely!!

As a matter of fact, COLLADA natively uses inverse-quadratic-coefficients to represent Lamp falloff in its schema:
https://www.khronos.org/files/collada_reference_card_1_4.pdf
(see page4, "Lighting Elements")

Such a data-model would avoid having to make assumptions about the falloff model when importing COLLADA scenes.. (see source/blender/collada/DocumentImporter.cpp:1222)

Furthermore, GLSL tutorials like the ones on lighthouse3d.com commonly use this formula to implement falloff in sample shaders. The big issue I have with the present inverse falloff modes is that they tie your hands.. I manually tried to write a proof converting the blender formula to the full-quadratic-equation.. can't be done.

Jack Andersen (jackoalan) set the repository for this revision to rB Blender.

Updated patch for changes made to key property enums

It's been months since anyone has responded to this ticket, is there anything that needs to be taken care of for this to be merged?
This is an extremely useful feature for complex light configuration, and is an extremely common algorithm used by most engines, and as Jack rightfully pointed out, it's even part of the COLLADA standard and would greatly reduce the number of assumptions required to convert from inverse-quadratic-coefficients thus simplifying the code required.

If there is some hangup preventing this from being merged Jack and I are fully willing to work to resolve them.

Anybody? Some input about what's required to get this patch accepted is all we're asking for.

source/blender/blenkernel/intern/lamp.c
84

Can you use coeff_lin, coeff_const and coeff_quad instead? Much less cryptic to read.

source/blender/gpu/GPU_material.h
157

Better naming please

Update enums and field names to be functionally clearer

This revision is now accepted and ready to land.Mar 12 2016, 10:02 PM
Jack Andersen (jackoalan) edited edge metadata.

Corrected enum assignment from last patch, minor indentation fix

Excellent! Thanks for the acceptance!

Be sure to diff 6248 though.. Just caught an enum fail in the first one from today

Can you rebase this against master? I'm getting some errors here

Complete rebase / conflict resolve to current master

Much thanks for working with us to get this resolved psy-fi :D

Many thanks for finding this useful! I'm sure others in the game-dev community will find it handy.

Now, off to update some Python scripts

This revision was automatically updated to reflect the committed changes.

Committed in 861616bf693b78b070ada6cbc6aa79eb807fdde8 thanks for the patch