Blender V4.3
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
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
19#include "DNA_material_types.h"
20#include "DNA_texture_types.h"
21#include "DNA_world_types.h"
22
23#include "WM_types.hh"
24
25#ifdef RNA_RUNTIME
26
27# include "MEM_guardedalloc.h"
28
29# include "BKE_context.hh"
30# include "BKE_layer.hh"
31# include "BKE_main.hh"
32# include "BKE_texture.h"
33
34# include "DEG_depsgraph.hh"
35# include "DEG_depsgraph_build.hh"
36
37# include "ED_node.hh"
38
39# include "WM_api.hh"
40
41static PointerRNA rna_World_lighting_get(PointerRNA *ptr)
42{
43 return rna_pointer_inherit_refine(ptr, &RNA_WorldLighting, ptr->owner_id);
44}
45
46static PointerRNA rna_World_mist_get(PointerRNA *ptr)
47{
48 return rna_pointer_inherit_refine(ptr, &RNA_WorldMistSettings, ptr->owner_id);
49}
50
51static void rna_World_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
52{
53 World *wo = (World *)ptr->owner_id;
54
55 DEG_id_tag_update(&wo->id, 0);
57}
58
59# if 0
60static void rna_World_draw_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
61{
62 World *wo = (World *)ptr->owner_id;
63
64 DEG_id_tag_update(&wo->id, 0);
66}
67# endif
68
69static void rna_World_draw_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
70{
71 World *wo = (World *)ptr->owner_id;
72
73 DEG_id_tag_update(&wo->id, 0);
76}
77
78static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr)
79{
80 World *wrld = (World *)ptr->data;
81 Main *bmain = CTX_data_main(C);
82 Scene *scene = CTX_data_scene(C);
83
84 if (wrld->use_nodes && wrld->nodetree == nullptr) {
85 ED_node_shader_default(C, &wrld->id);
86 }
87
89 rna_World_update(bmain, scene, ptr);
90 rna_World_draw_update(bmain, scene, ptr);
91}
92
93void rna_World_lightgroup_get(PointerRNA *ptr, char *value)
94{
95 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
96 char value_buf[sizeof(lgm->name)];
97 int len = BKE_lightgroup_membership_get(lgm, value_buf);
98 memcpy(value, value_buf, len + 1);
99}
100
101int rna_World_lightgroup_length(PointerRNA *ptr)
102{
103 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
105}
106
107void rna_World_lightgroup_set(PointerRNA *ptr, const char *value)
108{
109 BKE_lightgroup_membership_set(&((World *)ptr->owner_id)->lightgroup, value);
110}
111
112#else
113
115 {LIGHT_PROBE_RESOLUTION_128, "128", 0, "128", ""},
116 {LIGHT_PROBE_RESOLUTION_256, "256", 0, "256", ""},
117 {LIGHT_PROBE_RESOLUTION_512, "512", 0, "512", ""},
118 {LIGHT_PROBE_RESOLUTION_1024, "1024", 0, "1024", ""},
119 {LIGHT_PROBE_RESOLUTION_2048, "2048", 0, "2048", ""},
120 {LIGHT_PROBE_RESOLUTION_4096, "4096", 0, "4096", ""},
121 {0, nullptr, 0, nullptr, nullptr},
122};
123
124static void rna_def_lighting(BlenderRNA *brna)
125{
126 StructRNA *srna;
127 PropertyRNA *prop;
128
129 srna = RNA_def_struct(brna, "WorldLighting", nullptr);
130 RNA_def_struct_sdna(srna, "World");
131 RNA_def_struct_nested(brna, srna, "World");
132 RNA_def_struct_ui_text(srna, "Lighting", "Lighting for a World data-block");
133
134 /* ambient occlusion */
135 prop = RNA_def_property(srna, "ao_factor", PROP_FLOAT, PROP_FACTOR);
136 RNA_def_property_float_sdna(prop, nullptr, "aoenergy");
137 RNA_def_property_range(prop, 0, INT_MAX);
138 RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
139 RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
140 RNA_def_property_update(prop, 0, "rna_World_update");
141
142 prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
143 RNA_def_property_float_sdna(prop, nullptr, "aodist");
146 prop, "Distance", "Length of rays, defines how far away other faces give occlusion effect");
147 RNA_def_property_update(prop, 0, "rna_World_update");
148}
149
151{
152 StructRNA *srna;
153 PropertyRNA *prop;
154
155 static const EnumPropertyItem falloff_items[] = {
156 {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
157 {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
159 "INVERSE_QUADRATIC",
160 0,
161 "Inverse Quadratic",
162 "Use inverse quadratic progression"},
163 {0, nullptr, 0, nullptr, nullptr},
164 };
165
166 srna = RNA_def_struct(brna, "WorldMistSettings", nullptr);
167 RNA_def_struct_sdna(srna, "World");
168 RNA_def_struct_nested(brna, srna, "World");
169 RNA_def_struct_ui_text(srna, "World Mist", "Mist settings for a World data-block");
170
171 prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
172 RNA_def_property_boolean_sdna(prop, nullptr, "mode", WO_MIST);
174 prop, "Use Mist", "Occlude objects with the environment color as they are further away");
175 RNA_def_property_update(prop, 0, "rna_World_draw_update");
176
177 prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
178 RNA_def_property_float_sdna(prop, nullptr, "misi");
179 RNA_def_property_range(prop, 0, 1);
180 RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect");
181 RNA_def_property_update(prop, 0, "rna_World_draw_update");
182
183 prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE);
184 RNA_def_property_float_sdna(prop, nullptr, "miststa");
186 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
188 prop, "Start", "Starting distance of the mist, measured from the camera");
189 RNA_def_property_update(prop, 0, "rna_World_draw_update");
190
191 prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE);
192 RNA_def_property_float_sdna(prop, nullptr, "mistdist");
194 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
195 RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in");
196 RNA_def_property_update(prop, 0, "rna_World_draw_update");
197
198 prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE);
199 RNA_def_property_float_sdna(prop, nullptr, "misthi");
200 RNA_def_property_range(prop, 0, 100);
201 RNA_def_property_ui_text(prop, "Height", "Control how much mist density decreases with height");
202 RNA_def_property_update(prop, 0, "rna_World_update");
203
204 prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
205 RNA_def_property_enum_sdna(prop, nullptr, "mistype");
206 RNA_def_property_enum_items(prop, falloff_items);
207 RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist");
208 RNA_def_property_update(prop, 0, "rna_World_draw_update");
209}
210
212{
213 StructRNA *srna;
214 PropertyRNA *prop;
215
216 static const float default_world_color[] = {0.05f, 0.05f, 0.05f};
217
218 srna = RNA_def_struct(brna, "World", "ID");
220 srna,
221 "World",
222 "World data-block describing the environment and ambient lighting of a scene");
223 RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
224
226
227 /* Flags */
228 prop = RNA_def_property(srna, "use_eevee_finite_volume", PROP_BOOLEAN, PROP_NONE);
231 "Finite Volume",
232 "The world's volume used to be rendered by EEVEE Legacy. Conversion is "
233 "needed for it to render properly.");
235
236 /* colors */
237 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
238 RNA_def_property_float_sdna(prop, nullptr, "horr");
239 RNA_def_property_array(prop, 3);
240 RNA_def_property_float_array_default(prop, default_world_color);
241 RNA_def_property_ui_text(prop, "Color", "Color of the background");
242 // RNA_def_property_update(prop, 0, "rna_World_update");
243 /* render-only uses this */
244 RNA_def_property_update(prop, 0, "rna_World_draw_update");
245
246 /* nested structs */
247 prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
249 RNA_def_property_struct_type(prop, "WorldLighting");
250 RNA_def_property_pointer_funcs(prop, "rna_World_lighting_get", nullptr, nullptr, nullptr);
251 RNA_def_property_ui_text(prop, "Lighting", "World lighting settings");
252
253 prop = RNA_def_property(srna, "mist_settings", PROP_POINTER, PROP_NONE);
255 RNA_def_property_struct_type(prop, "WorldMistSettings");
256 RNA_def_property_pointer_funcs(prop, "rna_World_mist_get", nullptr, nullptr, nullptr);
257 RNA_def_property_ui_text(prop, "Mist", "World mist settings");
258
259 /* nodes */
260 prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
261 RNA_def_property_pointer_sdna(prop, nullptr, "nodetree");
264 RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
265
266 prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
267 RNA_def_property_boolean_sdna(prop, nullptr, "use_nodes", 1);
270 RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world");
271 RNA_def_property_update(prop, 0, "rna_World_use_nodes_update");
272
273 /* Lightgroup Membership */
274 prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE);
276 prop, "rna_World_lightgroup_get", "rna_World_lightgroup_length", "rna_World_lightgroup_set");
278 RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the world belongs to");
279
280 /* Reflection Probe Baking. */
281 prop = RNA_def_property(srna, "probe_resolution", PROP_ENUM, PROP_NONE);
282 RNA_def_property_enum_sdna(prop, nullptr, "probe_resolution");
284 RNA_def_property_ui_text(prop, "Resolution", "Resolution when baked to a texture");
285 RNA_def_property_update(prop, 0, "rna_World_draw_update");
286
287 prop = RNA_def_property(srna, "sun_threshold", PROP_FLOAT, PROP_NONE);
289 "Sun Threshold",
290 "If non-zero, the maximum value for world contribution that will be "
291 "recorded inside the world light probe. The excess contribution is "
292 "converted to a sun light. This reduces the light bleeding caused by "
293 "very bright light sources.");
294 RNA_def_property_range(prop, 0.0f, FLT_MAX);
295 RNA_def_property_update(prop, 0, "rna_World_draw_update");
296
297 prop = RNA_def_property(srna, "sun_angle", PROP_FLOAT, PROP_ANGLE);
298 RNA_def_property_range(prop, DEG2RADF(0.0f), DEG2RADF(180.0f));
300 prop, "Sun Angle", "Angular diameter of the Sun as seen from the Earth");
301 RNA_def_property_update(prop, 0, "rna_World_draw_update");
302
303 prop = RNA_def_property(srna, "use_sun_shadow", PROP_BOOLEAN, PROP_NONE);
304 RNA_def_property_boolean_sdna(prop, nullptr, "flag", WO_USE_SUN_SHADOW);
305 RNA_def_property_ui_text(prop, "Use Shadow", "Enable sun shadow casting");
306 RNA_def_property_update(prop, 0, "rna_World_draw_update");
307
308 prop = RNA_def_property(srna, "sun_shadow_maximum_resolution", PROP_FLOAT, PROP_DISTANCE);
309 RNA_def_property_range(prop, 0.0f, FLT_MAX);
310 RNA_def_property_ui_range(prop, 0.0001f, 0.020f, 0.05f, 4);
312 "Shadows Resolution Limit",
313 "Maximum size of a shadow map pixel. Higher values use less memory at "
314 "the cost of shadow quality.");
316 RNA_def_property_update(prop, 0, "rna_World_draw_update");
317
318 prop = RNA_def_property(srna, "sun_shadow_filter_radius", PROP_FLOAT, PROP_NONE);
319 RNA_def_property_range(prop, 0.0f, FLT_MAX);
320 RNA_def_property_ui_range(prop, 0.0f, 5.0f, 1.0f, 2);
322 prop, "Shadow Filter Radius", "Blur shadow aliasing using Percentage Closer Filtering");
324 RNA_def_property_update(prop, 0, "rna_World_draw_update");
325
326 prop = RNA_def_property(srna, "use_sun_shadow_jitter", PROP_BOOLEAN, PROP_NONE);
329 prop,
330 "Shadow Jitter",
331 "Enable jittered soft shadows to increase shadow precision (disabled in viewport unless "
332 "enabled in the render settings). Has a high performance impact.");
334 RNA_def_property_update(prop, 0, "rna_World_draw_update");
335
336 prop = RNA_def_property(srna, "sun_shadow_jitter_overblur", PROP_FLOAT, PROP_PERCENTAGE);
337 RNA_def_property_range(prop, 0.0f, 100.0f);
338 RNA_def_property_ui_range(prop, 0.0f, 20.0f, 10.0f, 0);
340 prop,
341 "Shadow Jitter Overblur",
342 "Apply shadow tracing to each jittered sample to reduce under-sampling artifacts");
344 RNA_def_property_update(prop, 0, "rna_World_draw_update");
345
346 rna_def_lighting(brna);
347 rna_def_world_mist(brna);
348}
349
350#endif
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
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)
void DEG_relations_tag_update(Main *bmain)
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
@ WO_MIST
@ 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
void ED_node_shader_default(const bContext *C, ID *id)
Definition node_edit.cc:549
Read Guarded memory(de)allocation.
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:355
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:296
@ PROP_ANIMATABLE
Definition RNA_types.hh:220
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:284
@ PROP_DISTANCE
Definition RNA_types.hh:159
@ PROP_COLOR
Definition RNA_types.hh:163
@ PROP_ANGLE
Definition RNA_types.hh:155
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_PERCENTAGE
Definition RNA_types.hh:153
@ PROP_FACTOR
Definition RNA_types.hh:154
#define NC_WORLD
Definition WM_types.hh:354
#define ND_WORLD
Definition WM_types.hh:419
#define ND_DRAW
Definition WM_types.hh:428
#define ND_WORLD_DRAW
Definition WM_types.hh:454
#define NC_OBJECT
Definition WM_types.hh:346
int len
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, StructRNA *type, void *data)
void rna_def_animdata_common(StructRNA *srna)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
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_struct_ui_text(StructRNA *srna, const char *name, const char *description)
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:114
void RNA_def_world(BlenderRNA *brna)
Definition rna_world.cc:211
static void rna_def_world_mist(BlenderRNA *brna)
Definition rna_world.cc:150
static void rna_def_lighting(BlenderRNA *brna)
Definition rna_world.cc:124
#define FLT_MAX
Definition stdcycles.h:14
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4126