Blender V5.0
rna_world.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cstdlib>
11
12#include "RNA_define.hh"
13
14#include "BLI_math_rotation.h"
15
16#include "rna_internal.hh"
17
18#include "DNA_world_types.h"
19
20#include "WM_types.hh"
21
22#ifdef RNA_RUNTIME
23
24# include "BKE_context.hh"
25# include "BKE_layer.hh"
26# include "BKE_main.hh"
27# include "BKE_texture.h"
28
29# include "DEG_depsgraph.hh"
30# include "DEG_depsgraph_build.hh"
31
32# include "ED_node.hh"
33
34# include "WM_api.hh"
35
36static PointerRNA rna_World_lighting_get(PointerRNA *ptr)
37{
38 return RNA_pointer_create_with_parent(*ptr, &RNA_WorldLighting, ptr->owner_id);
39}
40
41static PointerRNA rna_World_mist_get(PointerRNA *ptr)
42{
43 return RNA_pointer_create_with_parent(*ptr, &RNA_WorldMistSettings, ptr->owner_id);
44}
45
46static void rna_World_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
47{
48 World *wo = (World *)ptr->owner_id;
49
50 DEG_id_tag_update(&wo->id, 0);
52}
53
54# if 0
55static void rna_World_draw_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
56{
57 World *wo = (World *)ptr->owner_id;
58
59 DEG_id_tag_update(&wo->id, 0);
61}
62# endif
63
64static void rna_World_draw_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
65{
66 World *wo = (World *)ptr->owner_id;
67
68 DEG_id_tag_update(&wo->id, 0);
71}
72
73void rna_World_lightgroup_get(PointerRNA *ptr, char *value)
74{
75 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
76 char value_buf[sizeof(lgm->name)];
77 int len = BKE_lightgroup_membership_get(lgm, value_buf);
78 memcpy(value, value_buf, len + 1);
79}
80
81int rna_World_lightgroup_length(PointerRNA *ptr)
82{
83 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
85}
86
87void rna_World_lightgroup_set(PointerRNA *ptr, const char *value)
88{
89 BKE_lightgroup_membership_set(&((World *)ptr->owner_id)->lightgroup, value);
90}
91
92bool rna_World_use_nodes_get(PointerRNA * /*ptr*/)
93{
94 /* #use_nodes is deprecated. Worlds always use nodes. */
95 return true;
96}
97
98void rna_World_use_nodes_set(PointerRNA * /*ptr*/, bool /*new_value*/)
99{
100 /* #use_nodes is deprecated. Setting the property has no effect.
101 * Note: Users will get a warning through the RNA deprecation warning, so no need to log a
102 * warning here. */
103}
104
105#else
106
108 {LIGHT_PROBE_RESOLUTION_128, "128", 0, "128", ""},
109 {LIGHT_PROBE_RESOLUTION_256, "256", 0, "256", ""},
110 {LIGHT_PROBE_RESOLUTION_512, "512", 0, "512", ""},
111 {LIGHT_PROBE_RESOLUTION_1024, "1024", 0, "1024", ""},
112 {LIGHT_PROBE_RESOLUTION_2048, "2048", 0, "2048", ""},
113 {LIGHT_PROBE_RESOLUTION_4096, "4096", 0, "4096", ""},
114 {0, nullptr, 0, nullptr, nullptr},
115};
116
117static void rna_def_lighting(BlenderRNA *brna)
118{
119 StructRNA *srna;
120 PropertyRNA *prop;
121
122 srna = RNA_def_struct(brna, "WorldLighting", nullptr);
123 RNA_def_struct_sdna(srna, "World");
124 RNA_def_struct_nested(brna, srna, "World");
125 RNA_def_struct_ui_text(srna, "Lighting", "Lighting for a World data-block");
126
127 /* ambient occlusion */
128 prop = RNA_def_property(srna, "ao_factor", PROP_FLOAT, PROP_FACTOR);
129 RNA_def_property_float_sdna(prop, nullptr, "aoenergy");
130 RNA_def_property_range(prop, 0, INT_MAX);
131 RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
132 RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
133 RNA_def_property_update(prop, 0, "rna_World_update");
134
135 prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
136 RNA_def_property_float_sdna(prop, nullptr, "aodist");
139 prop, "Distance", "Length of rays, defines how far away other faces give occlusion effect");
140 RNA_def_property_update(prop, 0, "rna_World_update");
141}
142
144{
145 StructRNA *srna;
146 PropertyRNA *prop;
147
148 static const EnumPropertyItem falloff_items[] = {
149 {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
150 {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
152 "INVERSE_QUADRATIC",
153 0,
154 "Inverse Quadratic",
155 "Use inverse quadratic progression"},
156 {0, nullptr, 0, nullptr, nullptr},
157 };
158
159 srna = RNA_def_struct(brna, "WorldMistSettings", nullptr);
160 RNA_def_struct_sdna(srna, "World");
161 RNA_def_struct_nested(brna, srna, "World");
162 RNA_def_struct_ui_text(srna, "World Mist", "Mist settings for a World data-block");
163
164 prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
165 RNA_def_property_boolean_sdna(prop, nullptr, "mode", WO_MIST);
167 prop, "Use Mist", "Occlude objects with the environment color as they are further away");
168 RNA_def_property_update(prop, 0, "rna_World_draw_update");
169
170 prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
171 RNA_def_property_float_sdna(prop, nullptr, "misi");
172 RNA_def_property_range(prop, 0, 1);
173 RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect");
174 RNA_def_property_update(prop, 0, "rna_World_draw_update");
175
176 prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE);
177 RNA_def_property_float_sdna(prop, nullptr, "miststa");
179 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
181 prop, "Start", "Starting distance of the mist, measured from the camera");
182 RNA_def_property_update(prop, 0, "rna_World_draw_update");
183
184 prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE);
185 RNA_def_property_float_sdna(prop, nullptr, "mistdist");
187 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
188 RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in");
189 RNA_def_property_update(prop, 0, "rna_World_draw_update");
190
191 prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE);
192 RNA_def_property_float_sdna(prop, nullptr, "misthi");
193 RNA_def_property_range(prop, 0, 100);
194 RNA_def_property_ui_text(prop, "Height", "Control how much mist density decreases with height");
195 RNA_def_property_update(prop, 0, "rna_World_update");
196
197 prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
198 RNA_def_property_enum_sdna(prop, nullptr, "mistype");
199 RNA_def_property_enum_items(prop, falloff_items);
200 RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist");
201 RNA_def_property_update(prop, 0, "rna_World_draw_update");
202}
203
205{
206 StructRNA *srna;
207 PropertyRNA *prop;
208
209 static const float default_world_color[] = {0.05f, 0.05f, 0.05f};
210
211 srna = RNA_def_struct(brna, "World", "ID");
213 srna,
214 "World",
215 "World data-block describing the environment and ambient lighting of a scene");
216 RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
217
219
220 /* Flags */
221 prop = RNA_def_property(srna, "use_eevee_finite_volume", PROP_BOOLEAN, PROP_NONE);
224 "Finite Volume",
225 "The world's volume used to be rendered by EEVEE Legacy. Conversion is "
226 "needed for it to render properly.");
228
229 /* colors */
230 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
231 RNA_def_property_float_sdna(prop, nullptr, "horr");
232 RNA_def_property_array(prop, 3);
233 RNA_def_property_float_array_default(prop, default_world_color);
234 RNA_def_property_ui_text(prop, "Color", "Color of the background");
235 // RNA_def_property_update(prop, 0, "rna_World_update");
236 /* render-only uses this */
237 RNA_def_property_update(prop, 0, "rna_World_draw_update");
238
239 /* nested structs */
240 prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
242 RNA_def_property_struct_type(prop, "WorldLighting");
243 RNA_def_property_pointer_funcs(prop, "rna_World_lighting_get", nullptr, nullptr, nullptr);
244 RNA_def_property_ui_text(prop, "Lighting", "World lighting settings");
245
246 prop = RNA_def_property(srna, "mist_settings", PROP_POINTER, PROP_NONE);
248 RNA_def_property_struct_type(prop, "WorldMistSettings");
249 RNA_def_property_pointer_funcs(prop, "rna_World_mist_get", nullptr, nullptr, nullptr);
250 RNA_def_property_ui_text(prop, "Mist", "World mist settings");
251
252 /* nodes */
253 prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
254 RNA_def_property_pointer_sdna(prop, nullptr, "nodetree");
257 RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
258
259 prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
260 RNA_def_property_boolean_sdna(prop, nullptr, "use_nodes", 1);
263 RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world");
264 RNA_def_property_boolean_funcs(prop, "rna_World_use_nodes_get", "rna_World_use_nodes_set");
266 "Unused but kept for compatibility reasons. Setting the property "
267 "has no effect, and getting it always returns True.",
268 500,
269 600);
270
271 /* Lightgroup Membership */
272 prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE);
274 prop, "rna_World_lightgroup_get", "rna_World_lightgroup_length", "rna_World_lightgroup_set");
276 RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the world belongs to");
277
278 /* Reflection Probe Baking. */
279 prop = RNA_def_property(srna, "probe_resolution", PROP_ENUM, PROP_NONE);
280 RNA_def_property_enum_sdna(prop, nullptr, "probe_resolution");
282 RNA_def_property_ui_text(prop, "Resolution", "Resolution when baked to a texture");
283 RNA_def_property_update(prop, 0, "rna_World_draw_update");
284
285 prop = RNA_def_property(srna, "sun_threshold", PROP_FLOAT, PROP_NONE);
287 "Sun Threshold",
288 "If non-zero, the maximum value for world contribution that will be "
289 "recorded inside the world light probe. The excess contribution is "
290 "converted to a sun light. This reduces the light bleeding caused by "
291 "very bright light sources.");
292 RNA_def_property_range(prop, 0.0f, FLT_MAX);
293 RNA_def_property_update(prop, 0, "rna_World_draw_update");
294
295 prop = RNA_def_property(srna, "sun_angle", PROP_FLOAT, PROP_ANGLE);
296 RNA_def_property_range(prop, DEG2RADF(0.0f), DEG2RADF(180.0f));
298 prop, "Sun Angle", "Angular diameter of the Sun as seen from the Earth");
299 RNA_def_property_update(prop, 0, "rna_World_draw_update");
300
301 prop = RNA_def_property(srna, "use_sun_shadow", PROP_BOOLEAN, PROP_NONE);
302 RNA_def_property_boolean_sdna(prop, nullptr, "flag", WO_USE_SUN_SHADOW);
303 RNA_def_property_ui_text(prop, "Use Shadow", "Enable sun shadow casting");
304 RNA_def_property_update(prop, 0, "rna_World_draw_update");
305
306 prop = RNA_def_property(srna, "sun_shadow_maximum_resolution", PROP_FLOAT, PROP_DISTANCE);
307 RNA_def_property_range(prop, 0.0f, FLT_MAX);
308 RNA_def_property_ui_range(prop, 0.0001f, 0.020f, 0.05f, 4);
310 "Shadows Resolution Limit",
311 "Maximum size of a shadow map pixel. Higher values use less memory at "
312 "the cost of shadow quality.");
314 RNA_def_property_update(prop, 0, "rna_World_draw_update");
315
316 prop = RNA_def_property(srna, "sun_shadow_filter_radius", PROP_FLOAT, PROP_NONE);
317 RNA_def_property_range(prop, 0.0f, FLT_MAX);
318 RNA_def_property_ui_range(prop, 0.0f, 5.0f, 1.0f, 2);
320 prop, "Shadow Filter Radius", "Blur shadow aliasing using Percentage Closer Filtering");
322 RNA_def_property_update(prop, 0, "rna_World_draw_update");
323
324 prop = RNA_def_property(srna, "use_sun_shadow_jitter", PROP_BOOLEAN, PROP_NONE);
327 prop,
328 "Shadow Jitter",
329 "Enable jittered soft shadows to increase shadow precision (disabled in viewport unless "
330 "enabled in the render settings). Has a high performance impact.");
332 RNA_def_property_update(prop, 0, "rna_World_draw_update");
333
334 prop = RNA_def_property(srna, "sun_shadow_jitter_overblur", PROP_FLOAT, PROP_PERCENTAGE);
335 RNA_def_property_range(prop, 0.0f, 100.0f);
336 RNA_def_property_ui_range(prop, 0.0f, 20.0f, 10.0f, 0);
338 prop,
339 "Shadow Jitter Overblur",
340 "Apply shadow tracing to each jittered sample to reduce under-sampling artifacts");
342 RNA_def_property_update(prop, 0, "rna_World_draw_update");
343
344 rna_def_lighting(brna);
345 rna_def_world_mist(brna);
346}
347
348#endif
int BKE_lightgroup_membership_length(const LightgroupMembership *lgm)
void BKE_lightgroup_membership_set(LightgroupMembership **lgm, const char *name)
int BKE_lightgroup_membership_get(const LightgroupMembership *lgm, char *name)
#define DEG2RADF(_deg)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ WO_MIST
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
@ WO_USE_SUN_SHADOW
@ WO_USE_EEVEE_FINITE_VOLUME
@ WO_USE_SUN_SHADOW_JITTER
@ LIGHT_PROBE_RESOLUTION_128
@ LIGHT_PROBE_RESOLUTION_512
@ LIGHT_PROBE_RESOLUTION_4096
@ LIGHT_PROBE_RESOLUTION_256
@ LIGHT_PROBE_RESOLUTION_2048
@ LIGHT_PROBE_RESOLUTION_1024
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_ENUM
Definition RNA_types.hh:166
@ PROP_STRING
Definition RNA_types.hh:165
@ PROP_POINTER
Definition RNA_types.hh:167
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:503
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:407
@ PROP_ANIMATABLE
Definition RNA_types.hh:319
@ PROP_EDITABLE
Definition RNA_types.hh:306
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:395
@ PROP_DISTANCE
Definition RNA_types.hh:256
@ PROP_COLOR
Definition RNA_types.hh:260
@ PROP_ANGLE
Definition RNA_types.hh:252
@ PROP_NONE
Definition RNA_types.hh:233
@ PROP_PERCENTAGE
Definition RNA_types.hh:250
@ PROP_FACTOR
Definition RNA_types.hh:251
#define NC_WORLD
Definition WM_types.hh:387
#define ND_WORLD
Definition WM_types.hh:452
#define ND_DRAW
Definition WM_types.hh:461
#define ND_WORLD_DRAW
Definition WM_types.hh:487
#define NC_OBJECT
Definition WM_types.hh:379
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
void rna_def_animdata_common(StructRNA *srna)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_deprecated(PropertyRNA *prop, const char *note, const short version, const short removal_version)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
static const EnumPropertyItem world_probe_resolution_items[]
Definition rna_world.cc:107
void RNA_def_world(BlenderRNA *brna)
Definition rna_world.cc:204
static void rna_def_world_mist(BlenderRNA *brna)
Definition rna_world.cc:143
static void rna_def_lighting(BlenderRNA *brna)
Definition rna_world.cc:117
#define FLT_MAX
Definition stdcycles.h:14
uint len
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4238