Blender  V3.3
FX_shader_shadow.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2018 Blender Foundation. */
3 
8 #include <stdio.h>
9 
10 #include "DNA_gpencil_types.h"
11 #include "DNA_object_types.h"
12 #include "DNA_scene_types.h"
13 #include "DNA_screen_types.h"
14 
15 #include "BLI_utildefines.h"
16 
17 #include "BLT_translation.h"
18 
19 #include "BKE_context.h"
20 #include "BKE_lib_query.h"
21 #include "BKE_modifier.h"
22 #include "BKE_screen.h"
23 #include "BKE_shader_fx.h"
24 
25 #include "UI_interface.h"
26 #include "UI_resources.h"
27 
28 #include "RNA_access.h"
29 
30 #include "FX_shader_types.h"
31 #include "FX_ui_common.h"
32 
33 #include "DEG_depsgraph.h"
34 #include "DEG_depsgraph_build.h"
35 
36 static void initData(ShaderFxData *md)
37 {
39  gpfx->rotation = 0.0f;
40  ARRAY_SET_ITEMS(gpfx->offset, 15, 20);
41  ARRAY_SET_ITEMS(gpfx->scale, 1.0f, 1.0f);
42  ARRAY_SET_ITEMS(gpfx->shadow_rgba, 0.0f, 0.0f, 0.0f, 0.8f);
43 
44  gpfx->amplitude = 10.0f;
45  gpfx->period = 20.0f;
46  gpfx->phase = 0.0f;
47  gpfx->orientation = 1;
48 
49  ARRAY_SET_ITEMS(gpfx->blur, 5, 5);
50  gpfx->samples = 2;
51 
52  gpfx->object = NULL;
53 }
54 
55 static void copyData(const ShaderFxData *md, ShaderFxData *target)
56 {
58 }
59 
61 {
63  if (fxd->object != NULL) {
64  DEG_add_object_relation(ctx->node, fxd->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
65  }
66  DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
67 }
68 
69 static bool isDisabled(ShaderFxData *fx, int UNUSED(userRenderParams))
70 {
72 
73  return (!fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT);
74 }
75 
76 static void foreachIDLink(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *userData)
77 {
79 
80  walk(userData, ob, (ID **)&fxd->object, IDWALK_CB_NOP);
81 }
82 
83 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
84 {
85  uiLayout *row, *col;
86  uiLayout *layout = panel->layout;
87 
89 
90  uiLayoutSetPropSep(layout, true);
91 
92  uiItemR(layout, ptr, "shadow_color", 0, NULL, ICON_NONE);
93 
94  /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
95  col = uiLayoutColumn(layout, true);
96  PropertyRNA *prop = RNA_struct_find_property(ptr, "offset");
97  uiItemFullR(col, ptr, prop, 0, 0, 0, IFACE_("Offset X"), ICON_NONE);
98  uiItemFullR(col, ptr, prop, 1, 0, 0, IFACE_("Y"), ICON_NONE);
99 
100  uiItemR(layout, ptr, "scale", 0, NULL, ICON_NONE);
101  uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
102 
103  row = uiLayoutRowWithHeading(layout, true, IFACE_("Object Pivot"));
104  uiItemR(row, ptr, "use_object", 0, "", ICON_NONE);
105  uiItemR(row, ptr, "object", 0, "", ICON_NONE);
106 
107  shaderfx_panel_end(layout, ptr);
108 }
109 
110 static void blur_panel_draw(const bContext *UNUSED(C), Panel *panel)
111 {
112  uiLayout *col;
113  uiLayout *layout = panel->layout;
114 
116 
117  uiLayoutSetPropSep(layout, true);
118 
119  /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
120  col = uiLayoutColumn(layout, true);
121  PropertyRNA *prop = RNA_struct_find_property(ptr, "blur");
122  uiItemFullR(col, ptr, prop, 0, 0, 0, IFACE_("Blur X"), ICON_NONE);
123  uiItemFullR(col, ptr, prop, 1, 0, 0, IFACE_("Y"), ICON_NONE);
124 
125  uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE);
126 }
127 
128 static void wave_header_draw(const bContext *UNUSED(C), Panel *panel)
129 {
130  uiLayout *layout = panel->layout;
131 
133 
134  uiItemR(layout, ptr, "use_wave", 0, IFACE_("Wave Effect"), ICON_NONE);
135 }
136 
137 static void wave_panel_draw(const bContext *UNUSED(C), Panel *panel)
138 {
139  uiLayout *layout = panel->layout;
140 
142 
143  uiLayoutSetPropSep(layout, true);
144 
145  uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_wave"));
146 
147  uiItemR(layout, ptr, "orientation", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
148  uiItemR(layout, ptr, "amplitude", 0, NULL, ICON_NONE);
149  uiItemR(layout, ptr, "period", 0, NULL, ICON_NONE);
150  uiItemR(layout, ptr, "phase", 0, NULL, ICON_NONE);
151 }
152 
153 static void panelRegister(ARegionType *region_type)
154 {
156  shaderfx_subpanel_register(region_type, "blur", "Blur", NULL, blur_panel_draw, panel_type);
158  region_type, "wave", "", wave_header_draw, wave_panel_draw, panel_type);
159 }
160 
162  /* name */ N_("Shadow"),
163  /* structName */ "ShadowShaderFxData",
164  /* structSize */ sizeof(ShadowShaderFxData),
165  /* type */ eShaderFxType_GpencilType,
166  /* flags */ 0,
167 
168  /* copyData */ copyData,
169 
170  /* initData */ initData,
171  /* freeData */ NULL,
172  /* isDisabled */ isDisabled,
173  /* updateDepsgraph */ updateDepsgraph,
174  /* dependsOnTime */ NULL,
175  /* foreachIDLink */ foreachIDLink,
176  /* panelRegister */ panelRegister,
177 };
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:33
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: BKE_modifier.h:107
@ eShaderFxType_GpencilType
Definition: BKE_shader_fx.h:35
void BKE_shaderfx_copydata_generic(const struct ShaderFxData *fx_src, struct ShaderFxData *fx_dst)
#define ARRAY_SET_ITEMS(...)
#define UNUSED(x)
#define IFACE_(msgid)
void DEG_add_object_relation(struct DepsNodeHandle *node_handle, struct 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 initData(ShaderFxData *md)
static void updateDepsgraph(ShaderFxData *fx, const ModifierUpdateDepsgraphContext *ctx)
ShaderFxTypeInfo shaderfx_Type_Shadow
static void wave_header_draw(const bContext *UNUSED(C), Panel *panel)
static void wave_panel_draw(const bContext *UNUSED(C), Panel *panel)
static bool isDisabled(ShaderFxData *fx, int UNUSED(userRenderParams))
static void blur_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void panelRegister(ARegionType *region_type)
static void foreachIDLink(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *userData)
static void copyData(const ShaderFxData *md, ShaderFxData *target)
PanelType * shaderfx_panel_register(ARegionType *region_type, ShaderFxType type, PanelDrawFn draw)
Definition: FX_ui_common.c:223
PanelType * shaderfx_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
Definition: FX_ui_common.c:248
void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr)
Definition: FX_ui_common.c:84
PointerRNA * shaderfx_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
Definition: FX_ui_common.c:93
#define C
Definition: RandGen.cpp:25
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
void uiLayoutSetActive(uiLayout *layout, bool active)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiItemFullR(uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag, const char *name, int icon)
uint col
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
Definition: DNA_ID.h:368
struct DepsNodeHandle * node
Definition: BKE_modifier.h:134
struct uiLayout * layout
struct Object * object
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480