Fix light intensity and attenuation import from GLTF
This commit is contained in:
parent
5f386fecf0
commit
aa7ab96e71
1 changed files with 4 additions and 9 deletions
|
@ -5176,19 +5176,16 @@ Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
const float range = CLAMP(l->range, 0, 4096);
|
const float range = CLAMP(l->range, 0, 4096);
|
||||||
// Doubling the range will double the effective brightness, so we need double attenuation (half brightness).
|
|
||||||
// We want to have double intensity give double brightness, so we need half the attenuation.
|
|
||||||
const float attenuation = range / (intensity * 2048);
|
|
||||||
if (l->light_type == "point") {
|
if (l->light_type == "point") {
|
||||||
OmniLight3D *light = memnew(OmniLight3D);
|
OmniLight3D *light = memnew(OmniLight3D);
|
||||||
light->set_param(OmniLight3D::PARAM_ATTENUATION, attenuation);
|
light->set_param(OmniLight3D::PARAM_ENERGY, intensity);
|
||||||
light->set_param(OmniLight3D::PARAM_RANGE, range);
|
light->set_param(OmniLight3D::PARAM_RANGE, range);
|
||||||
light->set_color(l->color);
|
light->set_color(l->color);
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
if (l->light_type == "spot") {
|
if (l->light_type == "spot") {
|
||||||
SpotLight3D *light = memnew(SpotLight3D);
|
SpotLight3D *light = memnew(SpotLight3D);
|
||||||
light->set_param(SpotLight3D::PARAM_ATTENUATION, attenuation);
|
light->set_param(SpotLight3D::PARAM_ENERGY, intensity);
|
||||||
light->set_param(SpotLight3D::PARAM_RANGE, range);
|
light->set_param(SpotLight3D::PARAM_RANGE, range);
|
||||||
light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad2deg(l->outer_cone_angle));
|
light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad2deg(l->outer_cone_angle));
|
||||||
light->set_color(l->color);
|
light->set_color(l->color);
|
||||||
|
@ -5253,14 +5250,12 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig
|
||||||
l->light_type = "point";
|
l->light_type = "point";
|
||||||
OmniLight3D *light = cast_to<OmniLight3D>(p_light);
|
OmniLight3D *light = cast_to<OmniLight3D>(p_light);
|
||||||
l->range = light->get_param(OmniLight3D::PARAM_RANGE);
|
l->range = light->get_param(OmniLight3D::PARAM_RANGE);
|
||||||
float attenuation = p_light->get_param(OmniLight3D::PARAM_ATTENUATION);
|
l->intensity = light->get_param(OmniLight3D::PARAM_ENERGY);
|
||||||
l->intensity = l->range / (attenuation * 2048);
|
|
||||||
} else if (cast_to<SpotLight3D>(p_light)) {
|
} else if (cast_to<SpotLight3D>(p_light)) {
|
||||||
l->light_type = "spot";
|
l->light_type = "spot";
|
||||||
SpotLight3D *light = cast_to<SpotLight3D>(p_light);
|
SpotLight3D *light = cast_to<SpotLight3D>(p_light);
|
||||||
l->range = light->get_param(SpotLight3D::PARAM_RANGE);
|
l->range = light->get_param(SpotLight3D::PARAM_RANGE);
|
||||||
float attenuation = light->get_param(SpotLight3D::PARAM_ATTENUATION);
|
l->intensity = light->get_param(SpotLight3D::PARAM_ENERGY);
|
||||||
l->intensity = l->range / (attenuation * 2048);
|
|
||||||
l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE));
|
l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE));
|
||||||
|
|
||||||
// This equation is the inverse of the import equation (which has a desmos link).
|
// This equation is the inverse of the import equation (which has a desmos link).
|
||||||
|
|
Loading…
Reference in a new issue