Blender V4.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
9#include <cstdio>
10
12#include "DNA_object_types.h"
13#include "DNA_scene_types.h"
14#include "DNA_screen_types.h"
15
16#include "BLI_utildefines.h"
17
18#include "BLT_translation.hh"
19
20#include "BKE_context.hh"
21#include "BKE_lib_query.hh"
22#include "BKE_modifier.hh"
23#include "BKE_screen.hh"
24#include "BKE_shader_fx.h"
25
26#include "UI_interface.hh"
27#include "UI_resources.hh"
28
29#include "RNA_access.hh"
30
31#include "FX_shader_types.h"
32#include "FX_ui_common.h"
33
34#include "DEG_depsgraph.hh"
36
37static void init_data(ShaderFxData *md)
38{
40 gpfx->rotation = 0.0f;
41 ARRAY_SET_ITEMS(gpfx->offset, 15, 20);
42 ARRAY_SET_ITEMS(gpfx->scale, 1.0f, 1.0f);
43 ARRAY_SET_ITEMS(gpfx->shadow_rgba, 0.0f, 0.0f, 0.0f, 0.8f);
44
45 gpfx->amplitude = 10.0f;
46 gpfx->period = 20.0f;
47 gpfx->phase = 0.0f;
48 gpfx->orientation = 1;
49
50 ARRAY_SET_ITEMS(gpfx->blur, 5, 5);
51 gpfx->samples = 2;
52
53 gpfx->object = nullptr;
54}
55
56static void copy_data(const ShaderFxData *md, ShaderFxData *target)
57{
59}
60
62{
64 if (fxd->object != nullptr) {
65 DEG_add_object_relation(ctx->node, fxd->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
66 }
67 DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
68}
69
70static bool is_disabled(ShaderFxData *fx, bool /*use_render_params*/)
71{
73
74 return (!fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT);
75}
76
77static void foreach_ID_link(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *user_data)
78{
80
81 walk(user_data, ob, (ID **)&fxd->object, IDWALK_CB_NOP);
82}
83
84static void panel_draw(const bContext * /*C*/, Panel *panel)
85{
86 uiLayout *row, *col;
87 uiLayout *layout = panel->layout;
88
90
91 uiLayoutSetPropSep(layout, true);
92
93 uiItemR(layout, ptr, "shadow_color", UI_ITEM_NONE, nullptr, ICON_NONE);
94
95 /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
96 col = uiLayoutColumn(layout, true);
97 PropertyRNA *prop = RNA_struct_find_property(ptr, "offset");
98 uiItemFullR(col, ptr, prop, 0, 0, UI_ITEM_NONE, IFACE_("Offset X"), ICON_NONE);
99 uiItemFullR(col, ptr, prop, 1, 0, UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
100
101 uiItemR(layout, ptr, "scale", UI_ITEM_NONE, nullptr, ICON_NONE);
102 uiItemR(layout, ptr, "rotation", UI_ITEM_NONE, nullptr, ICON_NONE);
103
104 row = uiLayoutRowWithHeading(layout, true, IFACE_("Object Pivot"));
105 uiItemR(row, ptr, "use_object", UI_ITEM_NONE, "", ICON_NONE);
106 uiItemR(row, ptr, "object", UI_ITEM_NONE, "", ICON_NONE);
107
108 shaderfx_panel_end(layout, ptr);
109}
110
111static void blur_panel_draw(const bContext * /*C*/, Panel *panel)
112{
113 uiLayout *col;
114 uiLayout *layout = panel->layout;
115
117
118 uiLayoutSetPropSep(layout, true);
119
120 /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
121 col = uiLayoutColumn(layout, true);
123 uiItemFullR(col, ptr, prop, 0, 0, UI_ITEM_NONE, IFACE_("Blur X"), ICON_NONE);
124 uiItemFullR(col, ptr, prop, 1, 0, UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
125
126 uiItemR(layout, ptr, "samples", UI_ITEM_NONE, nullptr, ICON_NONE);
127}
128
129static void wave_header_draw(const bContext * /*C*/, Panel *panel)
130{
131 uiLayout *layout = panel->layout;
132
134
135 uiItemR(layout, ptr, "use_wave", UI_ITEM_NONE, IFACE_("Wave Effect"), ICON_NONE);
136}
137
138static void wave_panel_draw(const bContext * /*C*/, Panel *panel)
139{
140 uiLayout *layout = panel->layout;
141
143
144 uiLayoutSetPropSep(layout, true);
145
146 uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_wave"));
147
148 uiItemR(layout, ptr, "orientation", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
149 uiItemR(layout, ptr, "amplitude", UI_ITEM_NONE, nullptr, ICON_NONE);
150 uiItemR(layout, ptr, "period", UI_ITEM_NONE, nullptr, ICON_NONE);
151 uiItemR(layout, ptr, "phase", UI_ITEM_NONE, nullptr, ICON_NONE);
152}
153
154static void panel_register(ARegionType *region_type)
155{
157 shaderfx_subpanel_register(region_type, "blur", "Blur", nullptr, blur_panel_draw, panel_type);
159 region_type, "wave", "", wave_header_draw, wave_panel_draw, panel_type);
160}
161
163 /*name*/ N_("Shadow"),
164 /*struct_name*/ "ShadowShaderFxData",
165 /*struct_size*/ sizeof(ShadowShaderFxData),
167 /*flags*/ ShaderFxTypeFlag(0),
168
169 /*copy_data*/ copy_data,
170
171 /*init_data*/ init_data,
172 /*free_data*/ nullptr,
173 /*is_disabled*/ is_disabled,
174 /*update_depsgraph*/ update_depsgraph,
175 /*depends_on_time*/ nullptr,
176 /*foreach_ID_link*/ foreach_ID_link,
177 /*panel_register*/ panel_register,
178};
@ IDWALK_CB_NOP
void(*)(void *user_data, Object *ob, ID **idpoin, int cb_flag) IDWalkFunc
@ eShaderFxType_GpencilType
void BKE_shaderfx_copydata_generic(const struct ShaderFxData *fx_src, struct ShaderFxData *fx_dst)
ShaderFxTypeFlag
#define ARRAY_SET_ITEMS(...)
#define IFACE_(msgid)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
@ DEG_OB_COMP_TRANSFORM
Object is a sort of wrapper for general info.
@ FX_SHADOW_USE_OBJECT
struct ShadowShaderFxData ShadowShaderFxData
@ eShaderFxType_Shadow
static void wave_panel_draw(const bContext *, Panel *panel)
static void panel_register(ARegionType *region_type)
ShaderFxTypeInfo shaderfx_Type_Shadow
static void blur_panel_draw(const bContext *, Panel *panel)
static void foreach_ID_link(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *user_data)
static void update_depsgraph(ShaderFxData *fx, const ModifierUpdateDepsgraphContext *ctx)
static void panel_draw(const bContext *, Panel *panel)
static void init_data(ShaderFxData *md)
static void copy_data(const ShaderFxData *md, ShaderFxData *target)
static void wave_header_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)
PanelType * shaderfx_panel_register(ARegionType *region_type, ShaderFxType type, PanelDrawFn draw)
void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr)
PointerRNA * shaderfx_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
static bool is_disabled
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, const char *name, int icon, const char *placeholder=nullptr)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
#define UI_ITEM_NONE
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
uint col
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition DNA_ID.h:413
struct uiLayout * layout
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126