diff options
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 33 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.h | 8 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs | 28 | ||||
-rw-r--r-- | modules/mono/glue/callable_glue.cpp | 79 | ||||
-rw-r--r-- | modules/mono/glue/glue_header.h | 2 | ||||
-rw-r--r-- | scene/resources/visual_shader.cpp | 14 |
6 files changed, 158 insertions, 6 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index d0f3da8d81..6d023b8a7d 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1426,13 +1426,23 @@ void VisualShaderEditor::_set_mode(int p_which) { edit_type_standard->set_visible(false); edit_type_particles->set_visible(false); edit_type_sky->set_visible(true); + edit_type_fog->set_visible(false); edit_type = edit_type_sky; custom_mode_box->set_visible(false); mode = MODE_FLAGS_SKY; + } else if (p_which == VisualShader::MODE_FOG) { + edit_type_standard->set_visible(false); + edit_type_particles->set_visible(false); + edit_type_sky->set_visible(false); + edit_type_fog->set_visible(true); + edit_type = edit_type_fog; + custom_mode_box->set_visible(false); + mode = MODE_FLAGS_FOG; } else if (p_which == VisualShader::MODE_PARTICLES) { edit_type_standard->set_visible(false); edit_type_particles->set_visible(true); edit_type_sky->set_visible(false); + edit_type_fog->set_visible(false); edit_type = edit_type_particles; if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) { custom_mode_box->set_visible(false); @@ -1444,6 +1454,7 @@ void VisualShaderEditor::_set_mode(int p_which) { edit_type_particles->set_visible(false); edit_type_standard->set_visible(true); edit_type_sky->set_visible(false); + edit_type_fog->set_visible(false); edit_type = edit_type_standard; custom_mode_box->set_visible(false); mode = MODE_FLAGS_SPATIAL_CANVASITEM; @@ -1601,6 +1612,8 @@ VisualShader::Type VisualShaderEditor::get_current_shader_type() const { type = VisualShader::Type(edit_type->get_selected() + 3 + (custom_mode_enabled ? 3 : 0)); } else if (mode & MODE_FLAGS_SKY) { type = VisualShader::Type(edit_type->get_selected() + 8); + } else if (mode & MODE_FLAGS_FOG) { + type = VisualShader::Type(edit_type->get_selected() + 9); } else { type = VisualShader::Type(edit_type->get_selected()); } @@ -3520,6 +3533,8 @@ void VisualShaderEditor::_mode_selected(int p_id) { } } else if (mode & MODE_FLAGS_SKY) { offset = 8; + } else if (mode & MODE_FLAGS_FOG) { + offset = 9; } visual_shader->set_shader_type(VisualShader::Type(p_id + offset)); @@ -4062,6 +4077,11 @@ VisualShaderEditor::VisualShaderEditor() { edit_type_sky->select(0); edit_type_sky->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected)); + edit_type_fog = memnew(OptionButton); + edit_type_fog->add_item(TTR("Fog")); + edit_type_fog->select(0); + edit_type_fog->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected)); + edit_type = edit_type_standard; graph->get_zoom_hbox()->add_child(custom_mode_box); @@ -4072,6 +4092,8 @@ VisualShaderEditor::VisualShaderEditor() { graph->get_zoom_hbox()->move_child(edit_type_particles, 0); graph->get_zoom_hbox()->add_child(edit_type_sky); graph->get_zoom_hbox()->move_child(edit_type_sky, 0); + graph->get_zoom_hbox()->add_child(edit_type_fog); + graph->get_zoom_hbox()->move_child(edit_type_fog, 0); add_node = memnew(Button); add_node->set_flat(true); @@ -4340,6 +4362,7 @@ VisualShaderEditor::VisualShaderEditor() { const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes."); const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode."); const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode."); + const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode."); const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode."); const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode."); const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode."); @@ -4459,6 +4482,16 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("SkyCoords", "Input", "Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "sky_coords"), "sky_coords", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); add_options.push_back(AddOption("Time", "Input", "Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); + // FOG INPUTS + + add_options.push_back(AddOption("WorldPosition", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "world_position"), "world_position", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("ObjectPosition", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "object_position"), "object_position", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("UVW", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "uvw"), "uvw", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("Extents", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "extents"), "extents", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("Transform", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "transform"), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("SDF", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "sdf"), "sdf", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + add_options.push_back(AddOption("Time", "Input", "Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); + // PARTICLES INPUTS add_options.push_back(AddOption("CollisionDepth", "Input", "Collide", "VisualShaderNodeInput", vformat(input_param_for_collide_shader_mode, "collision_depth"), "collision_depth", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 5788959a77..58bbcb7113 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -145,6 +145,7 @@ class VisualShaderEditor : public VBoxContainer { OptionButton *edit_type_standard; OptionButton *edit_type_particles; OptionButton *edit_type_sky; + OptionButton *edit_type_fog; CheckBox *custom_mode_box; bool custom_mode_enabled = false; @@ -180,7 +181,8 @@ class VisualShaderEditor : public VBoxContainer { enum ShaderModeFlags { MODE_FLAGS_SPATIAL_CANVASITEM = 1, MODE_FLAGS_SKY = 2, - MODE_FLAGS_PARTICLES = 4 + MODE_FLAGS_PARTICLES = 4, + MODE_FLAGS_FOG = 8, }; int mode = MODE_FLAGS_SPATIAL_CANVASITEM; @@ -203,6 +205,10 @@ class VisualShaderEditor : public VBoxContainer { TYPE_FLAGS_SKY = 1, }; + enum FogTypeFlags { + TYPE_FLAGS_FOG = 1, + }; + enum ToolsMenuOptions { EXPAND_ALL, COLLAPSE_ALL diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs index a28a46896b..2722b64e6d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace Godot { @@ -71,5 +72,32 @@ namespace Godot _method = null; _delegate = @delegate; } + + /// <summary> + /// Calls the method represented by this <see cref="Callable"/>. + /// Arguments can be passed and should match the method's signature. + /// </summary> + /// <param name="args">Arguments that will be passed to the method call.</param> + /// <returns>The value returned by the method.</returns> + public object Call(params object[] args) + { + return godot_icall_Callable_Call(ref this, args); + } + + /// <summary> + /// Calls the method represented by this <see cref="Callable"/> in deferred mode, i.e. during the idle frame. + /// Arguments can be passed and should match the method's signature. + /// </summary> + /// <param name="args">Arguments that will be passed to the method call.</param> + public void CallDeferred(params object[] args) + { + godot_icall_Callable_CallDeferred(ref this, args); + } + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern object godot_icall_Callable_Call(ref Callable callable, object[] args); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void godot_icall_Callable_CallDeferred(ref Callable callable, object[] args); } } diff --git a/modules/mono/glue/callable_glue.cpp b/modules/mono/glue/callable_glue.cpp new file mode 100644 index 0000000000..54b65fdb94 --- /dev/null +++ b/modules/mono/glue/callable_glue.cpp @@ -0,0 +1,79 @@ +/*************************************************************************/ +/* callable_glue.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef MONO_GLUE_ENABLED + +#include "../mono_gd/gd_mono_marshal.h" +#include "arguments_vector.h" + +MonoObject *godot_icall_Callable_Call(GDMonoMarshal::M_Callable *p_callable, MonoArray *p_args) { + Callable callable = GDMonoMarshal::managed_to_callable(*p_callable); + + int argc = mono_array_length(p_args); + + ArgumentsVector<Variant> arg_store(argc); + ArgumentsVector<const Variant *> args(argc); + + for (int i = 0; i < argc; i++) { + MonoObject *elem = mono_array_get(p_args, MonoObject *, i); + arg_store.set(i, GDMonoMarshal::mono_object_to_variant(elem)); + args.set(i, &arg_store.get(i)); + } + + Variant result; + Callable::CallError error; + callable.call(args.ptr(), argc, result, error); + + return GDMonoMarshal::variant_to_mono_object(result); +} + +void godot_icall_Callable_CallDeferred(GDMonoMarshal::M_Callable *p_callable, MonoArray *p_args) { + Callable callable = GDMonoMarshal::managed_to_callable(*p_callable); + + int argc = mono_array_length(p_args); + + ArgumentsVector<Variant> arg_store(argc); + ArgumentsVector<const Variant *> args(argc); + + for (int i = 0; i < argc; i++) { + MonoObject *elem = mono_array_get(p_args, MonoObject *, i); + arg_store.set(i, GDMonoMarshal::mono_object_to_variant(elem)); + args.set(i, &arg_store.get(i)); + } + + callable.call_deferred(args.ptr(), argc); +} + +void godot_register_callable_icalls() { + GDMonoUtils::add_internal_call("Godot.Callable::godot_icall_Callable_Call", godot_icall_Callable_Call); + GDMonoUtils::add_internal_call("Godot.Callable::godot_icall_Callable_CallDeferred", godot_icall_Callable_CallDeferred); +} + +#endif // MONO_GLUE_ENABLED diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h index eed3bd2167..074220bb9b 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -36,6 +36,7 @@ void godot_register_collections_icalls(); void godot_register_gd_icalls(); void godot_register_string_name_icalls(); void godot_register_nodepath_icalls(); +void godot_register_callable_icalls(); void godot_register_object_icalls(); void godot_register_rid_icalls(); void godot_register_string_icalls(); @@ -50,6 +51,7 @@ void godot_register_glue_header_icalls() { godot_register_gd_icalls(); godot_register_string_name_icalls(); godot_register_nodepath_icalls(); + godot_register_callable_icalls(); godot_register_object_icalls(); godot_register_rid_icalls(); godot_register_string_icalls(); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index d9cf4a3a0b..fd785631a8 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2385,11 +2385,6 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, - // Sky - - { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" }, - { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, - // Particles { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -2398,6 +2393,15 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, + // Sky + + { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" }, + { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, + + // Fog + + { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, + { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, nullptr, nullptr }, }; |