1 | /**************************************************************************/ |
2 | /* visual_shader_particle_nodes.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef VISUAL_SHADER_PARTICLE_NODES_H |
32 | #define VISUAL_SHADER_PARTICLE_NODES_H |
33 | |
34 | #include "scene/resources/visual_shader.h" |
35 | |
36 | class ImageTexture; |
37 | |
38 | // Emit nodes |
39 | |
40 | class VisualShaderNodeParticleEmitter : public VisualShaderNode { |
41 | GDCLASS(VisualShaderNodeParticleEmitter, VisualShaderNode); |
42 | |
43 | protected: |
44 | bool mode_2d = false; |
45 | static void _bind_methods(); |
46 | |
47 | public: |
48 | virtual int get_output_port_count() const override; |
49 | virtual PortType get_output_port_type(int p_port) const override; |
50 | virtual String get_output_port_name(int p_port) const override; |
51 | virtual bool has_output_port_preview(int p_port) const override; |
52 | |
53 | virtual void set_mode_2d(bool p_enabled); |
54 | bool is_mode_2d() const; |
55 | |
56 | Vector<StringName> get_editable_properties() const override; |
57 | virtual HashMap<StringName, String> get_editable_properties_names() const override; |
58 | bool is_show_prop_names() const override; |
59 | |
60 | VisualShaderNodeParticleEmitter(); |
61 | }; |
62 | |
63 | class VisualShaderNodeParticleSphereEmitter : public VisualShaderNodeParticleEmitter { |
64 | GDCLASS(VisualShaderNodeParticleSphereEmitter, VisualShaderNodeParticleEmitter); |
65 | |
66 | public: |
67 | virtual String get_caption() const override; |
68 | |
69 | virtual int get_input_port_count() const override; |
70 | virtual PortType get_input_port_type(int p_port) const override; |
71 | virtual String get_input_port_name(int p_port) const override; |
72 | |
73 | virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; |
74 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
75 | |
76 | VisualShaderNodeParticleSphereEmitter(); |
77 | }; |
78 | |
79 | class VisualShaderNodeParticleBoxEmitter : public VisualShaderNodeParticleEmitter { |
80 | GDCLASS(VisualShaderNodeParticleBoxEmitter, VisualShaderNodeParticleEmitter); |
81 | |
82 | public: |
83 | virtual String get_caption() const override; |
84 | |
85 | virtual int get_input_port_count() const override; |
86 | virtual PortType get_input_port_type(int p_port) const override; |
87 | virtual String get_input_port_name(int p_port) const override; |
88 | virtual void set_mode_2d(bool p_enabled) override; |
89 | |
90 | virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; |
91 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
92 | |
93 | VisualShaderNodeParticleBoxEmitter(); |
94 | }; |
95 | |
96 | class VisualShaderNodeParticleRingEmitter : public VisualShaderNodeParticleEmitter { |
97 | GDCLASS(VisualShaderNodeParticleRingEmitter, VisualShaderNodeParticleEmitter); |
98 | |
99 | public: |
100 | virtual String get_caption() const override; |
101 | |
102 | virtual int get_input_port_count() const override; |
103 | virtual PortType get_input_port_type(int p_port) const override; |
104 | virtual String get_input_port_name(int p_port) const override; |
105 | |
106 | virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; |
107 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
108 | |
109 | VisualShaderNodeParticleRingEmitter(); |
110 | }; |
111 | |
112 | class VisualShaderNodeParticleMeshEmitter : public VisualShaderNodeParticleEmitter { |
113 | GDCLASS(VisualShaderNodeParticleMeshEmitter, VisualShaderNodeParticleEmitter); |
114 | Ref<Mesh> mesh; |
115 | bool use_all_surfaces = true; |
116 | int surface_index = 0; |
117 | |
118 | Ref<ImageTexture> position_texture; |
119 | Ref<ImageTexture> normal_texture; |
120 | Ref<ImageTexture> color_texture; |
121 | Ref<ImageTexture> uv_texture; |
122 | Ref<ImageTexture> uv2_texture; |
123 | |
124 | String _generate_code(VisualShader::Type p_type, int p_id, const String *p_output_vars, int p_index, const String &p_texture_name, PortType p_port_type) const; |
125 | |
126 | void _update_texture(const Vector<Vector2> &p_array, Ref<ImageTexture> &r_texture); |
127 | void _update_texture(const Vector<Vector3> &p_array, Ref<ImageTexture> &r_texture); |
128 | void _update_texture(const Vector<Color> &p_array, Ref<ImageTexture> &r_texture); |
129 | void _update_textures(); |
130 | |
131 | protected: |
132 | static void _bind_methods(); |
133 | |
134 | public: |
135 | virtual String get_caption() const override; |
136 | |
137 | virtual int get_output_port_count() const override; |
138 | virtual PortType get_output_port_type(int p_port) const override; |
139 | virtual String get_output_port_name(int p_port) const override; |
140 | |
141 | virtual int get_input_port_count() const override; |
142 | virtual PortType get_input_port_type(int p_port) const override; |
143 | virtual String get_input_port_name(int p_port) const override; |
144 | |
145 | virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override; |
146 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
147 | |
148 | void set_mesh(Ref<Mesh> p_mesh); |
149 | Ref<Mesh> get_mesh() const; |
150 | |
151 | void set_use_all_surfaces(bool p_enabled); |
152 | bool is_use_all_surfaces() const; |
153 | |
154 | void set_surface_index(int p_surface_index); |
155 | int get_surface_index() const; |
156 | |
157 | Vector<StringName> get_editable_properties() const override; |
158 | HashMap<StringName, String> get_editable_properties_names() const override; |
159 | Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override; |
160 | |
161 | VisualShaderNodeParticleMeshEmitter(); |
162 | }; |
163 | |
164 | class VisualShaderNodeParticleMultiplyByAxisAngle : public VisualShaderNode { |
165 | GDCLASS(VisualShaderNodeParticleMultiplyByAxisAngle, VisualShaderNode); |
166 | bool degrees_mode = true; |
167 | |
168 | protected: |
169 | static void _bind_methods(); |
170 | |
171 | public: |
172 | virtual String get_caption() const override; |
173 | |
174 | virtual int get_input_port_count() const override; |
175 | virtual PortType get_input_port_type(int p_port) const override; |
176 | virtual String get_input_port_name(int p_port) const override; |
177 | virtual bool is_show_prop_names() const override; |
178 | |
179 | virtual int get_output_port_count() const override; |
180 | virtual PortType get_output_port_type(int p_port) const override; |
181 | virtual String get_output_port_name(int p_port) const override; |
182 | virtual bool has_output_port_preview(int p_port) const override; |
183 | |
184 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
185 | |
186 | void set_degrees_mode(bool p_enabled); |
187 | bool is_degrees_mode() const; |
188 | Vector<StringName> get_editable_properties() const override; |
189 | |
190 | VisualShaderNodeParticleMultiplyByAxisAngle(); |
191 | }; |
192 | |
193 | class VisualShaderNodeParticleConeVelocity : public VisualShaderNode { |
194 | GDCLASS(VisualShaderNodeParticleConeVelocity, VisualShaderNode); |
195 | |
196 | public: |
197 | virtual String get_caption() const override; |
198 | |
199 | virtual int get_input_port_count() const override; |
200 | virtual PortType get_input_port_type(int p_port) const override; |
201 | virtual String get_input_port_name(int p_port) const override; |
202 | |
203 | virtual int get_output_port_count() const override; |
204 | virtual PortType get_output_port_type(int p_port) const override; |
205 | virtual String get_output_port_name(int p_port) const override; |
206 | virtual bool has_output_port_preview(int p_port) const override; |
207 | |
208 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
209 | |
210 | VisualShaderNodeParticleConeVelocity(); |
211 | }; |
212 | |
213 | class VisualShaderNodeParticleRandomness : public VisualShaderNode { |
214 | GDCLASS(VisualShaderNodeParticleRandomness, VisualShaderNode); |
215 | |
216 | public: |
217 | enum OpType { |
218 | OP_TYPE_SCALAR, |
219 | OP_TYPE_VECTOR_2D, |
220 | OP_TYPE_VECTOR_3D, |
221 | OP_TYPE_VECTOR_4D, |
222 | OP_TYPE_MAX, |
223 | }; |
224 | |
225 | private: |
226 | OpType op_type = OP_TYPE_SCALAR; |
227 | |
228 | protected: |
229 | static void _bind_methods(); |
230 | |
231 | public: |
232 | Vector<StringName> get_editable_properties() const override; |
233 | virtual String get_caption() const override; |
234 | |
235 | virtual int get_input_port_count() const override; |
236 | virtual PortType get_input_port_type(int p_port) const override; |
237 | virtual String get_input_port_name(int p_port) const override; |
238 | virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override; |
239 | |
240 | virtual int get_output_port_count() const override; |
241 | virtual PortType get_output_port_type(int p_port) const override; |
242 | virtual String get_output_port_name(int p_port) const override; |
243 | virtual bool has_output_port_preview(int p_port) const override; |
244 | |
245 | virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; |
246 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
247 | |
248 | void set_op_type(OpType p_type); |
249 | OpType get_op_type() const; |
250 | |
251 | VisualShaderNodeParticleRandomness(); |
252 | }; |
253 | |
254 | VARIANT_ENUM_CAST(VisualShaderNodeParticleRandomness::OpType) |
255 | |
256 | // Process nodes |
257 | |
258 | class VisualShaderNodeParticleAccelerator : public VisualShaderNode { |
259 | GDCLASS(VisualShaderNodeParticleAccelerator, VisualShaderNode); |
260 | |
261 | public: |
262 | enum Mode { |
263 | MODE_LINEAR, |
264 | MODE_RADIAL, |
265 | MODE_TANGENTIAL, |
266 | MODE_MAX, |
267 | }; |
268 | |
269 | private: |
270 | Mode mode = MODE_LINEAR; |
271 | |
272 | protected: |
273 | static void _bind_methods(); |
274 | |
275 | public: |
276 | Vector<StringName> get_editable_properties() const override; |
277 | virtual String get_caption() const override; |
278 | |
279 | virtual int get_input_port_count() const override; |
280 | virtual PortType get_input_port_type(int p_port) const override; |
281 | virtual String get_input_port_name(int p_port) const override; |
282 | |
283 | virtual int get_output_port_count() const override; |
284 | virtual PortType get_output_port_type(int p_port) const override; |
285 | virtual String get_output_port_name(int p_port) const override; |
286 | virtual bool has_output_port_preview(int p_port) const override; |
287 | |
288 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
289 | |
290 | void set_mode(Mode p_mode); |
291 | Mode get_mode() const; |
292 | |
293 | VisualShaderNodeParticleAccelerator(); |
294 | }; |
295 | |
296 | VARIANT_ENUM_CAST(VisualShaderNodeParticleAccelerator::Mode) |
297 | |
298 | // Common nodes |
299 | |
300 | class VisualShaderNodeParticleOutput : public VisualShaderNodeOutput { |
301 | GDCLASS(VisualShaderNodeParticleOutput, VisualShaderNodeOutput); |
302 | |
303 | public: |
304 | virtual String get_caption() const override; |
305 | |
306 | virtual int get_input_port_count() const override; |
307 | virtual PortType get_input_port_type(int p_port) const override; |
308 | virtual String get_input_port_name(int p_port) const override; |
309 | virtual bool is_port_separator(int p_index) const override; |
310 | |
311 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
312 | |
313 | VisualShaderNodeParticleOutput(); |
314 | }; |
315 | |
316 | class VisualShaderNodeParticleEmit : public VisualShaderNode { |
317 | GDCLASS(VisualShaderNodeParticleEmit, VisualShaderNode); |
318 | |
319 | public: |
320 | enum EmitFlags { |
321 | EMIT_FLAG_POSITION = 1, |
322 | EMIT_FLAG_ROT_SCALE = 2, |
323 | EMIT_FLAG_VELOCITY = 4, |
324 | EMIT_FLAG_COLOR = 8, |
325 | EMIT_FLAG_CUSTOM = 16, |
326 | }; |
327 | |
328 | protected: |
329 | int flags = EMIT_FLAG_POSITION | EMIT_FLAG_ROT_SCALE | EMIT_FLAG_VELOCITY | EMIT_FLAG_COLOR | EMIT_FLAG_CUSTOM; |
330 | static void _bind_methods(); |
331 | |
332 | public: |
333 | Vector<StringName> get_editable_properties() const override; |
334 | virtual String get_caption() const override; |
335 | |
336 | virtual int get_input_port_count() const override; |
337 | virtual PortType get_input_port_type(int p_port) const override; |
338 | virtual String get_input_port_name(int p_port) const override; |
339 | |
340 | virtual int get_output_port_count() const override; |
341 | virtual PortType get_output_port_type(int p_port) const override; |
342 | virtual String get_output_port_name(int p_port) const override; |
343 | |
344 | void add_flag(EmitFlags p_flag); |
345 | bool has_flag(EmitFlags p_flag) const; |
346 | |
347 | void set_flags(EmitFlags p_flags); |
348 | EmitFlags get_flags() const; |
349 | |
350 | virtual bool is_show_prop_names() const override; |
351 | virtual bool is_generate_input_var(int p_port) const override; |
352 | virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override; |
353 | virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; |
354 | |
355 | VisualShaderNodeParticleEmit(); |
356 | }; |
357 | |
358 | VARIANT_ENUM_CAST(VisualShaderNodeParticleEmit::EmitFlags) |
359 | |
360 | #endif // VISUAL_SHADER_PARTICLE_NODES_H |
361 | |