Visual Shaders are back.

This commit is contained in:
Juan Linietsky 2018-07-14 18:15:42 -03:00
parent 1fc7973a00
commit f6ce73f724
32 changed files with 6368 additions and 93 deletions

View File

@ -92,7 +92,7 @@ void EditorProperty::_notification(int p_what) {
Rect2 bottom_rect;
{
int child_room = size.width / 2;
int child_room = size.width * (1.0 - split_ratio);
Ref<Font> font = get_font("font", "Tree");
int height = font->get_height();
@ -691,6 +691,15 @@ bool EditorProperty::is_selectable() const {
return selectable;
}
void EditorProperty::set_name_split_ratio(float p_ratio) {
split_ratio = p_ratio;
}
float EditorProperty::get_name_split_ratio() const {
return split_ratio;
}
void EditorProperty::set_object_and_property(Object *p_object, const StringName &p_property) {
object = p_object;
property = p_property;
@ -744,6 +753,7 @@ void EditorProperty::_bind_methods() {
EditorProperty::EditorProperty() {
split_ratio = 0.5;
selectable = true;
text_size = 0;
read_only = false;
@ -1114,6 +1124,30 @@ EditorInspectorSection::EditorInspectorSection() {
Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS];
int EditorInspector::inspector_plugin_count = 0;
EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
for (int i = inspector_plugin_count - 1; i >= 0; i--) {
inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage);
if (inspector_plugins[i]->added_editors.size()) {
for (int j = 1; j < inspector_plugins[i]->added_editors.size(); j++) { //only keep first one
memdelete(inspector_plugins[i]->added_editors[j].property_editor);
}
EditorProperty *prop = Object::cast_to<EditorProperty>(inspector_plugins[i]->added_editors[0].property_editor);
if (prop) {
inspector_plugins[i]->added_editors.clear();
return prop;
} else {
memdelete(inspector_plugins[i]->added_editors[0].property_editor);
inspector_plugins[i]->added_editors.clear();
}
}
}
return NULL;
}
void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);

View File

@ -76,6 +76,8 @@ private:
bool selected;
int selected_focusable;
float split_ratio;
Vector<Control *> focusables;
Control *label_reference;
Control *bottom_editor;
@ -134,6 +136,9 @@ public:
void set_selectable(bool p_selectable);
bool is_selectable() const;
void set_name_split_ratio(float p_ratio);
float get_name_split_ratio() const;
void set_object_and_property(Object *p_object, const StringName &p_property);
EditorProperty();
};
@ -285,6 +290,8 @@ public:
static void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
static void cleanup_plugins();
static EditorProperty *instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
void set_undo_redo(UndoRedo *p_undo_redo);
String get_selected_path() const;

View File

@ -116,6 +116,7 @@
#include "editor/plugins/theme_editor_plugin.h"
#include "editor/plugins/tile_map_editor_plugin.h"
#include "editor/plugins/tile_set_editor_plugin.h"
#include "editor/plugins/visual_shader_editor_plugin.h"
#include "editor/pvrtc_compress.h"
#include "editor/register_exporters.h"
#include "editor/script_editor_debugger.h"
@ -4605,6 +4606,10 @@ EditorNode::EditorNode() {
Ref<EditorInspectorRootMotionPlugin> rmp;
rmp.instance();
EditorInspector::add_inspector_plugin(rmp);
Ref<EditorInspectorShaderModePlugin> smp;
smp.instance();
EditorInspector::add_inspector_plugin(smp);
}
_pvrtc_register_compressors();
@ -4646,7 +4651,8 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/scene_tabs/show_thumbnail_on_hover", true);
EDITOR_DEF("interface/inspector/capitalize_properties", true);
EDITOR_DEF("interface/inspector/disable_folding", false);
EDITOR_DEF("interface/inspector/open_resources_in_new_inspector", false);
EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true);
EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "Material,Mesh");
EDITOR_DEF("run/auto_save/save_before_running", true);
theme_base = memnew(Control);
@ -5367,8 +5373,7 @@ EditorNode::EditorNode() {
raise_bottom_panel_item(AnimationPlayerEditor::singleton);
add_editor_plugin(memnew(ShaderEditorPlugin(this)));
// FIXME: Disabled for Godot 3.0 as made incompatible, it needs to be ported to the new API.
//add_editor_plugin(memnew(ShaderGraphEditorPlugin(this)));
add_editor_plugin(memnew(VisualShaderEditorPlugin(this)));
add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this)));
add_editor_plugin(memnew(AnimationNodeBlendSpace1DEditorPlugin(this)));
add_editor_plugin(memnew(AnimationNodeBlendSpace2DEditorPlugin(this)));

View File

@ -405,6 +405,10 @@ void EditorPropertyEnum::setup(const Vector<String> &p_options) {
}
}
void EditorPropertyEnum::set_option_button_clip(bool p_enable) {
options->set_clip_text(p_enable);
}
void EditorPropertyEnum::_bind_methods() {
ClassDB::bind_method(D_METHOD("_option_selected"), &EditorPropertyEnum::_option_selected);
@ -2266,6 +2270,10 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &
}
}
void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
use_sub_inspector = p_enable;
}
void EditorPropertyResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("_file_selected"), &EditorPropertyResource::_file_selected);
@ -2288,7 +2296,8 @@ EditorPropertyResource::EditorPropertyResource() {
sub_inspector = NULL;
sub_inspector_vbox = NULL;
use_sub_inspector = !bool(EDITOR_GET("interface/inspector/open_resources_in_new_inspector"));
use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);
assign = memnew(Button);
@ -2691,6 +2700,22 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case Variant::OBJECT: {
EditorPropertyResource *editor = memnew(EditorPropertyResource);
editor->setup(p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
String open_in_new = EDITOR_GET("interface/inspector/resources_types_to_open_in_new_inspector");
for (int i = 0; i < open_in_new.get_slice_count(","); i++) {
String type = open_in_new.get_slicec(',', i).strip_edges();
for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
String inherits = p_hint_text.get_slicec(',', j);
if (ClassDB::is_parent_class(inherits, type)) {
editor->set_use_sub_inspector(false);
}
}
}
}
add_property_editor(p_path, editor);
} break;

View File

@ -178,6 +178,7 @@ protected:
public:
void setup(const Vector<String> &p_options);
virtual void update_property();
void set_option_button_clip(bool p_enable);
EditorPropertyEnum();
};
@ -531,6 +532,8 @@ public:
void collapse_all_folding();
void expand_all_folding();
void set_use_sub_inspector(bool p_enable);
EditorPropertyResource();
};

View File

