Blender V5.3
FX_shader_shadow.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_screen_types.h"
10
11#include "BLI_utildefines.hh"
12
13#include "BLT_translation.hh"
14
15#include "BKE_context.hh"
16#include "BKE_idtype.hh"
17#include "BKE_lib_query.hh"
18#include "BKE_modifier.hh"
19#include "BKE_screen.hh"
20#include "BKE_shader_fx.hh"
21
23#include "UI_resources.hh"
24
25#include "RNA_access.hh"
26
27#include "FX_shader_types.hh"
28#include "FX_ui_common.hh"
29
31
32namespace blender {
33
34static void init_data(ShaderFxData *md)
35{
36 ShadowShaderFxData *gpfx = reinterpret_cast<ShadowShaderFxData *>(md);
37 gpfx->rotation = 0.0f;
38 ARRAY_SET_ITEMS(gpfx->offset, 15, 20);
39 ARRAY_SET_ITEMS(gpfx->scale, 1.0f, 1.0f);
40 ARRAY_SET_ITEMS(gpfx->shadow_rgba, 0.0f, 0.0f, 0.0f, 0.8f);
41
42 gpfx->amplitude = 10.0f;
43 gpfx->period = 20.0f;
44 gpfx->phase = 0.0f;
45 gpfx->orientation = 1;
46
47 ARRAY_SET_ITEMS(gpfx->blur, 5, 5);
48 gpfx->samples = 2;
49
50 gpfx->object = nullptr;
51}
52
53static void copy_data(const ShaderFxData *md, ShaderFxData *target)
54{
56}
57
59{
60 ShadowShaderFxData *fxd = reinterpret_cast<ShadowShaderFxData *>(fx);
61 if (fxd->object != nullptr) {
62 DEG_add_object_relation(ctx->node, fxd->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
63 }
64 DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
65}
66
67static bool is_disabled(ShaderFxData *fx, bool /*use_render_params*/)
68{
69 ShadowShaderFxData *fxd = reinterpret_cast<ShadowShaderFxData *>(fx);
70
71 return (!fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT);
72}
73
74static void foreach_ID_link(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *user_data)
75{
76 ShadowShaderFxData *fxd = reinterpret_cast<ShadowShaderFxData *>(fx);
77
78 walk(user_data, ob, reinterpret_cast<ID **>(&fxd->object), IDWALK_CB_NOP);
79}
80
81static void panel_draw(const bContext * /*C*/, Panel *panel)
82{
83 ui::Layout &layout = *panel->layout;
84
86
87 layout.use_property_split_set(true);
88
89 layout.prop(ptr, "shadow_color", UI_ITEM_NONE, std::nullopt, ICON_NONE);
90 layout.prop(ptr, "offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
91 layout.prop(ptr, "scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
92 layout.prop(ptr, "rotation", UI_ITEM_NONE, std::nullopt, ICON_NONE);
93
94 ui::Layout &row = layout.row(true, IFACE_("Object Pivot"));
95 row.prop(ptr, "use_object", UI_ITEM_NONE, "", ICON_NONE);
96 row.prop(ptr, "object", UI_ITEM_NONE, "", ICON_NONE);
97
98 shaderfx_panel_end(layout, ptr);
99}
100
101static void blur_panel_draw(const bContext * /*C*/, Panel *panel)
102{
103 ui::Layout &layout = *panel->layout;
104
106
107 layout.use_property_split_set(true);
108
109 layout.prop(ptr, "blur", UI_ITEM_NONE, std::nullopt, ICON_NONE);
110 layout.prop(ptr, "samples", UI_ITEM_NONE, std::nullopt, ICON_NONE);
111}
112
113static void wave_header_draw(const bContext * /*C*/, Panel *panel)
114{
115 ui::Layout &layout = *panel->layout;
116
118
119 layout.prop(ptr, "use_wave", UI_ITEM_NONE, IFACE_("Wave Effect"), ICON_NONE);
120}
121
122static void wave_panel_draw(const bContext * /*C*/, Panel *panel)
123{
124 ui::Layout &layout = *panel->layout;
125
127
128 layout.use_property_split_set(true);
129
130 layout.active_set(RNA_boolean_get(ptr, "use_wave"));
131
132 layout.prop(ptr, "orientation", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
133 layout.prop(ptr, "amplitude", UI_ITEM_NONE, std::nullopt, ICON_NONE);
134 layout.prop(ptr, "period", UI_ITEM_NONE, std::nullopt, ICON_NONE);
135 layout.prop(ptr, "phase", UI_ITEM_NONE, std::nullopt, ICON_NONE);
136}
137
138static void panel_register(ARegionType *region_type)
139{
141 shaderfx_subpanel_register(region_type, "blur", "Blur", nullptr, blur_panel_draw, panel_type);
143 region_type, "wave", "", wave_header_draw, wave_panel_draw, panel_type);
144}
145
148{
149 ShadowShaderFxData *fxd = reinterpret_cast<ShadowShaderFxData *>(fx);
150 fn.single(fxd->shadow_rgba);
151}
152
154 /*name*/ N_("Shadow"),
155 /*struct_name*/ "ShadowShaderFxData",
156 /*struct_size*/ sizeof(ShadowShaderFxData),
158 /*flags*/ ShaderFxTypeFlag(0),
159
160 /*copy_data*/ copy_data,
161
162 /*init_data*/ init_data,
163 /*free_data*/ nullptr,
164 /*is_disabled*/ is_disabled,
165 /*update_depsgraph*/ update_depsgraph,
166 /*depends_on_time*/ nullptr,
167 /*foreach_ID_link*/ foreach_ID_link,
168 /*foreach_working_space_color*/ foreach_working_space_color,
169 /*panel_register*/ panel_register,
170};
171
172} // namespace blender
#define IFACE_(msgid)
#define UI_ITEM_NONE
#define ARRAY_SET_ITEMS(...)
BMesh Iterators.
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
ShaderFxTypeInfo shaderfx_Type_Shadow
PanelType * shaderfx_panel_register(ARegionType *region_type, ShaderFxType type, PanelDrawFn draw)
static void foreach_working_space_color(ModifierData *md, const IDTypeForeachColorFunctionCallback &fn)
static void init_data(ModifierData *md)
void(*)(void *user_data, Object *ob, ID **idpoin, LibraryForeachIDCallbackFlag cb_flag) IDWalkFunc
static void update_depsgraph(tGraphSliderOp *gso)
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
static void blur_panel_draw(const bContext *, Panel *panel)
PanelType * shaderfx_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
static void panel_register(ARegionType *region_type)
@ eShaderFxType_GpencilType
void shaderfx_panel_end(ui::Layout &layout, PointerRNA *ptr)
static void wave_panel_draw(const bContext *, Panel *panel)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PointerRNA * shaderfx_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
static void wave_header_draw(const bContext *, Panel *panel)
static void panel_draw(const bContext *, Panel *panel)
void BKE_shaderfx_copydata_generic(const ShaderFxData *fx_src, ShaderFxData *fx_dst)
Definition shader_fx.cc:161
static bool is_disabled(const Scene *, ModifierData *md, bool)
ui::Layout * layout
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & row(bool align)
#define N_(msgid)