Blender V4.5
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
73static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr)
74{
75 World *wrld = (World *)ptr->data;
76 Main *bmain = CTX_data_main(C);
77 Scene *scene = CTX_data_scene(C);
78
79 if (wrld->use_nodes && wrld->nodetree == nullptr) {
80 ED_node_shader_default(C, &wrld->id);
81 }
82
84 rna_World_update(bmain, scene, ptr);
85 rna_World_draw_update(bmain, scene, ptr);
86}
87
88void rna_World_lightgroup_get(PointerRNA *ptr, char *value)
89{
90 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
91 char value_buf[sizeof(lgm->name)];
92 int len = BKE_lightgroup_membership_get(lgm, value_buf);
93 memcpy(value, value_buf, len + 1);
94}
95
96int rna_World_lightgroup_length(PointerRNA *ptr)
97{
98 LightgroupMembership *lgm = ((World *)ptr->owner_id)->lightgroup;
100}
101
102void rna_World_lightgroup_set(PointerRNA *ptr, const char *value)
103{
104 BKE_lightgroup_membership_set(&((World *)ptr->owner_id)->lightgroup, value);
105}
106
107#else
108
110 {LIGHT_PROBE_RESOLUTION_128, "128", 0, "128", ""},
111 {LIGHT_PROBE_RESOLUTION_256, "256", 0, "256", ""},
112 {LIGHT_PROBE_RESOLUTION_512, "512", 0, "512", ""},
113 {LIGHT_PROBE_RESOLUTION_1024, "1024", 0, "1024", ""},
114 {LIGHT_PROBE_RESOLUTION_2048, "2048", 0, "2048", ""},
115 {LIGHT_PROBE_RESOLUTION_4096, "4096", 0, "4096", ""},
116 {0, nullptr, 0, nullptr, nullptr},
117};
118
119static void rna_def_lighting(BlenderRNA *brna)
120{
121 StructRNA *srna;
122 PropertyRNA *prop;
123
124 srna = RNA_def_struct(brna, "WorldLighting", nullptr);
125 RNA_def_struct_sdna(srna, "World");
126 RNA_def_struct_nested(brna, srna, "World");
127 RNA_def_struct_ui_text(srna, "Lighting", "Lighting for a World data-block");
128
129 /* ambient occlusion */
130 prop = RNA_def_property(srna, "ao_factor", PROP_FLOAT, PROP_FACTOR);
131 RNA_def_property_float_sdna(prop, nullptr, "aoenergy");
132 RNA_def_property_range(prop, 0, INT_MAX);
133 RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
134 RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
135 RNA_def_property_update(prop, 0, "rna_World_update");
136
137 prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
138 RNA_def_property_float_sdna(prop, nullptr, "aodist");
141 prop, "Distance", "Length of rays, defines how far away other faces give occlusion effect");
142 RNA_def_property_update(prop, 0, "rna_World_update");
143}
144
146{
147 StructRNA *srna;
148 PropertyRNA *prop;
149
150 static const EnumPropertyItem falloff_items[] = {
151 {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
152 {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
154 "INVERSE_QUADRATIC",
155 0,
156 "Inverse Quadratic",
157 "Use inverse quadratic progression"},
158 {0, nullptr, 0, nullptr, nullptr},
159 };
160
161 srna = RNA_def_struct(brna, "WorldMistSettings", nullptr);
162 RNA_def_struct_sdna(srna, "World");
163 RNA_def_struct_nested(brna, srna, "World");
164 RNA_def_struct_ui_text(srna, "World Mist", "Mist settings for a World data-block");
165
166 prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
167 RNA_def_property_boolean_sdna(prop, nullptr, "mode", WO_MIST);
169 prop, "Use Mist", "Occlude objects with the environment color as they are further away");
170 RNA_def_property_update(prop, 0, "rna_World_draw_update");
171
172 prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
173 RNA_def_property_float_sdna(prop, nullptr, "misi");
174 RNA_def_property_range(prop, 0, 1);
175 RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect");
176 RNA_def_property_update(prop, 0, "rna_World_draw_update");
177
178 prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE);
179 RNA_def_property_float_sdna(prop, nullptr, "miststa");
181 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
183 prop, "Start", "Starting distance of the mist, measured from the camera");
184 RNA_def_property_update(prop, 0, "rna_World_draw_update");
185
186 prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE);
187 RNA_def_property_float_sdna(prop, nullptr, "mistdist");
189 RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
190 RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in");
191 RNA_def_property_update(prop, 0, "rna_World_draw_update");
192
193 prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE);
194 RNA_def_property_float_sdna(prop, nullptr, "misthi");
195 RNA_def_property_range(prop, 0, 100);
196 RNA_def_property_ui_text(prop, "Height", "Control how much mist density decreases with height");
197 RNA_def_property_update(prop, 0, "rna_World_update");
198
199 prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
200 RNA_def_property_enum_sdna(prop, nullptr, "mistype");
201 RNA_def_property_enum_items(prop, falloff_items);
202 RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist");
203 RNA_def_property_update(prop, 0, "rna_World_draw_update");
204}
205
207{
208 StructRNA *srna;
209 PropertyRNA *prop;
210
211 static const float default_world_color[] = {0.05f, 0.05f, 0.05f};
212
213 srna = RNA_def_struct(brna, "World", "ID");
215 srna,
216 "World",
217 "World data-block describing the environment and ambient lighting of a scene");
218 RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
219
221
222 /* Flags */
223 prop = RNA_def_property(srna, "use_eevee_finite_volume", PROP_BOOLEAN, PROP_NONE);
226 "Finite Volume",
227 "The world's volume used to be rendered by EEVEE Legacy. Conversion is "
228 "needed for it to render properly.");
230
231 /* colors */
232 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
233 RNA_def_property_float_sdna(prop, nullptr, "horr");
234 RNA_def_property_array(prop, 3);
235 RNA_def_property_float_array_default(prop, default_world_color);
236 RNA_def_property_ui_text(prop, "Color", "Color of the background");
237 // RNA_def_property_update(prop, 0, "rna_World_update");
238 /* render-only uses this */
239 RNA_def_property_update(prop, 0, "rna_World_draw_update");
240
241 /* nested structs */
242 prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
244 RNA_def_property_struct_type(prop, "WorldLighting");
245 RNA_def_property_pointer_funcs(prop, "rna_World_lighting_get", nullptr, nullptr, nullptr);
246 RNA_def_property_ui_text(prop, "Lighting", "World lighting settings");
247
248 prop = RNA_def_property(srna, "mist_settings", PROP_POINTER, PROP_NONE);
250 RNA_def_property_struct_type(prop, "WorldMistSettings");
251 RNA_def_property_pointer_funcs(prop, "rna_World_mist_get", nullptr, nullptr, nullptr);
252 RNA_def_property_ui_text(prop, "Mist", "World mist settings");
253
254 /* nodes */
255 prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
256 RNA_def_property_pointer_sdna(prop, nullptr, "nodetree");
259 RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
260
261 prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
262 RNA_def_property_boolean_sdna(prop, nullptr, "use_nodes", 1);
265 RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world");
266 RNA_def_property_update(prop, 0, "rna_World_use_nodes_update");
267
268 /* Lightgroup Membership */
269 prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE);
271 prop, "rna_World_lightgroup_get", "rna_World_lightgroup_length", "rna_World_lightgroup_set");
273 RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the world belongs to");
274
275 /* Reflection Probe Baking. */
276 prop = RNA_def_property(srna, "probe_resolution", PROP_ENUM, PROP_NONE);
277 RNA_def_property_enum_sdna(prop, nullptr, "probe_resolution");
279 RNA_def_property_ui_text(prop, "Resolution", "Resolution when baked to a texture");
280 RNA_def_property_update(prop, 0, "rna_World_draw_update");
281
282 prop = RNA_def_property(srna, "sun_threshold", PROP_FLOAT, PROP_NONE);
284 "Sun Threshold",
285 "If non-zero, the maximum value for world contribution that will be "
286 "recorded inside the world light probe. The excess contribution is "
287 "converted to a sun light. This reduces the light bleeding caused by "
288 "very bright light sources.");
289 RNA_def_property_range(prop, 0.0f, FLT_MAX);
290 RNA_def_property_update(prop, 0, "rna_World_draw_update");
291
292 prop = RNA_def_property(srna, "sun_angle", PROP_FLOAT, PROP_ANGLE);
293 RNA_def_property_range(prop, DEG2RADF(0.0f), DEG2RADF(180.0f));
295 prop, "Sun Angle", "Angular diameter of the Sun as seen from the Earth");
296 RNA_def_property_update(prop, 0, "rna_World_draw_update");
297
298 prop = RNA_def_property(srna, "use_sun_shadow", PROP_BOOLEAN, PROP_NONE);
299 RNA_def_property_boolean_sdna(prop, nullptr, "flag", WO_USE_SUN_SHADOW);
300 RNA_def_property_ui_text(prop, "Use Shadow", "Enable sun shadow casting");
301 RNA_def_property_update(prop, 0, "rna_World_draw_update");
302
303 prop = RNA_def_property(srna, "sun_shadow_maximum_resolution", PROP_FLOAT, PROP_DISTANCE);
304 RNA_def_property_range(prop, 0.0f, FLT_MAX);
305 RNA_def_property_ui_range(prop, 0.0001f, 0.020f, 0.05f, 4);
307 "Shadows Resolution Limit",
308 "Maximum size of a shadow map pixel. Higher values use less memory at "
309 "the cost of shadow quality.");
311 RNA_def_property_update(prop, 0, "rna_World_draw_update");
312
313 prop = RNA_def_property(srna, "sun_shadow_filter_radius", PROP_FLOAT, PROP_NONE);
314 RNA_def_property_range(prop, 0.0f, FLT_MAX);
315 RNA_def_property_ui_range(prop, 0.0f, 5.0f, 1.0f, 2);
317 prop, "Shadow Filter Radius", "Blur shadow aliasing using Percentage Closer Filtering");
319 RNA_def_property_update(prop, 0, "rna_World_draw_update");
320
321 prop = RNA_def_property(srna, "use_sun_shadow_jitter", PROP_BOOLEAN, PROP_NONE);
324 prop,
325 "Shadow Jitter",
326 "Enable jittered soft shadows to increase shadow precision (disabled in viewport unless "
327 "enabled in the render settings). Has a high performance impact.");
329 RNA_def_property_update(prop, 0, "rna_World_draw_update");
330
331 prop = RNA_def_property(srna, "sun_shadow_jitter_overblur", PROP_FLOAT, PROP_PERCENTAGE);
332 RNA_def_property_range(prop, 0.0f, 100.0f);
333 RNA_def_property_ui_range(prop, 0.0f, 20.0f, 10.0f, 0);
335 prop,
336 "Shadow Jitter Overblur",
337 "Apply shadow tracing to each jittered sample to reduce under-sampling artifacts");
339 RNA_def_property_update(prop, 0, "rna_World_draw_update");
340
341 rna_def_lighting(brna);
342 rna_def_world_mist(brna);
343}
344
345#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_USE_SUN_SHADOW
@ WO_USE_EEVEE_FINITE_VOLUME
@ WO_USE_SUN_SHADOW_JITTER
@ WO_MIST
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
@ 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:574
@ PROP_FLOAT
Definition RNA_types.hh:152
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:469
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:381
@ PROP_ANIMATABLE
Definition RNA_types.hh:305
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:369
@ PROP_DISTANCE
Definition RNA_types.hh:244
@ PROP_COLOR
Definition RNA_types.hh:248
@ PROP_ANGLE
Definition RNA_types.hh:240
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_PERCENTAGE
Definition RNA_types.hh:238
@ PROP_FACTOR
Definition RNA_types.hh:239
#define C
Definition RandGen.cpp:29
#define NC_WORLD
Definition WM_types.hh:384
#define ND_WORLD
Definition WM_types.hh:449
#define ND_DRAW
Definition WM_types.hh:458
#define ND_WORLD_DRAW
Definition WM_types.hh:484
#define NC_OBJECT
Definition WM_types.hh:376
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_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:109
void RNA_def_world(BlenderRNA *brna)
Definition rna_world.cc:206
static void rna_def_world_mist(BlenderRNA *brna)
Definition rna_world.cc:145
static void rna_def_lighting(BlenderRNA *brna)
Definition rna_world.cc:119
#define FLT_MAX
Definition stdcycles.h:14
uint len
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4226