@ -72,10 +72,11 @@ static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left =
return style;
}
static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow = 1, bool p_vertical = false) {
static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false) {
Ref<StyleBoxLine> style(memnew(StyleBoxLine));
style->set_color(p_color);
style->set_grow(p_grow);
style->set_grow_begin(p_grow_begin);
style->set_grow_end(p_grow_end);
style->set_thickness(p_thickness);
style->set_vertical(p_vertical);
return style;
@ -462,9 +463,20 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine));
style_popup_separator->set_color(separator_color);
style_popup_separator->set_grow(popup_margin_size - MAX(EDSCALE, border_width));
style_popup_separator->set_grow_begin(popup_margin_size - MAX(EDSCALE, border_width));
style_popup_separator->set_grow_end(popup_margin_size - MAX(EDSCALE, border_width));
style_popup_separator->set_thickness(MAX(EDSCALE, border_width));
Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine));
style_popup_labeled_separator_left->set_grow_begin(popup_margin_size - MAX(EDSCALE, border_width));
style_popup_labeled_separator_left->set_color(separator_color);
style_popup_labeled_separator_left->set_thickness(MAX(EDSCALE, border_width));
Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine));
style_popup_labeled_separator_right->set_grow_end(popup_margin_size - MAX(EDSCALE, border_width));
style_popup_labeled_separator_right->set_color(separator_color);
style_popup_labeled_separator_right->set_thickness(MAX(EDSCALE, border_width));
Ref<StyleBoxEmpty> style_empty = make_empty_stylebox(default_margin_size, default_margin_size, default_margin_size, default_margin_size);
// Tabs
@ -578,6 +590,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_icon("arrow", "OptionButton", theme->get_icon("GuiOptionArrow", "EditorIcons"));
theme->set_constant("arrow_margin", "OptionButton", default_margin_size * EDSCALE);
theme->set_constant("modulate_arrow", "OptionButton", true);
theme->set_constant("hseparation", "OptionButton", 4 * EDSCALE);
// CheckButton
theme->set_stylebox("normal", "CheckButton", style_menu);
@ -626,6 +639,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
Ref<StyleBoxFlat> style_popup_menu = style_popup;
theme->set_stylebox("panel", "PopupMenu", style_popup_menu);
theme->set_stylebox("separator", "PopupMenu", style_popup_separator);
theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left);
theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right);
theme->set_color("font_color", "PopupMenu", font_color);
theme->set_color("font_color_hover", "PopupMenu", font_color_hl);
theme->set_color("font_color_accel", "PopupMenu", font_color_disabled);
@ -780,7 +796,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
// Separators
theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, border_width));
theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, border_width, 0, true));
theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, border_width, 0, 0, true));
// Debugger
@ -1005,6 +1021,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_constant("title_h_offset", "GraphNode", -16 * EDSCALE);
theme->set_constant("close_h_offset", "GraphNode", 20 * EDSCALE);
theme->set_constant("close_offset", "GraphNode", 20 * EDSCALE);
theme->set_constant("separation", "GraphNode", 1 * EDSCALE);
theme->set_icon("close", "GraphNode", theme->get_icon("GuiCloseCustomizable", "EditorIcons"));
theme->set_icon("resizer", "GraphNode", theme->get_icon("GuiResizer", "EditorIcons"));
theme->set_icon("port", "GraphNode", theme->get_icon("GuiGraphNodePort", "EditorIcons"));

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
version="1.1"
viewBox="0 0 16 16"
id="svg20"
sodipodi:docname="icon_visual_shader.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata26">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs24" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview22"
showgrid="false"
inkscape:zoom="14.75"
inkscape:cx="8"
inkscape:cy="8"
inkscape:window-x="67"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="svg20" />
<g
id="g18"
transform="matrix(1,0,0,0.50605327,0,0.49394673)">
<path
d="M 2,1 C 1.44774,1.0001 1.00006,1.4477 1,2 v 12 c 5.52e-5,0.5523 0.44774,0.9999 1,1 h 12 c 0.55226,-10e-5 0.99994,-0.4477 1,-1 V 6 L 10,1 Z m 1,2 h 6 v 3 c 0,0.554 0.44599,1 1,1 h 3 v 6 H 3 Z"
id="path2"
inkscape:connector-curvature="0"
style="fill:#e0e0e0" />
<path
d="m 10,11 h 2 v 1 h -2 z"
id="path4"
inkscape:connector-curvature="0"
style="fill:#9f70ff" />
<path
d="M 4,6 H 6 V 7 H 4 Z"
id="path6"
inkscape:connector-curvature="0"
style="fill:#ffeb70" />
<path
d="m 8,8 h 4 V 9 H 8 Z"
id="path8"
inkscape:connector-curvature="0"
style="fill:#9dff70" />
<path
d="M 7,6 H 8 V 7 H 7 Z"
id="path10"
inkscape:connector-curvature="0"
style="fill:#70deff" />
<path
d="m 4,11 h 5 v 1 H 4 Z"
id="path12"
inkscape:connector-curvature="0"
style="fill:#ff70ac" />
<path
d="M 4,4 H 7 V 5 H 4 Z"
id="path14"
inkscape:connector-curvature="0"
style="fill:#ff7070" />
<path
d="M 4,8 H 7 V 9 H 4 Z"
id="path16"
inkscape:connector-curvature="0"
style="fill:#70ffb9" />
</g>
<path
inkscape:connector-curvature="0"
style="fill:#e0e0e0"
d="m 2.8642321,9 v 6 h 2 a 3,3 0 0 0 3,-3 V 9 h -2 v 3 a 1,1 0 0 1 -1,1 V 9 Z"
id="path1394" />
<path
inkscape:connector-curvature="0"
style="fill:#e0e0e0"
d="m 10.864232,9 a 2,2 0 0 0 -1.7323999,1 2,2 0 0 0 0,2 2,2 0 0 0 1.7323999,1 H 8.8642321 v 2 h 1.9999999 a 2,2 0 0 0 1.7324,-1 2,2 0 0 0 0,-2 2,2 0 0 0 -1.7324,-1 h 2 V 9 Z"
id="path30" />
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -246,7 +246,7 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
Point2 instance_pos = graph->get_scroll_ofs() + graph->get_size() * 0.5;
anode->set_position(instance_pos);
anode->set_position(instance_pos / EDSCALE);
String base_name = add_options[p_idx].name;
int base = 1;

View File

