Fix T102853: radius of spot and point lamps shares same value with area lamp size
If we change the radius of a point or spot lamp, we also change the area lamp size. As shown in T102853, this is bad for animating the lamp type. The solution is to make the property point to another member of the DNA struct `Light`. Differential Revision: https://developer.blender.org/D16669
This commit is contained in:
parent
20b2d6fc71
commit
fbc2c4c331
Notes:
blender-bot
2023-02-14 10:09:24 +01:00
Referenced by issue #102853, Shape size of the point, spot and area light not behaving correctly when animated in EEVEE and Cycles
|
@ -25,7 +25,7 @@ extern "C" {
|
|||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 6
|
||||
#define BLENDER_FILE_SUBVERSION 7
|
||||
|
||||
/* Minimum Blender version that supports reading file written with the current
|
||||
* version. Older Blender versions will test this and show a warning if the file
|
||||
|
|
|
@ -2891,6 +2891,7 @@ void BKE_object_obdata_size_init(struct Object *ob, const float size)
|
|||
case OB_LAMP: {
|
||||
Light *lamp = (Light *)ob->data;
|
||||
lamp->dist *= size;
|
||||
lamp->radius *= size;
|
||||
lamp->area_size *= size;
|
||||
lamp->area_sizey *= size;
|
||||
lamp->area_sizez *= size;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "DNA_curves_types.h"
|
||||
#include "DNA_genfile.h"
|
||||
#include "DNA_gpencil_modifier_types.h"
|
||||
#include "DNA_light_types.h"
|
||||
#include "DNA_lineart_types.h"
|
||||
#include "DNA_listBase.h"
|
||||
#include "DNA_mask_types.h"
|
||||
|
@ -3836,6 +3837,13 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_ATLEAST(bmain, 305, 7)) {
|
||||
LISTBASE_FOREACH (Light *, light, &bmain->lights) {
|
||||
light->radius = light->area_size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioning code until next subversion bump goes here.
|
||||
*
|
||||
|
|
|
@ -45,7 +45,7 @@ static void light_shape_parameters_set(EEVEE_Light *evli, const Light *la, const
|
|||
evli->sizey = scale[1] / scale[2];
|
||||
evli->spotsize = cosf(la->spotsize * 0.5f);
|
||||
evli->spotblend = (1.0f - evli->spotsize) * la->spotblend;
|
||||
evli->radius = max_ff(0.001f, la->area_size);
|
||||
evli->radius = max_ff(0.001f, la->radius);
|
||||
}
|
||||
else if (la->type == LA_AREA) {
|
||||
evli->sizex = max_ff(0.003f, la->area_size * scale[0] * 0.5f);
|
||||
|
@ -62,7 +62,7 @@ static void light_shape_parameters_set(EEVEE_Light *evli, const Light *la, const
|
|||
evli->radius = max_ff(0.001f, tanf(min_ff(la->sun_angle, DEG2RADF(179.9f)) / 2.0f));
|
||||
}
|
||||
else {
|
||||
evli->radius = max_ff(0.001f, la->area_size);
|
||||
evli->radius = max_ff(0.001f, la->radius);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ void Light::shape_parameters_set(const ::Light *la, const float scale[3])
|
|||
_area_size_x = tanf(min_ff(la->sun_angle, DEG2RADF(179.9f)) / 2.0f);
|
||||
}
|
||||
else {
|
||||
_area_size_x = la->area_size;
|
||||
_area_size_x = la->radius;
|
||||
}
|
||||
_area_size_y = _area_size_x = max_ff(0.001f, _area_size_x);
|
||||
radius_squared = square_f(_area_size_x);
|
||||
|
|
|
@ -637,7 +637,7 @@ void OVERLAY_light_cache_populate(OVERLAY_Data *vedata, Object *ob)
|
|||
DRW_buffer_add_entry(cb->groundline, instdata.pos);
|
||||
|
||||
if (la->type == LA_LOCAL) {
|
||||
instdata.area_size_x = instdata.area_size_y = la->area_size;
|
||||
instdata.area_size_x = instdata.area_size_y = la->radius;
|
||||
DRW_buffer_add_entry(cb->light_point, color, &instdata);
|
||||
}
|
||||
else if (la->type == LA_SUN) {
|
||||
|
@ -661,7 +661,7 @@ void OVERLAY_light_cache_populate(OVERLAY_Data *vedata, Object *ob)
|
|||
instdata.spot_blend = sqrtf((-a - c * a) / (c - c * a));
|
||||
instdata.spot_cosine = a;
|
||||
/* HACK: We pack the area size in alpha color. This is decoded by the shader. */
|
||||
color[3] = -max_ff(la->area_size, FLT_MIN);
|
||||
color[3] = -max_ff(la->radius, FLT_MIN);
|
||||
DRW_buffer_add_entry(cb->light_spot, color, &instdata);
|
||||
|
||||
if ((la->mode & LA_SHOW_CONE) && !DRW_state_is_select()) {
|
||||
|
|
|
@ -1019,6 +1019,7 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
|
|||
et->setData("bias", &(lamp->bias));
|
||||
et->setData("bufsize", &(lamp->bufsize));
|
||||
et->setData("buffers", &(lamp->buffers));
|
||||
et->setData("radius", &(lamp->radius));
|
||||
et->setData("area_shape", &(lamp->area_shape));
|
||||
et->setData("area_size", &(lamp->area_size));
|
||||
et->setData("area_sizey", &(lamp->area_sizey));
|
||||
|
|
|
@ -132,6 +132,7 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Light *la)
|
|||
cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize);
|
||||
cla.addExtraTechniqueParameter("blender", "samp", la->samp);
|
||||
cla.addExtraTechniqueParameter("blender", "buffers", la->buffers);
|
||||
cla.addExtraTechniqueParameter("blender", "radius", la->radius);
|
||||
cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape);
|
||||
cla.addExtraTechniqueParameter("blender", "area_size", la->area_size);
|
||||
cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey);
|
||||
|
|
|
@ -175,7 +175,7 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
|||
if (pxr::UsdAttribute radius_attr = sphere_light.GetRadiusAttr()) {
|
||||
float radius = 0.0f;
|
||||
if (radius_attr.Get(&radius, motionSampleTime)) {
|
||||
blight->area_size = radius;
|
||||
blight->radius = radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
|||
if (pxr::UsdAttribute radius_attr = sphere_light.GetRadiusAttr()) {
|
||||
float radius = 0.0f;
|
||||
if (radius_attr.Get(&radius, motionSampleTime)) {
|
||||
blight->area_size = radius;
|
||||
blight->radius = radius;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ void USDLightWriter::do_write(HierarchyContext &context)
|
|||
break;
|
||||
case LA_LOCAL: {
|
||||
pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Define(stage, usd_path);
|
||||
sphere_light.CreateRadiusAttr().Set(light->area_size, timecode);
|
||||
sphere_light.CreateRadiusAttr().Set(light->radius, timecode);
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = sphere_light.LightAPI();
|
||||
#else
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef struct Light {
|
|||
|
||||
float clipsta, clipend;
|
||||
float bias;
|
||||
char _pad1[4];
|
||||
float radius;
|
||||
short bufsize, samp, buffers, filtertype;
|
||||
char bufflag, buftype;
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ static void rna_def_light_shadow(StructRNA *srna, bool sun)
|
|||
RNA_def_property_update(prop, 0, "rna_Light_update");
|
||||
|
||||
prop = RNA_def_property(srna, "shadow_soft_size", PROP_FLOAT, PROP_DISTANCE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "area_size");
|
||||
RNA_def_property_float_sdna(prop, NULL, "radius");
|
||||
RNA_def_property_range(prop, 0.0f, FLT_MAX);
|
||||
RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
|
||||
RNA_def_property_ui_text(
|
||||
|
|
Loading…
Reference in New Issue