-
Notifications
You must be signed in to change notification settings - Fork 179
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
UPBGE: Implement new Lamp Falloff #768
Conversation
- Inverse Square Cutoff for Lamps. Describes here: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ Code by @DCubix For feature request #728
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch seems coherent with the @adriansnetlis's report, even with the adding of a cutoff.
float d = max(dist - radius, 0.0); | ||
float denom = d / radius + 1.0; | ||
float att = 1.0 / (denom * denom); | ||
att = (att - cutoff) / (1.0 - cutoff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cutoff
is from 0 to 1 in the UI definition:
RNA_def_property_range(prop, 0.0f, 1.0f);
And here it could cause 0 division. You could limit it to 0.99.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just to check other shaders functions and the indeterminations are handle inside the shader instead of clamping the property range.
Perhaps we can optimize the lamp_falloff_invsquarecutoff function as follow:
void lamp_falloff_invsquarecutoff(float radius, float dist, float cutoff, out float visifac)
{
if (cutoff == 1.0 || radius == 0.0) {
visifac = 0.0;
}
else {
float d = max(dist - radius, 0.0);
if (d == 0.0) {
visifac = 1.0;
}
else {
float denom = d / radius + 1.0;
float att = 1.0 / (denom * denom);
att = (att - cutoff) / (1.0 - cutoff);
att = max(att, 0.0);
visifac = att;
}
}
}
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there's an interest for the user to set a cutoff to 1 or a zero radius ?
I agree for the second check level, you can even remove the max a check d <= 0.0.
Also about the UI, you can define a new RNA attribute named radius that is the same as distance attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changes done
@adriansnetlis I invited you so that you could do a review on this patch if you please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it looks like all has been implemented properly and the falloff is working.
When using Inverse Square Cutoff
the Distance
parameter in the user interface should say Radius
instead for better clarification.
A comparsion between Cycles pathtrace and the falloff in game engine tells it's working well.
UPBGE:
Cycles:
- Set good radius and cutoff default values - Avoid indeterminations clamping RNA values - optimize cutoff glsl function Additionally, I fixed Inverse Coefficients values that were default to zero before.
@@ -310,5 +311,13 @@ void BLO_update_defaults_startup_blend(Main *bmain) | |||
br->flag |= BRUSH_ACCUMULATE; | |||
} | |||
} | |||
|
|||
for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I moved this compatibility part in versioning_upbge.c and add the same initialization in BKE lamp constructor (certainly BKE_lamp_new).
Also why are coeff_*
changed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Done.
I changed the coeff_* as they didn't have init values (setted to 0.0) but i will do in an independent commit.
- lamp preview implemented - Fix defaults and init values.
https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
Code by @DCubix
For feature request #728