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

UPBGE: Implement new Lamp Falloff #768

Merged
merged 7 commits into from
Aug 7, 2018
Merged

UPBGE: Implement new Lamp Falloff #768

merged 7 commits into from
Aug 7, 2018

Conversation

lordloki
Copy link
Member

Code by @DCubix

For feature request #728

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

Code by @DCubix

For feature request #728
Copy link
Contributor

@panzergame panzergame left a 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);
Copy link
Contributor

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.

Copy link
Member Author

@lordloki lordloki Aug 1, 2018

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?

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changes done

@panzergame
Copy link
Contributor

@adriansnetlis I invited you so that you could do a review on this patch if you please.

Copy link

@adriansnetlis adriansnetlis left a 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:
lamp_falloff_ingame_1
Cycles:
lamp_falloff_pathtrace_1

- 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) {
Copy link
Contributor

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 ?

Copy link
Member Author

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.
@lordloki lordloki merged commit b87fe29 into master Aug 7, 2018
@lordloki lordloki deleted the ge_lamp_falloff branch August 10, 2018 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants