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

Change the light attenuation formulas. #44941

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

reduz
Copy link
Member

@reduz reduz commented Jan 5, 2021

-Much better looking, physically based.
-Almost negligible extra cost.

Pictures (Old Left, New Right):

image
image
image

Videos:

Old:

old_attenuation.mp4

New:

new_attenuation.mp4

@fire
Copy link
Member

fire commented Jan 5, 2021

Is it possible if you also changed the formulas in the gltf document for importing and exporting lights at the same time.

Light3D *GLTFDocument::_generate_light(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index) {

GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_light) {

See original test cases from gltf assets in #39450

Edited: Had the wrong link for exporting lights.

@akien-mga
Copy link
Member

There are similar looking equations in other places, are they meant to change too?

(Non exhaustive list, I just looked for spot_attenuation and for some pow(1.0 - x) equations.)

modules/lightmapper_rd/lm_compute.glsl
322:                            attenuation *= pow(1.0 - d, lights.data[i].spot_attenuation);
servers/rendering/renderer_rd/shaders/giprobe_write.glsl
155:                    attenuation *= pow(1.0 - d, lights.data[light].spot_attenuation);
servers/rendering/renderer_rd/shaders/sdfgi_direct_light.glsl
211:                                    attenuation *= pow(1.0 - d, lights.data[i].spot_attenuation);
servers/rendering/renderer_rd/shaders/scene_forward.glsl
1222:   spot_attenuation *= 1.0 - pow(spot_rim, spot_att_angle.x);
servers/rendering/renderer_rd/shaders/volumetric_fog.glsl
280:                    float attenuation = pow(max(1.0 - d, 0.0), attenuation_energy.x);
336:                    float attenuation = pow(max(1.0 - d, 0.0), attenuation_energy.x);

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks good to me. Subject to Akien's comment above. It looks like you accidentally removed a line.

@reduz
Copy link
Member Author

reduz commented Jan 5, 2021

There are similar looking equations in other places, are they meant to change too?

No, spot attenuation is ok, this will never be physically very correct anyway, we need to invert it though. @JFonS was planning to work on this, we can do it a separate PR, and this can be a good guide of all the places that need to be touched (though probably in this case, it needs to be inverted on the CPP)

@clayjohn
Copy link
Member

clayjohn commented Jan 5, 2021

@reduz the volumetric fog attenuation should change though.

@JFonS
Copy link
Contributor

JFonS commented Jan 5, 2021

Yup, I already found a way to properly invert the angle attenuation. I will also make sure this attenuation is consistent across LM/SDFGI/GIProbe etc. because currently there are some discrepancies.

-Much better looking, physically based.
-Almost negligible extra cost.
@reduz reduz force-pushed the new-light-attenuation branch from 1090abe to 446618c Compare January 5, 2021 17:45
@reduz
Copy link
Member Author

reduz commented Jan 5, 2021

@clayjohn ok, added the missing fog one. Should probably be good to merge once CI passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants