Blender  V2.93
FX_shader_shadow.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2018, Blender Foundation
17  * This is a new part of Blender
18  */
19 
24 #include <stdio.h>
25 
26 #include "DNA_gpencil_types.h"
27 #include "DNA_object_types.h"
28 #include "DNA_scene_types.h"
29 #include "DNA_screen_types.h"
30 
31 #include "BLI_utildefines.h"
32 
33 #include "BLT_translation.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_lib_query.h"
37 #include "BKE_modifier.h"
38 #include "BKE_screen.h"
39 #include "BKE_shader_fx.h"
40 
41 #include "UI_interface.h"
42 #include "UI_resources.h"
43 
44 #include "RNA_access.h"
45 
46 #include "FX_shader_types.h"
47 #include "FX_ui_common.h"
48 
49 #include "DEG_depsgraph.h"
50 #include "DEG_depsgraph_build.h"
51 
52 static void initData(ShaderFxData *md)
53 {
55  gpfx->rotation = 0.0f;
56  ARRAY_SET_ITEMS(gpfx->offset, 15, 20);
57  ARRAY_SET_ITEMS(gpfx->scale, 1.0f, 1.0f);
58  ARRAY_SET_ITEMS(gpfx->shadow_rgba, 0.0f, 0.0f, 0.0f, 0.8f);
59 
60  gpfx->amplitude = 10.0f;
61  gpfx->period = 20.0f;
62  gpfx->phase = 0.0f;
63  gpfx->orientation = 1;
64 
65  ARRAY_SET_ITEMS(gpfx->blur, 5, 5);
66  gpfx->samples = 2;
67 
68  gpfx->object = NULL;
69 }
70 
71 static void copyData(const ShaderFxData *md, ShaderFxData *target)
72 {
74 }
75 
77 {
79  if (fxd->object != NULL) {
80  DEG_add_object_relation(ctx->node, fxd->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
81  }
82  DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Shadow ShaderFx");
83 }
84 
85 static bool isDisabled(ShaderFxData *fx, int UNUSED(userRenderParams))
86 {
88 
89  return (!fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT);
90 }
91 
92 static void foreachIDLink(ShaderFxData *fx, Object *ob, IDWalkFunc walk, void *userData)
93 {
95 
96  walk(userData, ob, (ID **)&fxd->object, IDWALK_CB_NOP);
97 }
98 
99 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
100 {
101  uiLayout *row, *col;
102  uiLayout *layout = panel->layout;
103 
105 
106  uiLayoutSetPropSep(layout, true);
107 
108  uiItemR(layout, ptr, "shadow_color", 0, NULL, ICON_NONE);
109 
110  /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
111  col = uiLayoutColumn(layout, true);
112  PropertyRNA *prop = RNA_struct_find_property(ptr, "offset");
113  uiItemFullR(col, ptr, prop, 0, 0, 0, IFACE_("Offset X"), ICON_NONE);
114  uiItemFullR(col, ptr, prop, 1, 0, 0, IFACE_("Y"), ICON_NONE);
115 
116  uiItemR(layout, ptr, "scale", 0, NULL, ICON_NONE);
117  uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
118 
119  row = uiLayoutRowWithHeading(layout, true, IFACE_("Object Pivot"));
120  uiItemR(row, ptr, "use_object", 0, "", ICON_NONE);
121  uiItemR(row, ptr, "object", 0, "", ICON_NONE);
122 
123  shaderfx_panel_end(layout, ptr);
124 }
125 
126 static void blur_panel_draw(const bContext *UNUSED(C), Panel *panel)
127 {
128  uiLayout *col;
129  uiLayout *layout = panel->layout;
130 
132 
133  uiLayoutSetPropSep(layout, true);
134 
135  /* Add the X, Y labels manually because size is a #PROP_PIXEL. */
136  col = uiLayoutColumn(layout, true);
137  PropertyRNA *prop = RNA_struct_find_property(ptr, "blur");
138  uiItemFullR(col, ptr, prop, 0, 0, 0, IFACE_("Blur X"), ICON_NONE);
139  uiItemFullR(col, ptr, prop, 1, 0, 0, IFACE_("Y"), ICON_NONE);
140 
141  uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE);
142 }
143 
144 static void wave_header_draw(const bContext *UNUSED(C), Panel *panel)
145 {
146  uiLayout *layout = panel->layout;
147 
149 
150  uiItemR(layout, ptr, "use_wave", 0, IFACE_("Wave Effect"), ICON_NONE);
151 }
152 
153 static void wave_panel_draw(const bContext *UNUSED(C), Panel *panel)
154 {
155  uiLayout *layout = panel->layout;
156 
158 
159  uiLayoutSetPropSep(layout, true);
160 
161  uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_wave"));
162 
163  uiItemR(layout, ptr, "orientation", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
164  uiItemR(layout, ptr, "amplitude", 0, NULL, ICON_NONE);
165  uiItemR(layout, ptr, "period", 0, NULL, ICON_NONE);
166  uiItemR(layout, ptr, "phase", 0, NULL, ICON_NONE);
167 }
168 
169 static void panelRegister(ARegionType *region_type)
170 {
172  shaderfx_subpanel_register(region_type, "blur", "Blur", NULL, blur_panel_draw, panel_type);
174  region_type, "wave", "", wave_header_draw, wave_panel_draw, panel_type);
175 }
176 
178  /* name */ "Shadow",
179  /* structName */ "ShadowShaderFxData",
180  /* structSize */ sizeof(ShadowShaderFxData),
181  /* type */ eShaderFxType_GpencilType,
182  /* flags */ 0,
183 
184  /* copyData */ copyData,
185 
186  /* initData */ initData,
187  /* freeData */ NULL,
188  /* isDisabled */ isDisabled,
189  /* updateDepsgraph */ updateDepsgraph,
190  /* dependsOnTime */ NULL,
191  /* foreachIDLink */ foreachIDLink,
192  /* panelRegister */ panelRegister,
193 };
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: BKE_modifier.h:120
@ eShaderFxType_GpencilType
Definition: BKE_shader_fx.h:49
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:242
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:273
void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr)
Definition: FX_ui_common.c:99
PointerRNA * shaderfx_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
Definition: FX_ui_common.c:111
#define C
Definition: RandGen.cpp:39
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
void uiLayoutSetActive(uiLayout *layout, bool active)
@ UI_ITEM_R_EXPAND
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
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:866
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
Definition: DNA_ID.h:273
struct DepsNodeHandle * node
Definition: BKE_modifier.h:147
struct uiLayout * layout
struct Object * object
PointerRNA * ptr
Definition: wm_files.c:3157