diff options
author | Tim Stullich <tstullich> | 2019-05-15 15:45:33 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-15 17:07:50 +0300 |
commit | 5ba1a6bee0426e77a01cec8c89999ee4d15ced63 (patch) | |
tree | 3f6fa2deef19c31f93c9d68d54814fa85bf5d52a | |
parent | 2497ee31ec89560a9b72a070a70735caa6655b9e (diff) |
Lights: change sun light size to be specified as angle
This is the angular diameter as seen from earth, which is between 0.526° and
0.545° in reality. Sharing the size with other light types did not make much
sense and meant the unit was unclear.
Differential Revision: https://developer.blender.org/D4819
-rw-r--r-- | intern/cycles/blender/addon/properties.py | 2 | ||||
-rw-r--r-- | intern/cycles/blender/addon/ui.py | 4 | ||||
-rw-r--r-- | intern/cycles/blender/blender_object.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/render/light.cpp | 19 | ||||
-rw-r--r-- | intern/cycles/render/light.h | 1 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/properties_data_light.py | 4 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/light.c | 1 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 7 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_lights.c | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_light_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_light.c | 8 |
12 files changed, 52 insertions, 11 deletions
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 6da88a769f5..f376eb8ec67 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -1490,7 +1490,7 @@ class CyclesPreferences(bpy.types.AddonPreferences): break if not found_device: - col = box.column(align=True); + col = box.column(align=True) col.label(text="No compatible GPUs found for path tracing", icon='INFO') col.label(text="Cycles will render on the CPU", icon='BLANK1') return diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 9714067b08e..5ff88367f22 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -1345,8 +1345,10 @@ class CYCLES_LIGHT_PT_light(CyclesButtonsPanel, Panel): col.prop(light, "energy") col.separator() - if light.type in {'POINT', 'SUN', 'SPOT'}: + if light.type in {'POINT', 'SPOT'}: col.prop(light, "shadow_soft_size", text="Size") + elif light.type == 'SUN': + col.prop(light, "angle") elif light.type == 'AREA': col.prop(light, "shape", text="Shape") sub = col.column(align=True) diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 1094ff37afb..c07e896ab33 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -149,7 +149,7 @@ void BlenderSync::sync_light(BL::Object &b_parent, // } case BL::Light::type_SUN: { BL::SunLight b_sun_light(b_light); - light->size = b_sun_light.shadow_soft_size(); + light->angle = b_sun_light.angle(); light->type = LIGHT_DISTANT; break; } diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index ef4bd4260c9..5c3f1c35bdc 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -398,11 +398,18 @@ void LightManager::device_update_distribution(Device *, distribution[offset].lamp.size = light->size; totarea += lightarea; - if (light->size > 0.0f && light->use_mis) - use_lamp_mis = true; - if (light->type == LIGHT_BACKGROUND) { + if (light->type == LIGHT_DISTANT) { + use_lamp_mis |= (light->angle > 0.0f && light->use_mis); + } + else if (light->type == LIGHT_POINT || light->type == LIGHT_SPOT) { + use_lamp_mis |= (light->size > 0.0f && light->use_mis); + } + else if (light->type == LIGHT_AREA) { + use_lamp_mis |= light->use_mis; + } + else if (light->type == LIGHT_BACKGROUND) { num_background_lights++; - background_mis = light->use_mis; + background_mis |= light->use_mis; } light_index++; @@ -725,8 +732,8 @@ void LightManager::device_update_points(Device *, DeviceScene *dscene, Scene *sc else if (light->type == LIGHT_DISTANT) { shader_id &= ~SHADER_AREA_LIGHT; - float radius = light->size; - float angle = atanf(radius); + float angle = light->angle / 2.0f; + float radius = tanf(angle); float cosangle = cosf(angle); float area = M_PI_F * radius * radius; float invarea = (area > 0.0f) ? 1.0f / area : 1.0f; diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h index a7bffde7a8d..79450ea5f8d 100644 --- a/intern/cycles/render/light.h +++ b/intern/cycles/render/light.h @@ -47,6 +47,7 @@ class Light : public Node { float3 dir; float size; + float angle; float3 axisu; float sizeu; diff --git a/release/scripts/startup/bl_ui/properties_data_light.py b/release/scripts/startup/bl_ui/properties_data_light.py index 3d78b3a664d..376b7561739 100644 --- a/release/scripts/startup/bl_ui/properties_data_light.py +++ b/release/scripts/startup/bl_ui/properties_data_light.py @@ -101,8 +101,10 @@ class DATA_PT_EEVEE_light(DataButtonsPanel, Panel): col.separator() - if light.type in {'POINT', 'SPOT', 'SUN'}: + if light.type in {'POINT', 'SPOT'}: col.prop(light, "shadow_soft_size", text="Radius") + elif light.type == 'SUN': + col.prop(light, "angle") elif light.type == 'AREA': col.prop(light, "shape") diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 1b833d0a8c3..35b37475f17 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -2312,12 +2312,19 @@ class VIEW3D_MT_object_context_menu(Menu): props.data_path_item = "data.size_y" props.header_text = "Light Size Y: %.3f" - elif light.type in {'SPOT', 'POINT', 'SUN'}: + elif light.type in {'SPOT', 'POINT'}: props = layout.operator("wm.context_modal_mouse", text="Radius") props.data_path_iter = "selected_editable_objects" props.data_path_item = "data.shadow_soft_size" props.header_text = "Light Radius: %.3f" + elif light.type == 'SUN': + props = layout.operator("wm.context_modal_mouse", text="Angle") + props.data_path_iter = "selected_editable_objects" + props.data_path_item = "data.angle" + props.header_text = "Light Angle: %.3f" + + if light.type == 'SPOT': layout.separator() diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index 05b2eb82daf..1c3acb6a73a 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -80,6 +80,7 @@ void BKE_light_init(Light *la) la->contact_thickness = 0.2f; la->spec_fac = 1.0f; la->att_dist = 40.0f; + la->sun_angle = DEG2RADF(0.526f); curvemapping_initialize(la->curfalloff); } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 9d8fa2d06d0..526931d1a45 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3418,5 +3418,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) LISTBASE_FOREACH (bArmature *, arm, &bmain->armatures) { arm->flag &= ~(ARM_FLAG_UNUSED_7 | ARM_FLAG_UNUSED_9); } + + /* Initializes sun lights with the new angular diameter property */ + if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "sun_angle")) { + LISTBASE_FOREACH (Light *, light, &bmain->lights) { + light->sun_angle = 2.0f * atanf(light->area_size); + } + } } } diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c index 730372bce9c..f64cd340ab2 100644 --- a/source/blender/draw/engines/eevee/eevee_lights.c +++ b/source/blender/draw/engines/eevee/eevee_lights.c @@ -672,6 +672,9 @@ static void light_shape_parameters_set(EEVEE_Light *evli, const Light *la, float evli->sizey = max_ff(0.003f, la->area_size * scale[1] * 0.5f); } } + else if (la->type == LA_SUN) { + evli->radius = max_ff(0.001f, tanf(la->sun_angle / 2.0f)); + } else { evli->radius = max_ff(0.001f, la->area_size); } diff --git a/source/blender/makesdna/DNA_light_types.h b/source/blender/makesdna/DNA_light_types.h index 6bd118b7be9..5e881053910 100644 --- a/source/blender/makesdna/DNA_light_types.h +++ b/source/blender/makesdna/DNA_light_types.h @@ -66,6 +66,9 @@ typedef struct Light { short area_shape; float area_size, area_sizey, area_sizez; + float sun_angle; + char _pad3[4]; + /* texact is for buttons */ short texact, shadhalostep; diff --git a/source/blender/makesrna/intern/rna_light.c b/source/blender/makesrna/intern/rna_light.c index da2b5752a0f..54c8049d4d2 100644 --- a/source/blender/makesrna/intern/rna_light.c +++ b/source/blender/makesrna/intern/rna_light.c @@ -545,12 +545,20 @@ static void rna_def_spot_light(BlenderRNA *brna) static void rna_def_sun_light(BlenderRNA *brna) { StructRNA *srna; + PropertyRNA *prop; srna = RNA_def_struct(brna, "SunLight", "Light"); RNA_def_struct_sdna(srna, "Light"); RNA_def_struct_ui_text(srna, "Sun Light", "Constant direction parallel ray Light"); RNA_def_struct_ui_icon(srna, ICON_LIGHT_SUN); + prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "sun_angle"); + RNA_def_property_float_default(prop, DEG2RADF(0.526f)); + RNA_def_property_range(prop, DEG2RADF(0.0f), DEG2RADF(180.0f)); + RNA_def_property_ui_text(prop, "Angle", "Angular diameter of the Sun as seen from the Earth"); + RNA_def_property_update(prop, 0, "rna_Light_update"); + rna_def_light_energy(srna, true); rna_def_light_shadow(srna, true); } |