@ -130,9 +130,9 @@ void ShaderTextEditor::_load_theme_settings() {
}
}
for (const Set<String>::Element *E = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).size(); i++) {
keywords.push_back(E->get());
keywords.push_back(ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode()))[i]);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,186 @@
#ifndef VISUAL_SHADER_EDITOR_PLUGIN_H
#define VISUAL_SHADER_EDITOR_PLUGIN_H
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/property_editor.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/popup.h"
#include "scene/gui/tree.h"
#include "scene/resources/visual_shader.h"
class VisualShaderNodePlugin : public Reference {
GDCLASS(VisualShaderNodePlugin, Reference)
protected:
static void _bind_methods();
public:
virtual Control *create_editor(const Ref<VisualShaderNode> &p_node);
};
class VisualShaderEditor : public VBoxContainer {
GDCLASS(VisualShaderEditor, VBoxContainer);
CustomPropertyEditor *property_editor;
int editing_node;
int editing_port;
Ref<VisualShader> visual_shader;
GraphEdit *graph;
MenuButton *add_node;
OptionButton *edit_type;
PanelContainer *error_panel;
Label *error_label;
UndoRedo *undo_redo;
void _update_graph();
struct AddOption {
String name;
String category;
String type;
Ref<Script> script;
AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_type = String()) {
name = p_name;
type = p_type;
category = p_category;
}
};
Vector<AddOption> add_options;
void _draw_color_over_button(Object *obj, Color p_color);
void _add_node(int p_idx);
void _update_options_menu();
static VisualShaderEditor *singleton;
void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
bool updating;
void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
void _scroll_changed(const Vector2 &p_scroll);
void _node_selected(Object *p_node);
void _delete_request(int);
void _removed_from_graph();
void _node_changed(int p_id);
void _edit_port_default_input(Object *p_button, int p_node, int p_port);
void _port_edited();
void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
void _line_edit_changed(const String &p_text, Object *line_edit, int p_node_id);
void _line_edit_focus_out(Object *line_edit, int p_node_id);
void _duplicate_nodes();
Vector<Ref<VisualShaderNodePlugin> > plugins;
void _mode_selected(int p_id);
void _input_select_item(Ref<VisualShaderNodeInput> input, String name);
void _preview_select_port(int p_node, int p_port);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
static VisualShaderEditor *get_singleton() { return singleton; }
void add_custom_type(const String &p_name, const String &p_category, const Ref<Script> &p_script);
void remove_custom_type(const Ref<Script> &p_script);
virtual Size2 get_minimum_size() const;
void edit(VisualShader *p_visual_shader);
VisualShaderEditor();
};
class VisualShaderEditorPlugin : public EditorPlugin {
GDCLASS(VisualShaderEditorPlugin, EditorPlugin);
VisualShaderEditor *visual_shader_editor;
EditorNode *editor;
Button *button;
public:
virtual String get_name() const { return "VisualShader"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
virtual void make_visible(bool p_visible);
VisualShaderEditorPlugin(EditorNode *p_node);
~VisualShaderEditorPlugin();
};
class VisualShaderNodePluginDefault : public VisualShaderNodePlugin {
GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin)
public:
virtual Control *create_editor(const Ref<VisualShaderNode> &p_node);
};
class EditorPropertyShaderMode : public EditorProperty {
GDCLASS(EditorPropertyShaderMode, EditorProperty)
OptionButton *options;
void _option_selected(int p_which);
protected:
static void _bind_methods();
public:
void setup(const Vector<String> &p_options);
virtual void update_property();
void set_option_button_clip(bool p_enable);
EditorPropertyShaderMode();
};
class EditorInspectorShaderModePlugin : public EditorInspectorPlugin {
GDCLASS(EditorInspectorShaderModePlugin, EditorInspectorPlugin)
public:
virtual bool can_handle(Object *p_object);
virtual void parse_begin(Object *p_object);
virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
virtual void parse_end();
};
class VisualShaderNodePortPreview : public Control {
GDCLASS(VisualShaderNodePortPreview, Control)
Ref<VisualShader> shader;
VisualShader::Type type;
int node;
int port;
void _shader_changed(); //must regen
protected:
void _notification(int p_what);
static void _bind_methods();
public:
virtual Size2 get_minimum_size() const;
void setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port);
VisualShaderNodePortPreview();
};
#endif // VISUAL_SHADER_EDITOR_PLUGIN_H

View File

@ -321,8 +321,8 @@ MainLoop *test() {
dt["fragment"].built_ins["ALBEDO"] = SL::TYPE_VEC3;
dt["fragment"].can_discard = true;
Set<String> rm;
rm.insert("popo");
Vector<StringName> rm;
rm.push_back("popo");
Set<String> types;
types.insert("spatial");

View File

@ -36,7 +36,7 @@ Size2 OptionButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
if (has_icon("arrow"))
minsize.width += Control::get_icon("arrow")->get_width();
minsize.width += Control::get_icon("arrow")->get_width() + get_constant("hseparation");
return minsize;
}

View File

@ -430,6 +430,8 @@ void PopupMenu::_notification(int p_what) {
Ref<Texture> uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") };
Ref<Texture> submenu = get_icon("submenu");
Ref<StyleBox> separator = get_stylebox("separator");
Ref<StyleBox> labeled_separator_left = get_stylebox("labeled_separator_left");
Ref<StyleBox> labeled_separator_right = get_stylebox("labeled_separator_right");
style->draw(ci, Rect2(Point2(), get_size()));
Point2 ofs = style->get_offset();
@ -466,11 +468,26 @@ void PopupMenu::_notification(int p_what) {
hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation)));
}
String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].xl_text;
if (items[i].separator) {
int sep_h = separator->get_center_size().height + separator->get_minimum_size().height;
if (text != String()) {
int ss = font->get_string_size(text).width;
int center = (get_size().width) / 2;
int l = center - ss / 2;
int r = center + ss / 2;
if (l > item_ofs.x) {
labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, l - item_ofs.x), sep_h)));
}
if (r < get_size().width - style->get_margin(MARGIN_RIGHT)) {
labeled_separator_right->draw(ci, Rect2(Point2(r, item_ofs.y + Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, get_size().width - style->get_margin(MARGIN_RIGHT) - r), sep_h)));
}
} else {
separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h)));
}
}
if (items[i].checkable_type) {
Texture *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr();
@ -489,8 +506,13 @@ void PopupMenu::_notification(int p_what) {
}
item_ofs.y += font->get_ascent();
String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].xl_text;
if (!items[i].separator) {
if (items[i].separator) {
if (text != String()) {
int center = (get_size().width - font->get_string_size(text).width) / 2;
font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled);
}
} else {
font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color));
}
@ -1073,11 +1095,15 @@ void PopupMenu::remove_item(int p_idx) {
update();
}
void PopupMenu::add_separator() {
void PopupMenu::add_separator(const String &p_text) {
Item sep;
sep.separator = true;
sep.ID = -1;
if (p_text != String()) {
sep.text = p_text;
sep.xl_text = tr(p_text);
}
items.push_back(sep);
update();
}
@ -1310,7 +1336,7 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &PopupMenu::remove_item);
ClassDB::bind_method(D_METHOD("add_separator"), &PopupMenu::add_separator);
ClassDB::bind_method(D_METHOD("add_separator", "label"), &PopupMenu::add_separator, DEFVAL(String()));
ClassDB::bind_method(D_METHOD("clear"), &PopupMenu::clear);
ClassDB::bind_method(D_METHOD("_set_items"), &PopupMenu::_set_items);

View File

@ -180,7 +180,7 @@ public:
void remove_item(int p_idx);
void add_separator();
void add_separator(const String &p_text = String());
void clear();

View File

@ -159,6 +159,8 @@
#include "scene/resources/texture.h"
#include "scene/resources/tile_set.h"
#include "scene/resources/video_stream.h"
#include "scene/resources/visual_shader.h"
#include "scene/resources/visual_shader_nodes.h"
#include "scene/resources/world.h"
#include "scene/resources/world_2d.h"
#include "scene/scene_string_names.h"
@ -456,6 +458,39 @@ void register_scene_types() {
AcceptDialog::set_swap_ok_cancel(GLOBAL_DEF("gui/common/swap_ok_cancel", bool(OS::get_singleton()->get_swap_ok_cancel())));
ClassDB::register_class<Shader>();
ClassDB::register_class<VisualShader>();
ClassDB::register_virtual_class<VisualShaderNode>();
ClassDB::register_class<VisualShaderNodeInput>();
ClassDB::register_virtual_class<VisualShaderNodeOutput>();
ClassDB::register_class<VisualShaderNodeScalarConstant>();
ClassDB::register_class<VisualShaderNodeColorConstant>();
ClassDB::register_class<VisualShaderNodeVec3Constant>();
ClassDB::register_class<VisualShaderNodeTransformConstant>();
ClassDB::register_class<VisualShaderNodeScalarOp>();
ClassDB::register_class<VisualShaderNodeVectorOp>();
ClassDB::register_class<VisualShaderNodeColorOp>();
ClassDB::register_class<VisualShaderNodeTransformMult>();
ClassDB::register_class<VisualShaderNodeTransformVecMult>();
ClassDB::register_class<VisualShaderNodeScalarFunc>();
ClassDB::register_class<VisualShaderNodeVectorFunc>();
ClassDB::register_class<VisualShaderNodeDotProduct>();
ClassDB::register_class<VisualShaderNodeVectorLen>();
ClassDB::register_class<VisualShaderNodeScalarInterp>();
ClassDB::register_class<VisualShaderNodeVectorInterp>();
ClassDB::register_class<VisualShaderNodeVectorConstruct>();
ClassDB::register_class<VisualShaderNodeTransformConstruct>();
ClassDB::register_class<VisualShaderNodeVectorDestruct>();
ClassDB::register_class<VisualShaderNodeTransformDestruct>();
ClassDB::register_class<VisualShaderNodeTexture>();
ClassDB::register_class<VisualShaderNodeCubeMap>();
ClassDB::register_virtual_class<VisualShaderNodeUniform>();
ClassDB::register_class<VisualShaderNodeScalarUniform>();
ClassDB::register_class<VisualShaderNodeColorUniform>();
ClassDB::register_class<VisualShaderNodeVec3Uniform>();
ClassDB::register_class<VisualShaderNodeTransformUniform>();
ClassDB::register_class<VisualShaderNodeTextureUniform>();
ClassDB::register_class<VisualShaderNodeCubeMapUniform>();
ClassDB::register_class<ShaderMaterial>();
ClassDB::register_virtual_class<CanvasItem>();
ClassDB::register_class<CanvasItemMaterial>();

View File

@ -585,6 +585,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_stylebox("panel_disabled", "PopupMenu", make_stylebox(popup_bg_disabled_png, 4, 4, 4, 4));
theme->set_stylebox("hover", "PopupMenu", selected);
theme->set_stylebox("separator", "PopupMenu", make_stylebox(vseparator_png, 3, 3, 3, 3));
theme->set_stylebox("labeled_separator_left", "PopupMenu", make_stylebox(vseparator_png, 0, 0, 0, 0));
theme->set_stylebox("labeled_separator_right", "PopupMenu", make_stylebox(vseparator_png, 0, 0, 0, 0));
theme->set_icon("checked", "PopupMenu", make_icon(checked_png));
theme->set_icon("unchecked", "PopupMenu", make_icon(unchecked_png));

View File

@ -145,11 +145,17 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) {
if (shader.is_valid()) {
shader->disconnect("changed", this, "_shader_changed");
}
shader = p_shader;
RID rid;
if (shader.is_valid())
if (shader.is_valid()) {
rid = shader->get_rid();
shader->connect("changed", this, "_shader_changed");
}
VS::get_singleton()->material_set_shader(_get_material(), rid);
_change_notify(); //properties for shader exposed
@ -171,12 +177,17 @@ Variant ShaderMaterial::get_shader_param(const StringName &p_param) const {
return VS::get_singleton()->material_get_param(_get_material(), p_param);
}
void ShaderMaterial::_shader_changed() {
_change_notify(); //update all properties
}
void ShaderMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shader", "shader"), &ShaderMaterial::set_shader);
ClassDB::bind_method(D_METHOD("get_shader"), &ShaderMaterial::get_shader);
ClassDB::bind_method(D_METHOD("set_shader_param", "param", "value"), &ShaderMaterial::set_shader_param);
ClassDB::bind_method(D_METHOD("get_shader_param", "param"), &ShaderMaterial::get_shader_param);
ClassDB::bind_method(D_METHOD("_shader_changed"), &ShaderMaterial::_shader_changed);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shader", PROPERTY_HINT_RESOURCE_TYPE, "Shader"), "set_shader", "get_shader");
}

View File

@ -92,6 +92,8 @@ protected:
virtual bool _can_do_next_pass() const;
void _shader_changed();
public:
void set_shader(const Ref<Shader> &p_shader);
Ref<Shader> get_shader() const;

View File

@ -896,7 +896,7 @@ static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p
CharString utf8 = p_string.utf8();
if (p_bit_on_len) {
f->store_32(utf8.length() + 1 | 0x80000000);
f->store_32((utf8.length() + 1) | 0x80000000);
} else {
f->store_32(utf8.length() + 1);
}

View File

@ -54,16 +54,20 @@ void Shader::set_code(const String &p_code) {
VisualServer::get_singleton()->shader_set_code(shader, p_code);
params_cache_dirty = true;
emit_signal(SceneStringNames::get_singleton()->changed);
emit_changed();
}
String Shader::get_code() const {
_update_shader();
return VisualServer::get_singleton()->shader_get_code(shader);
}
void Shader::get_param_list(List<PropertyInfo> *p_params) const {
_update_shader();
List<PropertyInfo> local;
VisualServer::get_singleton()->shader_get_param_list(shader, &local);
params_cache.clear();
@ -72,6 +76,9 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const {
for (List<PropertyInfo>::Element *E = local.front(); E; E = E->next()) {
PropertyInfo pi = E->get();
if (default_textures.has(pi.name)) { //do not show default textures
continue;
}
pi.name = "shader_param/" + pi.name;
params_cache[pi.name] = E->get().name;
if (p_params) {
@ -86,6 +93,8 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const {
RID Shader::get_rid() const {
_update_shader();
return shader;
}
@ -98,6 +107,8 @@ void Shader::set_default_texture_param(const StringName &p_param, const Ref<Text
default_textures.erase(p_param);
VS::get_singleton()->shader_set_default_texture_param(shader, p_param, RID());
}
emit_changed();
}
Ref<Texture> Shader::get_default_texture_param(const StringName &p_param) const {
@ -120,6 +131,9 @@ bool Shader::has_param(const StringName &p_param) const {
return params_cache.has(p_param);
}
void Shader::_update_shader() const {
}
void Shader::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mode"), &Shader::get_mode);
@ -227,5 +241,5 @@ void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource,
}
bool ResourceFormatSaverShader::recognize(const RES &p_resource) const {
return Object::cast_to<Shader>(*p_resource) != NULL;
return p_resource->get_class_name() == "Shader"; //only shader, not inherited
}

View File

@ -61,12 +61,13 @@ private:
mutable Map<StringName, StringName> params_cache; //map a shader param to a material param..
Map<StringName, Ref<Texture> > default_textures;
virtual void _update_shader() const; //used for visual shader
protected:
static void _bind_methods();
public:
//void set_mode(Mode p_mode);
Mode get_mode() const;
virtual Mode get_mode() const;
void set_code(const String &p_code);
String get_code() const;

View File

@ -905,12 +905,20 @@ bool StyleBoxLine::is_vertical() const {
return vertical;
}
void StyleBoxLine::set_grow(float p_grow) {
grow = p_grow;
void StyleBoxLine::set_grow_end(float p_grow_end) {
grow_end = p_grow_end;
emit_changed();
}
float StyleBoxLine::get_grow() const {
return grow;
float StyleBoxLine::get_grow_end() const {
return grow_end;
}
void StyleBoxLine::set_grow_begin(float p_grow_begin) {
grow_begin = p_grow_begin;
emit_changed();
}
float StyleBoxLine::get_grow_begin() const {
return grow_begin;
}
void StyleBoxLine::_bind_methods() {
@ -919,13 +927,16 @@ void StyleBoxLine::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_color"), &StyleBoxLine::get_color);
ClassDB::bind_method(D_METHOD("set_thickness", "thickness"), &StyleBoxLine::set_thickness);
ClassDB::bind_method(D_METHOD("get_thickness"), &StyleBoxLine::get_thickness);
ClassDB::bind_method(D_METHOD("set_grow", "grow"), &StyleBoxLine::set_grow);
ClassDB::bind_method(D_METHOD("get_grow"), &StyleBoxLine::get_grow);
ClassDB::bind_method(D_METHOD("set_grow_begin", "offset"), &StyleBoxLine::set_grow_begin);
ClassDB::bind_method(D_METHOD("get_grow_begin"), &StyleBoxLine::get_grow_begin);
ClassDB::bind_method(D_METHOD("set_grow_end", "offset"), &StyleBoxLine::set_grow_end);
ClassDB::bind_method(D_METHOD("get_grow_end"), &StyleBoxLine::get_grow_end);
ClassDB::bind_method(D_METHOD("set_vertical", "vertical"), &StyleBoxLine::set_vertical);
ClassDB::bind_method(D_METHOD("is_vertical"), &StyleBoxLine::is_vertical);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "grow", PROPERTY_HINT_RANGE, "-300,300,1"), "set_grow", "get_grow");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "grow_begin", PROPERTY_HINT_RANGE, "-300,300,1"), "set_grow_begin", "get_grow_begin");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "grow_end", PROPERTY_HINT_RANGE, "-300,300,1"), "set_grow_end", "get_grow_end");
ADD_PROPERTY(PropertyInfo(Variant::INT, "thickness", PROPERTY_HINT_RANGE, "0,10"), "set_thickness", "get_thickness");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical");
}
@ -941,12 +952,12 @@ void StyleBoxLine::draw(RID p_canvas_item, const Rect2 &p_rect) const {
Rect2i r = p_rect;
if (vertical) {
r.position.y -= grow;
r.size.y += grow * 2;
r.position.y -= grow_begin;
r.size.y += (grow_begin + grow_end);
r.size.x = thickness;
} else {
r.position.x -= grow;
r.size.x += grow * 2;
r.position.x -= grow_begin;
r.size.x += (grow_begin + grow_end);
r.size.y = thickness;
}
@ -954,7 +965,8 @@ void StyleBoxLine::draw(RID p_canvas_item, const Rect2 &p_rect) const {
}
StyleBoxLine::StyleBoxLine() {
grow = 1.0;
grow_begin = 1.0;
grow_end = 1.0;
thickness = 1;
color = Color(0.0, 0.0, 0.0);
vertical = false;

View File

@ -236,7 +236,8 @@ class StyleBoxLine : public StyleBox {
Color color;
int thickness;
bool vertical;
float grow;
float grow_begin;
float grow_end;
protected:
virtual float get_style_margin(Margin p_margin) const;
@ -252,8 +253,11 @@ public:
void set_vertical(bool p_vertical);
bool is_vertical() const;
void set_grow(float p_grow);
float get_grow() const;
void set_grow_begin(float p_grow);
float get_grow_begin() const;
void set_grow_end(float p_grow);
float get_grow_end() const;
virtual Size2 get_center_size() const;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,284 @@
#ifndef VISUAL_SHADER_H
#define VISUAL_SHADER_H
#include "scene/resources/shader.h"
#include "string_builder.h"
class VisualShaderNodeUniform;
class VisualShaderNode;
class VisualShader : public Shader {
GDCLASS(VisualShader, Shader)
public:
enum Type {
TYPE_VERTEX,
TYPE_FRAGMENT,
TYPE_LIGHT,
TYPE_MAX
};
struct Connection {
int from_node;
int from_port;
int to_node;
int to_port;
};
struct DefaultTextureParam {
StringName name;
Ref<Texture> param;
};
private:
struct Node {
Ref<VisualShaderNode> node;
Vector2 position;
};
struct Graph {
Map<int, Node> nodes;
List<Connection> connections;
} graph[TYPE_MAX];
Shader::Mode shader_mode;
Array _get_node_connections(Type p_type) const;
Vector2 graph_offset;
struct RenderModeEnums {
Shader::Mode mode;
const char *string;
};
HashMap<String, int> modes;
Set<StringName> flags;
static RenderModeEnums render_mode_enums[];
volatile mutable bool dirty;
void _queue_update();
union ConnectionKey {
struct {
uint64_t node : 32;
uint64_t port : 32;
};
uint64_t key;
bool operator<(const ConnectionKey &p_key) const {
return key < p_key.key;
}
};
Error _write_node(Type p_type, StringBuilder &global_code, StringBuilder &code, Vector<DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview) const;
void _input_type_changed(Type p_type, int p_id);
protected:
virtual void _update_shader() const;
static void _bind_methods();
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
public:
enum {
NODE_ID_INVALID = -1,
NODE_ID_OUTPUT = 0,
};
void add_node(Type p_type, const Ref<VisualShaderNode> &p_node, const Vector2 &p_position, int p_id);
void set_node_position(Type p_type, int p_id, const Vector2 &p_position);
Vector2 get_node_position(Type p_type, int p_id) const;
Ref<VisualShaderNode> get_node(Type p_type, int p_id) const;
Vector<int> get_node_list(Type p_type) const;
int get_valid_node_id(Type p_type) const;
int find_node_id(Type p_type, const Ref<VisualShaderNode> &p_node) const;
void remove_node(Type p_type, int p_id);
bool is_node_connection(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
bool can_connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
Error connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void disconnect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void get_node_connections(Type p_type, List<Connection> *r_connections) const;
void set_mode(Mode p_mode);
virtual Mode get_mode() const;
void set_graph_offset(const Vector2 &p_offset);
Vector2 get_graph_offset() const;
String generate_preview_shader(Type p_type, int p_node, int p_port, Vector<DefaultTextureParam> &r_default_tex_params) const;
String validate_uniform_name(const String &p_name, const Ref<VisualShaderNodeUniform> &p_uniform) const;
VisualShader();
};
VARIANT_ENUM_CAST(VisualShader::Type)
///
///
///
class VisualShaderNode : public Resource {
GDCLASS(VisualShaderNode, Resource)
int port_preview;
Map<int, Variant> default_input_values;
Array _get_default_input_values() const;
void _set_default_input_values(const Array &p_values);
protected:
static void _bind_methods();
public:
enum PortType {
PORT_TYPE_SCALAR,
PORT_TYPE_VECTOR,
PORT_TYPE_TRANSFORM,
};
virtual String get_caption() const = 0;
virtual int get_input_port_count() const = 0;
virtual PortType get_input_port_type(int p_port) const = 0;
virtual String get_input_port_name(int p_port) const = 0;
void set_input_port_default_value(int p_port, const Variant &p_value);
Variant get_input_port_default_value(int p_port) const; // if NIL (default if node does not set anything) is returned, it means no default value is wanted if disconnected, thus no input var must be supplied (empty string will be supplied)
virtual int get_output_port_count() const = 0;
virtual PortType get_output_port_type(int p_port) const = 0;
virtual String get_output_port_name(int p_port) const = 0;
void set_output_port_for_preview(int p_index);
int get_output_port_for_preview() const;
virtual bool is_port_separator(int p_index) const;
virtual Vector<StringName> get_editable_properties() const;
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const = 0; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const;
VisualShaderNode();
};
/////
class VisualShaderNodeInput : public VisualShaderNode {
GDCLASS(VisualShaderNodeInput, VisualShaderNode)
friend class VisualShader;
VisualShader::Type shader_type;
Shader::Mode shader_mode;
struct Port {
Shader::Mode mode;
VisualShader::Type shader_type;
PortType type;
const char *name;
const char *string;
};
static const Port ports[];
static const Port preview_ports[];
String input_name;
protected:
static void _bind_methods();
void _validate_property(PropertyInfo &property) const;
public:
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String get_caption() const;
virtual String generate_code_for_preview(VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const;
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) const;
void set_input_name(String p_name);
String get_input_name() const;
int get_input_index_count() const;
PortType get_input_index_type(int p_index) const;
String get_input_index_name(int p_index) const;
PortType get_input_type_by_name(String p_name) const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeInput();
};
///
class VisualShaderNodeOutput : public VisualShaderNode {
GDCLASS(VisualShaderNodeOutput, VisualShaderNode)
public:
friend class VisualShader;
VisualShader::Type shader_type;
Shader::Mode shader_mode;
struct Port {
Shader::Mode mode;
VisualShader::Type shader_type;
PortType type;
const char *name;
const char *string;
};
static const Port ports[];
public:
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
Variant get_input_port_default_value(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual bool is_port_separator(int p_index) const;
virtual String get_caption() const;
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) const;
VisualShaderNodeOutput();
};
class VisualShaderNodeUniform : public VisualShaderNode {
GDCLASS(VisualShaderNodeUniform, VisualShaderNode)
String uniform_name;
protected:
static void _bind_methods();
public:
void set_uniform_name(const String &p_name);
String get_uniform_name() const;
VisualShaderNodeUniform();
};
#endif // VISUAL_SHADER_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,861 @@
#ifndef VISUAL_SHADER_NODES_H
#define VISUAL_SHADER_NODES_H
#include "scene/resources/visual_shader.h"
/// CONSTANTS ///
class VisualShaderNodeScalarConstant : public VisualShaderNode {
GDCLASS(VisualShaderNodeScalarConstant, VisualShaderNode)
float constant;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_constant(float p_value);
float get_constant() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeScalarConstant();
};
class VisualShaderNodeColorConstant : public VisualShaderNode {
GDCLASS(VisualShaderNodeColorConstant, VisualShaderNode)
Color constant;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_constant(Color p_value);
Color get_constant() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeColorConstant();
};
class VisualShaderNodeVec3Constant : public VisualShaderNode {
GDCLASS(VisualShaderNodeVec3Constant, VisualShaderNode)
Vector3 constant;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_constant(Vector3 p_value);
Vector3 get_constant() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeVec3Constant();
};
class VisualShaderNodeTransformConstant : public VisualShaderNode {
GDCLASS(VisualShaderNodeTransformConstant, VisualShaderNode)
Transform constant;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_constant(Transform p_value);
Transform get_constant() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeTransformConstant();
};
//////////////////////////////////
class VisualShaderNodeTexture : public VisualShaderNode {
GDCLASS(VisualShaderNodeTexture, VisualShaderNode)
Ref<Texture> texture;
public:
enum Source {
SOURCE_TEXTURE,
SOURCE_SCREEN,
SOURCE_2D_TEXTURE,
SOURCE_2D_NORMAL
};
enum TextureType {
TYPE_DATA,
TYPE_COLOR,
TYPE_NORMALMAP
};
private:
Source source;
TextureType texture_type;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_source(Source p_source);
Source get_source() const;
void set_texture(Ref<Texture> p_value);
Ref<Texture> get_texture() const;
void set_texture_type(TextureType p_type);
TextureType get_texture_type() const;
virtual Vector<StringName> get_editable_properties() const;
virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const;
VisualShaderNodeTexture();
};
VARIANT_ENUM_CAST(VisualShaderNodeTexture::TextureType)
VARIANT_ENUM_CAST(VisualShaderNodeTexture::Source)
//////////////////////////////////
class VisualShaderNodeCubeMap : public VisualShaderNode {
GDCLASS(VisualShaderNodeCubeMap, VisualShaderNode)
Ref<CubeMap> cube_map;
public:
enum TextureType {
TYPE_DATA,
TYPE_COLOR,
TYPE_NORMALMAP
};
private:
TextureType texture_type;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_cube_map(Ref<CubeMap> p_value);
Ref<CubeMap> get_cube_map() const;
void set_texture_type(TextureType p_type);
TextureType get_texture_type() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeCubeMap();
};
VARIANT_ENUM_CAST(VisualShaderNodeCubeMap::TextureType)
///////////////////////////////////////
class VisualShaderNodeScalarOp : public VisualShaderNode {
GDCLASS(VisualShaderNodeScalarOp, VisualShaderNode)
public:
enum Operator {
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_MOD,
OP_POW,
OP_MAX,
OP_MIN,
OP_ATAN2
};
protected:
Operator op;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_operator(Operator p_op);
Operator get_operator() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeScalarOp();
};
VARIANT_ENUM_CAST(VisualShaderNodeScalarOp::Operator)
class VisualShaderNodeVectorOp : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorOp, VisualShaderNode)
public:
enum Operator {
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_MOD,
OP_POW,
OP_MAX,
OP_MIN,
OP_CROSS
};
protected:
Operator op;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_operator(Operator p_op);
Operator get_operator() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeVectorOp();
};
VARIANT_ENUM_CAST(VisualShaderNodeVectorOp::Operator)
class VisualShaderNodeColorOp : public VisualShaderNode {
GDCLASS(VisualShaderNodeColorOp, VisualShaderNode)
public:
enum Operator {
OP_SCREEN,
OP_DIFFERENCE,
OP_DARKEN,
OP_LIGHTEN,
OP_OVERLAY,
OP_DODGE,
OP_BURN,
OP_SOFT_LIGHT,
OP_HARD_LIGHT,
};
protected:
Operator op;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_operator(Operator p_op);
Operator get_operator() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeColorOp();
};
VARIANT_ENUM_CAST(VisualShaderNodeColorOp::Operator)
class VisualShaderNodeTransformMult : public VisualShaderNode {
GDCLASS(VisualShaderNodeTransformMult, VisualShaderNode)
public:
enum Operator {
OP_AxB,
OP_BxA,
};
protected:
Operator op;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_operator(Operator p_op);
Operator get_operator() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeTransformMult();
};
VARIANT_ENUM_CAST(VisualShaderNodeTransformMult::Operator)
class VisualShaderNodeTransformVecMult : public VisualShaderNode {
GDCLASS(VisualShaderNodeTransformVecMult, VisualShaderNode)
public:
enum Operator {
OP_AxB,
OP_BxA,
OP_3x3_AxB,
OP_3x3_BxA,
};
protected:
Operator op;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_operator(Operator p_op);
Operator get_operator() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeTransformVecMult();
};
VARIANT_ENUM_CAST(VisualShaderNodeTransformVecMult::Operator)
///////////////////////////////////////
class VisualShaderNodeScalarFunc : public VisualShaderNode {
GDCLASS(VisualShaderNodeScalarFunc, VisualShaderNode)
public:
enum Function {
FUNC_SIN,
FUNC_COS,
FUNC_TAN,
FUNC_ASIN,
FUNC_ACOS,
FUNC_ATAN,
FUNC_SINH,
FUNC_COSH,
FUNC_TANH,
FUNC_LOG,
FUNC_EXP,
FUNC_SQRT,
FUNC_ABS,
FUNC_SIGN,
FUNC_FLOOR,
FUNC_ROUND,
FUNC_CEIL,
FUNC_FRAC,
FUNC_SATURATE,
FUNC_NEGATE,
};
protected:
Function func;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeScalarFunc();
};
VARIANT_ENUM_CAST(VisualShaderNodeScalarFunc::Function)
///////////////////////////////////////
class VisualShaderNodeVectorFunc : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorFunc, VisualShaderNode)
public:
enum Function {
FUNC_NORMALIZE,
FUNC_SATURATE,
FUNC_NEGATE,
FUNC_RECIPROCAL,
FUNC_RGB2HSV,
FUNC_HSV2RGB,
};
protected:
Function func;
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeVectorFunc();
};
VARIANT_ENUM_CAST(VisualShaderNodeVectorFunc::Function)
///////////////////////////////////////
class VisualShaderNodeDotProduct : public VisualShaderNode {
GDCLASS(VisualShaderNodeDotProduct, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeDotProduct();
};
///////////////////////////////////////
class VisualShaderNodeVectorLen : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorLen, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeVectorLen();
};
///////////////////////////////////////
class VisualShaderNodeScalarInterp : public VisualShaderNode {
GDCLASS(VisualShaderNodeScalarInterp, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeScalarInterp();
};
///////////////////////////////////////
class VisualShaderNodeVectorInterp : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorInterp, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeVectorInterp();
};
///////////////////////////////////////
class VisualShaderNodeVectorConstruct : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorConstruct, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeVectorConstruct();
};
///////////////////////////////////////
class VisualShaderNodeTransformConstruct : public VisualShaderNode {
GDCLASS(VisualShaderNodeTransformConstruct, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeTransformConstruct();
};
///////////////////////////////////////
class VisualShaderNodeVectorDestruct : public VisualShaderNode {
GDCLASS(VisualShaderNodeVectorDestruct, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeVectorDestruct();
};
///////////////////////////////////////
class VisualShaderNodeTransformDestruct : public VisualShaderNode {
GDCLASS(VisualShaderNodeTransformDestruct, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeTransformDestruct();
};
///////////////////////////////////////
class VisualShaderNodeScalarUniform : public VisualShaderNodeUniform {
GDCLASS(VisualShaderNodeScalarUniform, VisualShaderNodeUniform)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeScalarUniform();
};
class VisualShaderNodeColorUniform : public VisualShaderNodeUniform {
GDCLASS(VisualShaderNodeColorUniform, VisualShaderNodeUniform)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeColorUniform();
};
class VisualShaderNodeVec3Uniform : public VisualShaderNodeUniform {
GDCLASS(VisualShaderNodeVec3Uniform, VisualShaderNodeUniform)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeVec3Uniform();
};
class VisualShaderNodeTransformUniform : public VisualShaderNodeUniform {
GDCLASS(VisualShaderNodeTransformUniform, VisualShaderNodeUniform)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeTransformUniform();
};
//////////////////////////////////
class VisualShaderNodeTextureUniform : public VisualShaderNodeUniform {
GDCLASS(VisualShaderNodeTextureUniform, VisualShaderNodeUniform)
public:
enum TextureType {
TYPE_DATA,
TYPE_COLOR,
TYPE_NORMALMAP,
TYPE_ANISO,
};
enum ColorDefault {
COLOR_DEFAULT_WHITE,
COLOR_DEFAULT_BLACK
};
private:
TextureType texture_type;
ColorDefault color_default;
protected:
static void _bind_methods();
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
Vector<StringName> get_editable_properties() const;
void set_texture_type(TextureType p_type);
TextureType get_texture_type() const;
void set_color_default(ColorDefault p_default);
ColorDefault get_color_default() const;
VisualShaderNodeTextureUniform();
};
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureType)
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::ColorDefault)
//////////////////////////////////
class VisualShaderNodeCubeMapUniform : public VisualShaderNode {
GDCLASS(VisualShaderNodeCubeMapUniform, VisualShaderNode)
public:
virtual String get_caption() const;
virtual int get_input_port_count() const;
virtual PortType get_input_port_type(int p_port) const;
virtual String get_input_port_name(int p_port) const;
virtual int get_output_port_count() const;
virtual PortType get_output_port_type(int p_port) const;
virtual String get_output_port_name(int p_port) const;
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) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeCubeMapUniform();
};
#endif // VISUAL_SHADER_NODES_H

View File

@ -3583,7 +3583,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
return OK;
}
Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types) {
Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types) {
Token tk = _get_token();
@ -3642,7 +3642,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
return ERR_PARSE_ERROR;
}
if (!p_render_modes.has(mode)) {
if (p_render_modes.find(mode) == -1) {
_set_error("Invalid render mode: '" + String(mode) + "'");
return ERR_PARSE_ERROR;
}
@ -4097,7 +4097,7 @@ String ShaderLanguage::get_shader_type(const String &p_code) {
return String();
}
Error ShaderLanguage::compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types) {
Error ShaderLanguage::compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types) {
clear();
@ -4114,7 +4114,7 @@ Error ShaderLanguage::compile(const String &p_code, const Map<StringName, Functi
return OK;
}
Error ShaderLanguage::complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint) {
Error ShaderLanguage::complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint) {
clear();
@ -4134,9 +4134,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
return ERR_PARSE_ERROR;
} break;
case COMPLETION_RENDER_MODE: {
for (const Set<String>::Element *E = p_render_modes.front(); E; E = E->next()) {
for (int i = 0; i < p_render_modes.size(); i++) {
r_options->push_back(E->get());
r_options->push_back(p_render_modes[i]);
}
return OK;

View File

@ -650,7 +650,7 @@ private:
Error _parse_block(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, bool p_just_one = false, bool p_can_break = false, bool p_can_continue = false);
Error _parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types);
Error _parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types);
public:
//static void get_keyword_list(ShaderType p_type,List<String> *p_keywords);
@ -658,8 +658,8 @@ public:
void clear();
static String get_shader_type(const String &p_code);
Error compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types);
Error complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint);
Error compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types);
Error complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint);
String get_error_text();
int get_error_line();

View File

@ -35,7 +35,7 @@ const Map<StringName, ShaderLanguage::FunctionInfo> &ShaderTypes::get_functions(
return shader_modes[p_mode].functions;
}
const Set<String> &ShaderTypes::get_modes(VS::ShaderMode p_mode) {
const Vector<StringName> &ShaderTypes::get_modes(VS::ShaderMode p_mode) {
return shader_modes[p_mode].modes;
}
@ -140,43 +140,44 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["light"].can_discard = true;
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mix");
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_add");
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_sub");
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mul");
//order used puts first enum mode (default) first
shader_modes[VS::SHADER_SPATIAL].modes.push_back("blend_mix");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("blend_add");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("blend_sub");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("blend_mul");
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_opaque");
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_always");
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_never");
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_alpha_prepass");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("depth_draw_opaque");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("depth_draw_always");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("depth_draw_never");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("depth_draw_alpha_prepass");
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_test_disable");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("depth_test_disable");
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_front");
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_back");
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("cull_back");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("cull_front");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("cull_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.insert("unshaded");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("unshaded");
shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_lambert");
shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_lambert_wrap");
shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_oren_nayar");
shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_burley");
shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_toon");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("diffuse_lambert");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("diffuse_lambert_wrap");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("diffuse_oren_nayar");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("diffuse_burley");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("diffuse_toon");
shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_schlick_ggx");
shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_blinn");
shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_phong");
shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_toon");
shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("specular_schlick_ggx");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("specular_blinn");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("specular_phong");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("specular_toon");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("specular_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.insert("skip_vertex_transform");
shader_modes[VS::SHADER_SPATIAL].modes.insert("world_vertex_coords");
shader_modes[VS::SHADER_SPATIAL].modes.insert("ensure_correct_normals");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("skip_vertex_transform");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("world_vertex_coords");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("ensure_correct_normals");
shader_modes[VS::SHADER_SPATIAL].modes.insert("shadows_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("shadows_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.insert("vertex_lighting");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("vertex_lighting");
/************ CANVAS ITEM **************************/
@ -227,17 +228,17 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].can_discard = true;
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("skip_vertex_transform");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("skip_vertex_transform");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_mix");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_add");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_sub");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_mul");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_premul_alpha");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("blend_disabled");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_mix");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_add");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_sub");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_mul");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_premul_alpha");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("blend_disabled");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("unshaded");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.insert("light_only");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("unshaded");
shader_modes[VS::SHADER_CANVAS_ITEM].modes.push_back("light_only");
/************ PARTICLES **************************/
@ -257,9 +258,9 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_PARTICLES].functions["vertex"].built_ins["RANDOM_SEED"] = constt(ShaderLanguage::TYPE_UINT);
shader_modes[VS::SHADER_PARTICLES].functions["vertex"].can_discard = false;
shader_modes[VS::SHADER_PARTICLES].modes.insert("disable_force");
shader_modes[VS::SHADER_PARTICLES].modes.insert("disable_velocity");
shader_modes[VS::SHADER_PARTICLES].modes.insert("keep_data");
shader_modes[VS::SHADER_PARTICLES].modes.push_back("disable_force");
shader_modes[VS::SHADER_PARTICLES].modes.push_back("disable_velocity");
shader_modes[VS::SHADER_PARTICLES].modes.push_back("keep_data");
shader_types.insert("spatial");
shader_types.insert("canvas_item");

View File

@ -31,14 +31,16 @@
#ifndef SHADERTYPES_H
#define SHADERTYPES_H
#include "ordered_hash_map.h"
#include "servers/visual_server.h"
#include "shader_language.h"
class ShaderTypes {
struct Type {
Map<StringName, ShaderLanguage::FunctionInfo> functions;
Set<String> modes;
Vector<StringName> modes;
};
Map<VS::ShaderMode, Type> shader_modes;
@ -51,7 +53,7 @@ public:
static ShaderTypes *get_singleton() { return singleton; }
const Map<StringName, ShaderLanguage::FunctionInfo> &get_functions(VS::ShaderMode p_mode);
const Set<String> &get_modes(VS::ShaderMode p_mode);
const Vector<StringName> &get_modes(VS::ShaderMode p_mode);
const Set<String> &get_types();
ShaderTypes();