summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/navigation2d.cpp11
-rw-r--r--scene/2d/navigation_polygon.cpp2
-rw-r--r--scene/2d/particles_2d.cpp18
-rw-r--r--scene/2d/particles_2d.h2
-rw-r--r--scene/2d/physics_body_2d.cpp7
-rw-r--r--scene/2d/polygon_2d.cpp3
-rw-r--r--scene/3d/baked_lightmap.cpp3
-rw-r--r--scene/3d/cpu_particles.cpp4
-rw-r--r--scene/3d/navigation.cpp9
-rw-r--r--scene/3d/particles.cpp2
-rw-r--r--scene/3d/physics_joint.cpp15
-rw-r--r--scene/3d/vehicle_body.cpp10
-rw-r--r--scene/3d/voxel_light_baker.cpp26
-rw-r--r--scene/animation/animation_player.cpp2
-rw-r--r--scene/animation/animation_tree.cpp46
-rw-r--r--scene/animation/animation_tree.h2
-rw-r--r--scene/animation/skeleton_ik.cpp20
-rw-r--r--scene/animation/skeleton_ik.h2
-rw-r--r--scene/gui/base_button.cpp2
-rw-r--r--scene/gui/button.cpp3
-rw-r--r--scene/gui/control.cpp3
-rw-r--r--scene/gui/file_dialog.cpp16
-rw-r--r--scene/gui/file_dialog.h1
-rw-r--r--scene/gui/item_list.cpp2
-rw-r--r--scene/gui/line_edit.cpp5
-rw-r--r--scene/gui/link_button.cpp2
-rw-r--r--scene/gui/rich_text_label.cpp1
-rw-r--r--scene/gui/text_edit.cpp57
-rw-r--r--scene/gui/texture_progress.cpp2
-rw-r--r--scene/main/node.cpp10
-rw-r--r--scene/main/scene_tree.cpp2
-rw-r--r--scene/main/viewport.cpp25
-rw-r--r--scene/main/viewport.h3
-rw-r--r--scene/register_scene_types.cpp8
-rw-r--r--scene/resources/animation.cpp2
-rw-r--r--scene/resources/bit_mask.cpp16
-rw-r--r--scene/resources/dynamic_font.cpp4
-rw-r--r--scene/resources/dynamic_font_stb.cpp5
-rw-r--r--scene/resources/mesh.cpp11
-rw-r--r--scene/resources/packed_scene.cpp13
-rw-r--r--scene/resources/shader_graph.cpp2596
-rw-r--r--scene/resources/shader_graph.h446
-rw-r--r--scene/resources/surface_tool.cpp10
-rw-r--r--scene/resources/texture.cpp32
-rw-r--r--scene/resources/tile_set.cpp10
-rw-r--r--scene/resources/visual_shader.cpp2
46 files changed, 171 insertions, 3302 deletions
diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp
index e3b048fd74..9eec8e6cc3 100644
--- a/scene/2d/navigation2d.cpp
+++ b/scene/2d/navigation2d.cpp
@@ -121,7 +121,6 @@ void Navigation2D::_navpoly_link(int p_id) {
pending.edge = j;
p.edges.write[j].P = C->get().pending.push_back(pending);
continue;
- //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
C->get().B = &p;
@@ -144,8 +143,6 @@ void Navigation2D::_navpoly_unlink(int p_id) {
NavMesh &nm = navpoly_map[p_id];
ERR_FAIL_COND(!nm.linked);
- //print_line("UNLINK");
-
for (List<Polygon>::Element *E = nm.polygons.front(); E; E = E->next()) {
Polygon &p = E->get();
@@ -341,7 +338,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
path.resize(2);
path.write[0] = begin_point;
path.write[1] = end_point;
- //print_line("Direct Path");
return path;
}
@@ -379,7 +375,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
while (!found_route) {
if (open_list.size() == 0) {
- //print_line("NOU OPEN LIST");
break;
}
//check open list
@@ -526,7 +521,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
if (portal_left.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
left_poly = p;
portal_left = left;
- //print_line("***ADVANCE LEFT");
} else {
apex_point = portal_right;
@@ -537,8 +531,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
if (!path.size() || path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
path.push_back(apex_point);
skip = true;
- //print_line("addpoint left");
- //print_line("***CLIP LEFT");
}
}
@@ -547,7 +539,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
if (portal_right.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
right_poly = p;
portal_right = right;
- //print_line("***ADVANCE RIGHT");
} else {
apex_point = portal_left;
@@ -557,8 +548,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
portal_left = apex_point;
if (!path.size() || path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
path.push_back(apex_point);
- //print_line("addpoint right");
- //print_line("***CLIP RIGHT");
}
}
diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp
index 2d6679272a..84b12b0bfe 100644
--- a/scene/2d/navigation_polygon.cpp
+++ b/scene/2d/navigation_polygon.cpp
@@ -257,7 +257,7 @@ void NavigationPolygon::make_polygons_from_outlines() {
TriangulatorPartition tpart;
if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed!
- print_line("convex partition failed!");
+ ERR_PRINTS("NavigationPolygon: Convex partition failed!");
return;
}
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 1da1d44b17..a4c3057416 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -74,14 +74,14 @@ void Particles2D::set_randomness_ratio(float p_ratio) {
randomness_ratio = p_ratio;
VS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio);
}
-void Particles2D::set_visibility_rect(const Rect2 &p_aabb) {
+void Particles2D::set_visibility_rect(const Rect2 &p_visibility_rect) {
- visibility_rect = p_aabb;
+ visibility_rect = p_visibility_rect;
AABB aabb;
- aabb.position.x = p_aabb.position.x;
- aabb.position.y = p_aabb.position.y;
- aabb.size.x = p_aabb.size.x;
- aabb.size.y = p_aabb.size.y;
+ aabb.position.x = p_visibility_rect.position.x;
+ aabb.position.y = p_visibility_rect.position.y;
+ aabb.size.x = p_visibility_rect.size.x;
+ aabb.size.y = p_visibility_rect.size.y;
VS::get_singleton()->particles_set_custom_aabb(particles, aabb);
@@ -326,7 +326,7 @@ void Particles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &Particles2D::set_pre_process_time);
ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &Particles2D::set_explosiveness_ratio);
ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &Particles2D::set_randomness_ratio);
- ClassDB::bind_method(D_METHOD("set_visibility_rect", "aabb"), &Particles2D::set_visibility_rect);
+ ClassDB::bind_method(D_METHOD("set_visibility_rect", "visibility_rect"), &Particles2D::set_visibility_rect);
ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &Particles2D::set_use_local_coordinates);
ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &Particles2D::set_fixed_fps);
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &Particles2D::set_fractional_delta);
@@ -372,13 +372,13 @@ void Particles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_speed_scale", "get_speed_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
ADD_GROUP("Drawing", "");
- ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_rect"), "set_visibility_rect", "get_visibility_rect");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT2, "visibility_rect"), "set_visibility_rect", "get_visibility_rect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime"), "set_draw_order", "get_draw_order");
ADD_GROUP("Process Material", "process_");
diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h
index f367095581..31a66afb2a 100644
--- a/scene/2d/particles_2d.h
+++ b/scene/2d/particles_2d.h
@@ -84,7 +84,7 @@ public:
void set_pre_process_time(float p_time);
void set_explosiveness_ratio(float p_ratio);
void set_randomness_ratio(float p_ratio);
- void set_visibility_rect(const Rect2 &p_aabb);
+ void set_visibility_rect(const Rect2 &p_visibility_rect);
void set_use_local_coordinates(bool p_enable);
void set_process_material(const Ref<Material> &p_material);
void set_speed_scale(float p_scale);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 02213e07d0..8e31688d90 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -365,13 +365,6 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
ERR_FAIL_COND(!contact_monitor);
Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid);
- /*if (obj) {
- if (body_in)
- print_line("in: "+String(obj->call("get_name")));
- else
- print_line("out: "+String(obj->call("get_name")));
- }*/
-
ERR_FAIL_COND(!body_in && !E);
if (body_in) {
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 34f4ccc03e..fc0741cc5c 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -253,7 +253,6 @@ void Polygon2D::_notification(int p_what) {
//normalize
for (int j = 0; j < 4; j++) {
weightsw[i * 4 + j] /= tw;
- // print_line("point " + itos(i) + " idx " + itos(j) + " index: " + itos(bonesw[i * 4 + j]) + " weight: " + rtos(weightsw[i * 4 + j]));
}
}
}
@@ -345,8 +344,6 @@ void Polygon2D::_notification(int p_what) {
}
}
- //print_line("loops: " + itos(loops.size()) + " indices: " + itos(indices.size()));
-
VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID());
}
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp
index 26fd5ed658..2cb59c871c 100644
--- a/scene/3d/baked_lightmap.cpp
+++ b/scene/3d/baked_lightmap.cpp
@@ -374,9 +374,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi
capture_subdiv--;
css *= 2.0;
}
-
- print_line("bake subdiv: " + itos(bake_subdiv));
- print_line("capture subdiv: " + itos(capture_subdiv));
}
baker.begin_bake(bake_subdiv, bake_bounds);
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 8b2000d2e9..fa14174089 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -921,8 +921,6 @@ void CPUParticles::_update_particle_data_buffer() {
t = un_transform * t;
}
- // print_line(" particle " + itos(i) + ": " + String(r[idx].active ? "[x]" : "[ ]") + "\n\txform " + r[idx].transform + "\n\t" + r[idx].velocity + "\n\tcolor: " + r[idx].color);
-
if (r[idx].active) {
ptr[0] = t.basis.elements[0][0];
ptr[1] = t.basis.elements[0][1];
@@ -1190,7 +1188,7 @@ void CPUParticles::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime", PROPERTY_HINT_EXP_RANGE, "0.01,600.0,0.01"), "set_lifetime", "get_lifetime");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "preprocess", PROPERTY_HINT_EXP_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_speed_scale", "get_speed_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp
index f5b77d361c..8d84d2408c 100644
--- a/scene/3d/navigation.cpp
+++ b/scene/3d/navigation.cpp
@@ -120,9 +120,7 @@ void Navigation::_navmesh_link(int p_id) {
pending.edge = j;
p.edges.write[j].P = C->get().pending.push_back(pending);
continue;
- //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
- //ERR_CONTINUE(C->get().B!=NULL); //wut
C->get().B = &p;
C->get().B_edge = j;
@@ -312,7 +310,6 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector
if (!begin_poly || !end_poly) {
- //print_line("No Path Path");
return Vector<Vector3>(); //no path
}
@@ -322,7 +319,6 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector
path.resize(2);
path.write[0] = begin_point;
path.write[1] = end_point;
- //print_line("Direct Path");
return path;
}
@@ -347,7 +343,6 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector
while (!found_route) {
if (open_list.size() == 0) {
- //print_line("NOU OPEN LIST");
break;
}
//check open list
@@ -581,10 +576,6 @@ Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Ve
}
}
- if (closest_navmesh && closest_navmesh->owner) {
- //print_line("navmesh is: "+Object::cast_to<Node>(closest_navmesh->owner)->get_name());
- }
-
return closest_point;
}
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 4900692155..6ba569ac75 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -329,7 +329,7 @@ void Particles::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime", PROPERTY_HINT_EXP_RANGE, "0.01,600.0,0.01"), "set_lifetime", "get_lifetime");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "preprocess", PROPERTY_HINT_EXP_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_speed_scale", "get_speed_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp
index 7988c43eab..a30fc0ac3e 100644
--- a/scene/3d/physics_joint.cpp
+++ b/scene/3d/physics_joint.cpp
@@ -48,18 +48,14 @@ void Joint::_update_joint(bool p_only_free) {
Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
- if (!node_a || !node_b)
- return;
-
PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a);
PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b);
- if (!body_a || !body_b)
- return;
-
- if (!body_a) {
+ if (!body_a && body_b)
SWAP(body_a, body_b);
- }
+
+ if (!body_a)
+ return;
joint = _configure_joint(body_a, body_b);
@@ -69,7 +65,8 @@ void Joint::_update_joint(bool p_only_free) {
PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority);
ba = body_a->get_rid();
- bb = body_b->get_rid();
+ if (body_b)
+ bb = body_b->get_rid();
PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
}
diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp
index 26958930e4..f9d096633c 100644
--- a/scene/3d/vehicle_body.cpp
+++ b/scene/3d/vehicle_body.cpp
@@ -366,22 +366,14 @@ void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) {
const Vector3 &right = wheel.m_raycastInfo.m_wheelAxleWS;
Vector3 fwd = up.cross(right);
fwd = fwd.normalized();
- //up = right.cross(fwd);
- //up.normalize();
//rotate around steering over de wheelAxleWS
real_t steering = wheel.steers ? m_steeringValue : 0.0;
- //print_line(itos(p_idx)+": "+rtos(steering));
Basis steeringMat(up, steering);
Basis rotatingMat(right, wheel.m_rotation);
- /*
- if (p_idx==1)
- print_line("steeringMat " +steeringMat);
- */
-
Basis basis2(
right[0], up[0], fwd[0],
right[1], up[1], fwd[1],
@@ -420,8 +412,6 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) {
wheel.m_raycastInfo.m_groundObject = 0;
if (col) {
- //print_line("WHEEL "+itos(p_idx)+" FROM "+source+" TO: "+target);
- //print_line("WHEEL "+itos(p_idx)+" COLLIDE? "+itos(col));
param = source.distance_to(rr.position) / source.distance_to(target);
depth = raylen * param;
wheel.m_raycastInfo.m_contactNormalWS = rr.normal;
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp
index f3abdc6bbe..e846e1763d 100644
--- a/scene/3d/voxel_light_baker.cpp
+++ b/scene/3d/voxel_light_baker.cpp
@@ -491,8 +491,6 @@ Vector<Color> VoxelLightBaker::_get_bake_texture(Ref<Image> p_image, const Color
p_image = p_image->duplicate();
if (p_image->is_compressed()) {
- print_line("DECOMPRESSING!!!!");
-
p_image->decompress();
}
p_image->convert(Image::FORMAT_RGBA8);
@@ -859,7 +857,6 @@ void VoxelLightBaker::plot_light_directional(const Vector3 &p_direction, const C
int idx = first_leaf;
while (idx >= 0) {
- //print_line("plot idx " + itos(idx));
Light *light = &light_data[idx];
Vector3 to(light->x + 0.5, light->y + 0.5, light->z + 0.5);
@@ -949,7 +946,6 @@ void VoxelLightBaker::plot_light_omni(const Vector3 &p_pos, const Color &p_color
int idx = first_leaf;
while (idx >= 0) {
- //print_line("plot idx " + itos(idx));
Light *light = &light_data[idx];
Vector3 to(light->x + 0.5, light->y + 0.5, light->z + 0.5);
@@ -1079,7 +1075,6 @@ void VoxelLightBaker::plot_light_spot(const Vector3 &p_pos, const Vector3 &p_axi
int idx = first_leaf;
while (idx >= 0) {
- //print_line("plot idx " + itos(idx));
Light *light = &light_data[idx];
Vector3 to(light->x + 0.5, light->y + 0.5, light->z + 0.5);
@@ -1498,12 +1493,8 @@ void VoxelLightBaker::_sample_baked_octree_filtered_and_anisotropic(const Vector
for (int i = 0; i < 6; i++) {
//anisotropic read light
float amount = p_direction.dot(aniso_normal[i]);
- //if (c == 0) {
- // print_line("\t" + itos(n) + " aniso " + itos(i) + " " + rtos(light[cell].accum[i][0]) + " VEC: " + aniso_normal[i]);
- //}
if (amount < 0)
amount = 0;
- //amount = 1;
color[c][n].x += light[cell].accum[i][0] * amount;
color[c][n].y += light[cell].accum[i][1] * amount;
color[c][n].z += light[cell].accum[i][2] * amount;
@@ -1513,8 +1504,6 @@ void VoxelLightBaker::_sample_baked_octree_filtered_and_anisotropic(const Vector
color[c][n].y += cells[cell].emission[1];
color[c][n].z += cells[cell].emission[2];
}
-
- //print_line("\tlev " + itos(c) + " - " + itos(n) + " alpha: " + rtos(cells[test_cell].alpha) + " col: " + color[c][n]);
}
}
@@ -1559,8 +1548,6 @@ void VoxelLightBaker::_sample_baked_octree_filtered_and_anisotropic(const Vector
r_color = color_interp[0].linear_interpolate(color_interp[1], level_filter);
r_alpha = Math::lerp(alpha_interp[0], alpha_interp[1], level_filter);
-
- // print_line("pos: " + p_posf + " level " + rtos(p_level) + " down to " + itos(target_level) + "." + rtos(level_filter) + " color " + r_color + " alpha " + rtos(r_alpha));
}
Vector3 VoxelLightBaker::_voxel_cone_trace(const Vector3 &p_pos, const Vector3 &p_normal, float p_aperture) {
@@ -1577,8 +1564,6 @@ Vector3 VoxelLightBaker::_voxel_cone_trace(const Vector3 &p_pos, const Vector3 &
while (dist < max_distance && alpha < 0.95) {
float diameter = MAX(1.0, 2.0 * p_aperture * dist);
- //print_line("VCT: pos " + (p_pos + dist * p_normal) + " dist " + rtos(dist) + " mipmap " + rtos(log2(diameter)) + " alpha " + rtos(alpha));
- //Plane scolor = textureLod(probe, (pos + dist * direction) * cell_size, log2(diameter) );
_sample_baked_octree_filtered_and_anisotropic(p_pos + dist * p_normal, p_normal, log2(diameter), scolor, salpha);
float a = (1.0 - alpha);
color += scolor * a;
@@ -1601,7 +1586,6 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const
Vector3 bitangent = tangent.cross(p_normal).normalized();
Basis normal_xform = Basis(tangent, bitangent, p_normal).transposed();
- // print_line("normal xform: " + normal_xform);
const Vector3 *cone_dirs;
const float *cone_weights;
int cone_dir_count;
@@ -1667,10 +1651,7 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const
Vector3 accum;
for (int i = 0; i < cone_dir_count; i++) {
- // if (i > 0)
- // continue;
Vector3 dir = normal_xform.xform(cone_dirs[i]).normalized(); //normal may not completely correct when transformed to cell
- //print_line("direction: " + dir);
accum += _voxel_cone_trace(p_pos, dir, cone_aperture) * cone_weights[i];
}
@@ -1802,7 +1783,6 @@ void VoxelLightBaker::_lightmap_bake_point(uint32_t p_x, LightMap *p_line) {
LightMap *pixel = &p_line[p_x];
if (pixel->pos == Vector3())
return;
- //print_line("pos: " + pixel->pos + " normal " + pixel->normal);
switch (bake_mode) {
case BAKE_MODE_CONE_TRACE: {
pixel->light = _compute_pixel_light_at_pos(pixel->pos, pixel->normal) * energy;
@@ -1810,8 +1790,6 @@ void VoxelLightBaker::_lightmap_bake_point(uint32_t p_x, LightMap *p_line) {
case BAKE_MODE_RAY_TRACE: {
pixel->light = _compute_ray_trace_at_pos(pixel->pos, pixel->normal) * energy;
} break;
- // pixel->light = Vector3(1, 1, 1);
- //}
}
}
@@ -1895,7 +1873,6 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh
if (bake_mode == BAKE_MODE_RAY_TRACE) {
//blur
- print_line("bluring, use pos for separatable copy");
//gauss kernel, 7 step sigma 2
static const float gauss_kernel[4] = { 0.214607, 0.189879, 0.131514, 0.071303 };
//horizontal pass
@@ -1960,8 +1937,6 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh
#pragma omp parallel
#endif
for (int i = 0; i < height; i++) {
-
- //print_line("bake line " + itos(i) + " / " + itos(height));
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 1)
#endif
@@ -2304,7 +2279,6 @@ Ref<MultiMesh> VoxelLightBaker::create_debug_multimesh(DebugMode p_mode) {
mm->set_transform_format(MultiMesh::TRANSFORM_3D);
mm->set_color_format(MultiMesh::COLOR_8BIT);
- print_line("leaf voxels: " + itos(leaf_voxel_count));
mm->set_instance_count(leaf_voxel_count);
Ref<ArrayMesh> mesh;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index a660665d3f..d8db1973d2 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -960,8 +960,6 @@ Error AnimationPlayer::add_animation(const StringName &p_name, const Ref<Animati
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
- //print_line("Add anim: "+String(p_name)+" name: "+p_animation->get_name());
-
if (animation_set.has(p_name)) {
_unref_anim(animation_set[p_name].animation);
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 76f0ee9359..73bd00e456 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -109,12 +109,12 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p
Ref<AnimationNode> node = blend_tree->get_node(node_name);
//inputs.write[p_input].last_pass = state->last_pass;
- float activity=0;
+ float activity = 0;
float ret = _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity);
Vector<AnimationTree::Activity> *activity_ptr = state->tree->input_activity_map.getptr(base_path);
- if (activity_ptr && p_input<activity_ptr->size()) {
+ if (activity_ptr && p_input < activity_ptr->size()) {
activity_ptr->write[p_input].last_pass = state->last_pass;
activity_ptr->write[p_input].activity = activity;
}
@@ -698,6 +698,28 @@ void AnimationTree::_process_graph(float p_delta) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node(animation_player));
+ ObjectID current_animation_player = 0;
+
+ if (player) {
+ current_animation_player = player->get_instance_id();
+ }
+
+ if (last_animation_player != current_animation_player) {
+
+ if (last_animation_player) {
+ Object *old_player = ObjectDB::get_instance(last_animation_player);
+ if (old_player) {
+ old_player->disconnect("caches_cleared", this, "_clear_caches");
+ }
+ }
+
+ if (player) {
+ player->connect("caches_cleared", this, "_clear_caches");
+ }
+
+ last_animation_player = current_animation_player;
+ }
+
if (!player) {
ERR_PRINT("AnimationTree: path points to a node not an AnimationPlayer, disabling playback");
set_active(false);
@@ -1197,6 +1219,13 @@ void AnimationTree::_notification(int p_what) {
if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_caches();
+ if (last_animation_player) {
+
+ Object *old_player = ObjectDB::get_instance(last_animation_player);
+ if (old_player) {
+ old_player->disconnect("caches_cleared", this, "_clear_caches");
+ }
+ }
}
}
@@ -1296,13 +1325,13 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<A
if (node->get_input_count() && !input_activity_map.has(p_base_path)) {
Vector<Activity> activity;
- for(int i=0;i<node->get_input_count();i++) {
+ for (int i = 0; i < node->get_input_count(); i++) {
Activity a;
- a.last_pass=0;
+ a.last_pass = 0;
activity.push_back(a);
}
input_activity_map[p_base_path] = activity;
- input_activity_map_get[String(p_base_path).substr(0,String(p_base_path).length()-1)]=&input_activity_map[p_base_path];
+ input_activity_map_get[String(p_base_path).substr(0, String(p_base_path).length() - 1)] = &input_activity_map[p_base_path];
}
List<PropertyInfo> plist;
@@ -1402,14 +1431,14 @@ void AnimationTree::rename_parameter(const String &p_base, const String &p_new_b
_update_properties();
}
-float AnimationTree::get_connection_activity(const StringName& p_path,int p_connection) const {
+float AnimationTree::get_connection_activity(const StringName &p_path, int p_connection) const {
if (!input_activity_map_get.has(p_path)) {
return 0;
}
const Vector<Activity> *activity = input_activity_map_get[p_path];
- if (!activity || p_connection<0 || p_connection>=activity->size()) {
+ if (!activity || p_connection < 0 || p_connection >= activity->size()) {
return 0;
}
@@ -1420,7 +1449,6 @@ float AnimationTree::get_connection_activity(const StringName& p_path,int p_conn
return (*activity)[p_connection].activity;
}
-
void AnimationTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active);
ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active);
@@ -1447,6 +1475,7 @@ void AnimationTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance);
ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationTree::_node_removed);
+ ClassDB::bind_method(D_METHOD("_clear_caches"), &AnimationTree::_clear_caches);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode"), "set_tree_root", "get_tree_root");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player");
@@ -1468,6 +1497,7 @@ AnimationTree::AnimationTree() {
setup_pass = 1;
started = true;
properties_dirty = true;
+ last_animation_player = 0;
}
AnimationTree::~AnimationTree() {
diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h
index 70f3932f21..6cb363d50a 100644
--- a/scene/animation/animation_tree.h
+++ b/scene/animation/animation_tree.h
@@ -266,6 +266,8 @@ private:
void _update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node);
+ ObjectID last_animation_player;
+
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
diff --git a/scene/animation/skeleton_ik.cpp b/scene/animation/skeleton_ik.cpp
index 9b1cb1369a..69975e6195 100644
--- a/scene/animation/skeleton_ik.cpp
+++ b/scene/animation/skeleton_ik.cpp
@@ -54,9 +54,9 @@ FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::add_child(
}
/// Build a chain that starts from the root to tip
-void FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain) {
+bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain) {
- ERR_FAIL_COND(-1 == p_task->root_bone);
+ ERR_FAIL_COND_V(-1 == p_task->root_bone, false);
Chain &chain(p_task->chain);
@@ -77,8 +77,8 @@ void FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain
for (int x = p_task->end_effectors.size() - 1; 0 <= x; --x) {
const EndEffector *ee(&p_task->end_effectors[x]);
- ERR_FAIL_COND(p_task->root_bone >= ee->tip_bone);
- ERR_FAIL_INDEX(ee->tip_bone, p_task->skeleton->get_bone_count());
+ ERR_FAIL_COND_V(p_task->root_bone >= ee->tip_bone, false);
+ ERR_FAIL_INDEX_V(ee->tip_bone, p_task->skeleton->get_bone_count(), false);
sub_chain_size = 0;
// Picks all IDs that composing a single chain in reverse order (except the root)
@@ -133,6 +133,7 @@ void FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain
break;
}
}
+ return true;
}
void FabrikInverseKinematic::update_chain(const Skeleton *p_sk, ChainItem *p_chain_item) {
@@ -247,7 +248,10 @@ FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleto
task->end_effectors.push_back(ee);
task->goal_global_transform = goal_transform;
- build_chain(task);
+ if (!build_chain(task)) {
+ free_task(task);
+ return NULL;
+ }
return task;
}
@@ -535,8 +539,10 @@ void SkeletonIK::reload_chain() {
return;
task = FabrikInverseKinematic::create_simple_task(skeleton, skeleton->find_bone(root_bone), skeleton->find_bone(tip_bone), _get_target_transform());
- task->max_iterations = max_iterations;
- task->min_distance = min_distance;
+ if (task) {
+ task->max_iterations = max_iterations;
+ task->min_distance = min_distance;
+ }
}
void SkeletonIK::reload_goal() {
diff --git a/scene/animation/skeleton_ik.h b/scene/animation/skeleton_ik.h
index 08fb00e798..202d6959bb 100644
--- a/scene/animation/skeleton_ik.h
+++ b/scene/animation/skeleton_ik.h
@@ -123,7 +123,7 @@ public:
private:
/// Init a chain that starts from the root to tip
- static void build_chain(Task *p_task, bool p_force_simple_chain = true);
+ static bool build_chain(Task *p_task, bool p_force_simple_chain = true);
static void update_chain(const Skeleton *p_sk, ChainItem *p_chain_item);
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index acdbd9de08..d17ae1d84c 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -31,7 +31,6 @@
#include "base_button.h"
#include "os/keyboard.h"
-#include "print_string.h"
#include "scene/main/viewport.h"
#include "scene/scene_string_names.h"
@@ -361,7 +360,6 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
return DRAW_DISABLED;
};
- //print_line("press attempt: "+itos(status.press_attempt)+" hover: "+itos(status.hovering)+" pressed: "+itos(status.pressed));
if (status.press_attempt == false && status.hovering && !status.pressed) {
return DRAW_HOVER;
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 03b25a138f..a34f2f1ad5 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -29,7 +29,6 @@
/*************************************************************************/
#include "button.h"
-#include "print_string.h"
#include "servers/visual_server.h"
#include "translation.h"
@@ -76,8 +75,6 @@ void Button::_notification(int p_what) {
Color color;
Color color_icon(1, 1, 1, 1);
- //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
-
Ref<StyleBox> style = get_stylebox("normal");
switch (get_draw_mode()) {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 18f06eca31..e094a063be 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -357,7 +357,7 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
if (data.shader_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph", hint));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint));
}
}
{
@@ -769,6 +769,7 @@ void Control::force_drag(const Variant &p_data, Control *p_control) {
void Control::set_drag_preview(Control *p_control) {
ERR_FAIL_COND(!is_inside_tree());
+ ERR_FAIL_COND(get_viewport()->gui_is_dragging());
get_viewport()->_gui_set_drag_preview(this, p_control);
}
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 635f812805..9bddaa7d29 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -284,7 +284,13 @@ bool FileDialog::_is_open_should_be_disabled() {
if (mode == MODE_OPEN_ANY || mode == MODE_SAVE_FILE)
return false;
- TreeItem *ti = tree->get_selected();
+ TreeItem *ti = tree->get_next_selected(tree->get_root());
+ while (ti) {
+ TreeItem *prev_ti = ti;
+ ti = tree->get_next_selected(tree->get_root());
+ if (ti == prev_ti)
+ break;
+ }
// We have something that we can't select?
if (!ti)
return mode != MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
@@ -328,6 +334,10 @@ void FileDialog::deselect_items() {
}
}
+void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selected) {
+ _tree_selected();
+}
+
void FileDialog::_tree_selected() {
TreeItem *ti = tree->get_selected();
@@ -754,6 +764,7 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input);
+ ClassDB::bind_method(D_METHOD("_tree_multi_selected"), &FileDialog::_tree_multi_selected);
ClassDB::bind_method(D_METHOD("_tree_selected"), &FileDialog::_tree_selected);
ClassDB::bind_method(D_METHOD("_tree_item_activated"), &FileDialog::_tree_item_activated);
ClassDB::bind_method(D_METHOD("_dir_entered"), &FileDialog::_dir_entered);
@@ -794,7 +805,7 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mode_overrides_title"), "set_mode_overrides_title", "is_mode_overriding_title");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open one,Open many,Open folder,Open any,Save"), "set_mode", "get_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open File,Open Files,Open Folder,Open Any,Save"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"), "set_access", "get_access");
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "filters"), "set_filters", "get_filters");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_hidden_files"), "set_show_hidden_files", "is_showing_hidden_files");
@@ -890,6 +901,7 @@ FileDialog::FileDialog() {
_update_drives();
connect("confirmed", this, "_action_pressed");
+ tree->connect("multi_selected", this, "_tree_multi_selected", varray(), CONNECT_DEFERRED);
tree->connect("cell_selected", this, "_tree_selected", varray(), CONNECT_DEFERRED);
tree->connect("item_activated", this, "_tree_item_activated", varray());
tree->connect("nothing_selected", this, "deselect_items");
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index ad483d5dab..3227f1c3a8 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -104,6 +104,7 @@ private:
void update_file_list();
void update_filters();
+ void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected);
void _tree_selected();
void _select_drive(int p_idx);
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index d61bd97c2a..9f5c12e87f 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -502,7 +502,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
bool selected = !items[j].selected;
select(j, false);
if (selected)
- emit_signal("multi_selected", i, true);
+ emit_signal("multi_selected", j, true);
}
if (mb->get_button_index() == BUTTON_RIGHT) {
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 549daecdae..1f3d5e6e13 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -866,15 +866,14 @@ void LineEdit::_notification(int p_what) {
void LineEdit::copy_text() {
- if (selection.enabled) {
-
+ if (selection.enabled && !pass) {
OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
}
}
void LineEdit::cut_text() {
- if (selection.enabled) {
+ if (selection.enabled && !pass) {
OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
selection_delete();
}
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index d862e8669c..8560efdde5 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -68,8 +68,6 @@ void LinkButton::_notification(int p_what) {
Color color;
bool do_underline = false;
- //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
-
switch (get_draw_mode()) {
case DRAW_NORMAL: {
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index a3748bf14c..a5f9bea1b1 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -2034,7 +2034,6 @@ void RichTextLabel::selection_copy() {
if (text != "") {
OS::get_singleton()->set_clipboard(text);
- //print_line("COPY: "+text);
}
}
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 9a8dc62e4e..ec98b01ced 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -5640,6 +5640,10 @@ void TextEdit::_confirm_completion() {
end_complex_operation();
_cancel_completion();
+
+ if (last_completion_char == '(') {
+ query_code_comple();
+ }
}
void TextEdit::_cancel_code_hint() {
@@ -5692,15 +5696,12 @@ void TextEdit::_update_completion_candidates() {
bool pre_keyword = false;
bool cancel = false;
- //print_line("inquote: "+itos(inquote)+"first quote "+itos(first_quote)+" cofs-1 "+itos(cofs-1));
if (!inquote && first_quote == cofs - 1) {
//no completion here
- //print_line("cancel!");
cancel = true;
} else if (inquote && first_quote != -1) {
s = l.substr(first_quote, cofs - first_quote);
- //print_line("s: 1"+s);
} else if (cofs > 0 && l[cofs - 1] == ' ') {
int kofs = cofs - 1;
String kw;
@@ -5713,7 +5714,6 @@ void TextEdit::_update_completion_candidates() {
}
pre_keyword = keywords.has(kw);
- //print_line("KW "+kw+"? "+itos(pre_keyword));
} else {
@@ -5755,43 +5755,23 @@ void TextEdit::_update_completion_candidates() {
completion_strings.write[i] = completion_strings[i].unquote().quote("'");
}
- if (s == completion_strings[i]) {
- // A perfect match, stop completion
- _cancel_completion();
- return;
+ if (completion_strings[i].begins_with(s)) {
+ completion_options.push_back(completion_strings[i]);
}
+ }
- if (s.is_subsequence_ofi(completion_strings[i])) {
- // don't remove duplicates if no input is provided
- if (s != "" && completion_options.find(completion_strings[i]) != -1) {
- continue;
- }
- // Calculate the similarity to keep completions in good order
- float similarity;
- if (completion_strings[i].begins_with(s)) {
- // Substrings (same case) are the best candidates
- similarity = 1.2;
- } else if (completion_strings[i].to_lower().begins_with(s.to_lower())) {
- // then any substrings
- similarity = 1.1;
- } else {
- // Otherwise compute the similarity
- similarity = s.to_lower().similarity(completion_strings[i].to_lower());
+ if (completion_options.size() == 0) {
+ for (int i = 0; i < completion_strings.size(); i++) {
+ if (s.is_subsequence_of(completion_strings[i])) {
+ completion_options.push_back(completion_strings[i]);
}
+ }
+ }
- int comp_size = completion_options.size();
- if (comp_size == 0) {
+ if (completion_options.size() == 0) {
+ for (int i = 0; i < completion_strings.size(); i++) {
+ if (s.is_subsequence_ofi(completion_strings[i])) {
completion_options.push_back(completion_strings[i]);
- sim_cache.push_back(similarity);
- } else {
- float comp_sim;
- int pos = 0;
- do {
- comp_sim = sim_cache[pos++];
- } while (pos < comp_size && similarity < comp_sim);
- pos = similarity > comp_sim ? pos - 1 : pos; // Pos will be off by one
- completion_options.insert(pos, completion_strings[i]);
- sim_cache.insert(pos, similarity);
}
}
}
@@ -5799,7 +5779,12 @@ void TextEdit::_update_completion_candidates() {
if (completion_options.size() == 0) {
//no options to complete, cancel
_cancel_completion();
+ return;
+ }
+ if (completion_options.size() == 1 && s == completion_options[0]) {
+ // A perfect match, stop completion
+ _cancel_completion();
return;
}
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index 6e4fe88dbf..ff90576c1b 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -266,6 +266,8 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F
}
}
+ p_texture->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
+
RID ci = get_canvas_item();
VS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, true, p_modulate);
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index f6905e7c2e..e30f58e012 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2082,9 +2082,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
} else {
Object *obj = ClassDB::instance(get_class());
- if (!obj) {
- print_line("could not duplicate: " + String(get_class()));
- }
+ ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class()));
ERR_FAIL_COND(!obj);
node = Object::cast_to<Node>(obj);
if (!node)
@@ -2179,9 +2177,7 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
Node *node = NULL;
Object *obj = ClassDB::instance(get_class());
- if (!obj) {
- print_line("could not duplicate: " + String(get_class()));
- }
+ ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class()));
ERR_FAIL_COND_V(!obj, NULL);
node = Object::cast_to<Node>(obj);
if (!node)
@@ -2472,7 +2468,7 @@ static void _Node_debug_sn(Object *p_obj) {
path = n->get_name();
else
path = String(p->get_name()) + "/" + p->get_path_to(n);
- print_line(itos(p_obj->get_instance_id()) + "- Stray Node: " + path + " (Type: " + n->get_class() + ")");
+ print_line(itos(p_obj->get_instance_id()) + " - Stray Node: " + path + " (Type: " + n->get_class() + ")");
}
void Node::_print_stray_nodes() {
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index e99f785848..1d23650a1e 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -1195,8 +1195,6 @@ void SceneTree::_update_root_rect() {
VisualServer::get_singleton()->black_bars_set_margins(0, 0, 0, 0);
}
- //print_line("VP SIZE: "+viewport_size+" OFFSET: "+offset+" = "+(offset*2+viewport_size));
- //print_line("SS: "+video_mode);
switch (stretch_mode) {
case STRETCH_MODE_2D: {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index f92b6e7583..d1b3eb9d9a 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -185,6 +185,7 @@ public:
Viewport::GUI::GUI() {
+ dragging = false;
mouse_focus = NULL;
mouse_click_grabber = NULL;
mouse_focus_button = -1;
@@ -1506,12 +1507,6 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
if (Object::cast_to<Viewport>(p_node))
return NULL;
- Control *c = Object::cast_to<Control>(p_node);
-
- if (c) {
- //print_line("at "+String(c->get_path())+" POS "+c->get_position()+" bt "+p_xform);
- }
-
//subwindows first!!
if (!p_node->is_visible()) {
@@ -1524,6 +1519,8 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
if (matrix.basis_determinant() == 0.0f)
return NULL;
+ Control *c = Object::cast_to<Control>(p_node);
+
if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) {
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
@@ -1654,7 +1651,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
*/
gui.mouse_focus = _gui_find_control(pos);
- //print_line("has mf "+itos(gui.mouse_focus!=NULL));
gui.mouse_focus_button = mb->get_button_index();
if (!gui.mouse_focus) {
@@ -1683,11 +1679,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
arr.push_back(gui.mouse_focus->get_class());
ScriptDebugger::get_singleton()->send_message("click_ctrl", arr);
}
-
-/*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) {
-
- print_line(String(gui.mouse_focus->get_path())+" - "+pos);
- }*/
#endif
if (mb->get_button_index() == BUTTON_LEFT) { //assign focus
@@ -1728,6 +1719,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
gui.drag_data = Variant();
+ gui.dragging = false;
if (gui.drag_preview) {
memdelete(gui.drag_preview);
@@ -1757,6 +1749,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
gui.drag_data = Variant();
+ gui.dragging = false;
_propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
//change mouse accordingly
}
@@ -1819,10 +1812,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *control = Object::cast_to<Control>(ci);
if (control) {
+ gui.dragging = true;
gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum);
if (gui.drag_data.get_type() != Variant::NIL) {
gui.mouse_focus = NULL;
+ } else {
+ gui.dragging = false;
}
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
@@ -2262,6 +2258,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *
ERR_EXPLAIN("Drag data must be a value");
ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
+ gui.dragging = true;
gui.drag_data = p_data;
gui.mouse_focus = NULL;
@@ -2701,6 +2698,9 @@ bool Viewport::is_snap_controls_to_pixels_enabled() const {
return snap_controls_to_pixels;
}
+bool Viewport::gui_is_dragging() const {
+ return gui.dragging;
+}
void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr);
@@ -2787,6 +2787,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack);
ClassDB::bind_method(D_METHOD("gui_get_drag_data"), &Viewport::gui_get_drag_data);
+ ClassDB::bind_method(D_METHOD("gui_is_dragging"), &Viewport::gui_is_dragging);
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index e4ef373c77..450f235b79 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -274,6 +274,7 @@ private:
bool roots_order_dirty;
List<Control *> roots;
int canvas_sort_index; //for sorting items with canvas as root
+ bool dragging;
GUI();
} gui;
@@ -474,6 +475,8 @@ public:
void _subwindow_visibility_changed();
+ bool gui_is_dragging() const;
+
Viewport();
~Viewport();
};
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index da4e2f991d..dccdd244ef 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -150,7 +150,6 @@
#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/scene_format_text.h"
#include "scene/resources/segment_shape_2d.h"
-#include "scene/resources/shader_graph.h"
#include "scene/resources/shape_line_2d.h"
#include "scene/resources/sky_box.h"
#include "scene/resources/sphere_shape.h"
@@ -564,6 +563,9 @@ void register_scene_types() {
/* REGISTER RESOURCES */
ClassDB::register_virtual_class<Shader>();
+ ClassDB::register_class<ParticlesMaterial>();
+ SceneTree::add_idle_callback(ParticlesMaterial::flush_changes);
+ ParticlesMaterial::init_shaders();
#ifndef _3D_DISABLED
ClassDB::register_virtual_class<Mesh>();
@@ -581,10 +583,6 @@ void register_scene_types() {
SceneTree::add_idle_callback(SpatialMaterial::flush_changes);
SpatialMaterial::init_shaders();
- ClassDB::register_class<ParticlesMaterial>();
- SceneTree::add_idle_callback(ParticlesMaterial::flush_changes);
- ParticlesMaterial::init_shaders();
-
ClassDB::register_class<MultiMesh>();
ClassDB::register_class<MeshLibrary>();
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 7041b62487..58e6db3f5e 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -2906,8 +2906,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
//able to optimize more
erase = false;
} else {
-
- //print_line(itos(i)+"because of interp");
}
}
}
diff --git a/scene/resources/bit_mask.cpp b/scene/resources/bit_mask.cpp
index 39206ed043..5694099754 100644
--- a/scene/resources/bit_mask.cpp
+++ b/scene/resources/bit_mask.cpp
@@ -492,18 +492,14 @@ static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_
}
} while (reenter || popped);
-#ifdef DEBUG_ENABLED
- print_line("max stack size: " + itos(stack.size()));
-#endif
+ print_verbose("BitMap: Max stack size: " + itos(stack.size()));
}
Vector<Vector<Vector2> > BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, float p_epsilon) const {
Rect2i r = Rect2i(0, 0, width, height).clip(p_rect);
+ print_verbose("BitMap: Rect: " + r);
-#ifdef DEBUG_ENABLED
- print_line("Rect: " + r);
-#endif
Point2i from;
Ref<BitMap> fill;
fill.instance();
@@ -515,13 +511,9 @@ Vector<Vector<Vector2> > BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, fl
if (!fill->get_bit(Point2(j, i)) && get_bit(Point2(j, i))) {
Vector<Vector2> polygon = _march_square(r, Point2i(j, i));
-#ifdef DEBUG_ENABLED
- print_line("pre reduce: " + itos(polygon.size()));
-#endif
+ print_verbose("BitMap: Pre reduce: " + itos(polygon.size()));
polygon = reduce(polygon, r, p_epsilon);
-#ifdef DEBUG_ENABLED
- print_line("post reduce: " + itos(polygon.size()));
-#endif
+ print_verbose("BitMap: Post reduce: " + itos(polygon.size()));
polygons.push_back(polygon);
fill_bits(this, fill, Point2i(j, i), r);
}
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index 2f2abd4e08..4df849df6a 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -435,8 +435,6 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
break;
}
- //print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" X: "+itos(tex_x)+" Y: "+itos(tex_y));
-
if (ret.index == -1) {
//could not find texture to fit, create one
ret.x = 0;
@@ -1036,6 +1034,8 @@ SelfList<DynamicFont>::List DynamicFont::dynamic_fonts;
DynamicFont::DynamicFont() :
font_list(this) {
+ cache_id.size = 16;
+ outline_cache_id.size = 16;
spacing_top = 0;
spacing_bottom = 0;
spacing_char = 0;
diff --git a/scene/resources/dynamic_font_stb.cpp b/scene/resources/dynamic_font_stb.cpp
index 29f1106d16..be394e19c4 100644
--- a/scene/resources/dynamic_font_stb.cpp
+++ b/scene/resources/dynamic_font_stb.cpp
@@ -214,7 +214,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
int advance;
stbtt_GetCodepointHMetrics(&font->info, p_char, &advance, 0);
- //print_line("char has no bitmap: "+itos(p_char)+" but advance is "+itos(advance*scale));
Character ch;
ch.texture_idx = -1;
ch.advance = advance * scale;
@@ -279,8 +278,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
break;
}
- //print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" X: "+itos(tex_x)+" Y: "+itos(tex_y));
-
if (tex_index == -1) {
//could not find texture to fit, create one
tex_x = 0;
@@ -364,8 +361,6 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
chr.rect = Rect2(tex_x + rect_margin, tex_y + rect_margin, w, h);
- //print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" RECT: "+chr.rect+" X OFS: "+itos(xofs)+" Y OFS: "+itos(yofs));
-
char_map[p_char] = chr;
stbtt_FreeBitmap(cpbitmap, NULL);
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index dcd87a2a61..e6ef956dc5 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -482,6 +482,11 @@ void Mesh::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint");
+ ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count);
+ ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &Mesh::surface_get_arrays);
+ ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &Mesh::surface_get_blend_shape_arrays);
+ ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &Mesh::surface_get_material);
+
BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
@@ -1241,7 +1246,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe
surfaces_tools.push_back(st); //stay there
}
- print_line("gen indices: " + itos(gen_index_count));
+ print_verbose("Mesh: Gen indices: " + itos(gen_index_count));
//go through all indices
for (int i = 0; i < gen_index_count; i += 3) {
@@ -1313,7 +1318,6 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &ArrayMesh::get_blend_shape_mode);
ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
- ClassDB::bind_method(D_METHOD("get_surface_count"), &ArrayMesh::get_surface_count);
ClassDB::bind_method(D_METHOD("surface_remove", "surf_idx"), &ArrayMesh::surface_remove);
ClassDB::bind_method(D_METHOD("surface_update_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_region);
ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &ArrayMesh::surface_get_array_len);
@@ -1321,12 +1325,9 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &ArrayMesh::surface_get_format);
ClassDB::bind_method(D_METHOD("surface_get_primitive_type", "surf_idx"), &ArrayMesh::surface_get_primitive_type);
ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &ArrayMesh::surface_set_material);
- ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &ArrayMesh::surface_get_material);
ClassDB::bind_method(D_METHOD("surface_find_by_name", "name"), &ArrayMesh::surface_find_by_name);
ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name);
ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name);
- ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &ArrayMesh::surface_get_arrays);
- ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &ArrayMesh::surface_get_blend_shape_arrays);
ClassDB::bind_method(D_METHOD("create_trimesh_shape"), &ArrayMesh::create_trimesh_shape);
ClassDB::bind_method(D_METHOD("create_convex_shape"), &ArrayMesh::create_convex_shape);
ClassDB::bind_method(D_METHOD("create_outline", "margin"), &ArrayMesh::create_outline);
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 07783d5f4a..f034e07ff9 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -106,7 +106,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (i == 0 && base_scene_idx >= 0) {
//scene inheritance on root node
- //print_line("scene inherit");
Ref<PackedScene> sdata = props[base_scene_idx];
ERR_FAIL_COND_V(!sdata.is_valid(), NULL);
node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state
@@ -117,7 +116,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
} else if (n.instance >= 0) {
//instance a scene into this node
- //print_line("instance");
if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) {
String path = props[n.instance & FLAG_MASK];
@@ -141,7 +139,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
} else if (n.type == TYPE_INSTANCED) {
- //print_line("instanced");
//get the node from somewhere, it likely already exists from another instance
if (parent) {
node = parent->_get_child_by_name(snames[n.name]);
@@ -152,7 +149,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
#endif
}
} else if (ClassDB::is_class_enabled(snames[n.type])) {
- //print_line("created");
//node belongs to this scene and must be created
Object *obj = ClassDB::instance(snames[n.type]);
if (!Object::cast_to<Node>(obj)) {
@@ -491,15 +487,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
isdefault = true; //is script default value
}
- /*
- if (nd.instance<0 && ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one())) {
- continue;
- }
- */
-
- //print_line("PASSED!");
- //print_line("at: "+String(p_node->get_name())+"::"+name+": - nz: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO)+" no: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONONE));
- //print_line("value: "+String(value)+" is zero: "+itos(value.is_zero())+" is one" +itos(value.is_one()));
if (pack_state_stack.size()) {
// we are on part of an instanced subscene
diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp
deleted file mode 100644
index 070cc84863..0000000000
--- a/scene/resources/shader_graph.cpp
+++ /dev/null
@@ -1,2596 +0,0 @@
-/*************************************************************************/
-/* shader_graph.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 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. */
-/*************************************************************************/
-
-#include "shader_graph.h"
-
-#include "scene/scene_string_names.h"
-
-// FIXME: Needs to be ported to the new 3.0 shader API
-#if 0
-Array ShaderGraph::_get_node_list(ShaderType p_type) const {
-
- List<int> nodes;
- get_node_list(p_type,&nodes);
- Array arr(true);
- for (List<int>::Element *E=nodes.front();E;E=E->next())
- arr.push_back(E->get());
- return arr;
-}
-Array ShaderGraph::_get_connections(ShaderType p_type) const {
-
- List<Connection> connections;
- get_node_connections(p_type,&connections);
- Array arr(true);
- for (List<Connection>::Element *E=connections.front();E;E=E->next()) {
-
- Dictionary d(true);
- d["src_id"]=E->get().src_id;
- d["src_slot"]=E->get().src_slot;
- d["dst_id"]=E->get().dst_id;
- d["dst_slot"]=E->get().dst_slot;
- arr.push_back(d);
-
- }
- return arr;
-}
-
-void ShaderGraph::_set_data(const Dictionary &p_data) {
-
- Dictionary d=p_data;
- ERR_FAIL_COND(!d.has("shaders"));
- Array sh=d["shaders"];
- ERR_FAIL_COND(sh.size()!=3);
-
- for(int t=0;t<3;t++) {
- Array data=sh[t];
- ERR_FAIL_COND((data.size()%6)!=0);
- shader[t].node_map.clear();
- for(int i=0;i<data.size();i+=6) {
-
- Node n;
- n.id=data[i+0];
- n.type=NodeType(int(data[i+1]));
- n.pos=data[i+2];
- n.param1=data[i+3];
- n.param2=data[i+4];
-
- Array conns=data[i+5];
- ERR_FAIL_COND((conns.size()%3)!=0);
-
- for(int j=0;j<conns.size();j+=3) {
- SourceSlot ss;
- int ls=conns[j+0];
- if (ls == SLOT_DEFAULT_VALUE) {
- n.defaults[conns[j+1]]=conns[j+2];
- } else {
- ss.id=conns[j+1];
- ss.slot=conns[j+2];
- n.connections[ls]=ss;
- }
- }
- shader[t].node_map[n.id]=n;
-
- }
- }
-
- _pending_update_shader=true;
- _update_shader();
-
-}
-
-Dictionary ShaderGraph::_get_data() const {
-
- Array sh;
- for(int i=0;i<3;i++) {
- Array data;
- int ec = shader[i].node_map.size();
- data.resize(ec*6);
- int idx=0;
- for (Map<int,Node>::Element*E=shader[i].node_map.front();E;E=E->next()) {
-
- data[idx+0]=E->key();
- data[idx+1]=E->get().type;
- data[idx+2]=E->get().pos;
- data[idx+3]=E->get().param1;
- data[idx+4]=E->get().param2;
-
- Array conns;
- conns.resize(E->get().connections.size()*3+E->get().defaults.size()*3);
- int idx2=0;
- for(Map<int,SourceSlot>::Element*F=E->get().connections.front();F;F=F->next()) {
-
- conns[idx2+0]=F->key();
- conns[idx2+1]=F->get().id;
- conns[idx2+2]=F->get().slot;
- idx2+=3;
- }
- for(Map<int,Variant>::Element*F=E->get().defaults.front();F;F=F->next()) {
-
- conns[idx2+0]=SLOT_DEFAULT_VALUE;
- conns[idx2+1]=F->key();
- conns[idx2+2]=F->get();
- idx2+=3;
- }
-
- data[idx+5]=conns;
- idx+=6;
- }
- sh.push_back(data);
- }
-
- Dictionary data;
- data["shaders"]=sh;
- return data;
-}
-
-
-
-ShaderGraph::GraphError ShaderGraph::get_graph_error(ShaderType p_type) const {
-
- ERR_FAIL_INDEX_V(p_type,3,GRAPH_OK);
- return shader[p_type].error;
-}
-
-int ShaderGraph::node_count(ShaderType p_which, int p_type)
-{
- int count=0;
- for (Map<int,Node>::Element *E=shader[p_which].node_map.front();E;E=E->next())
- if (E->get().type==p_type)
- count++;
- return count;
-}
-
-void ShaderGraph::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_update_shader"),&ShaderGraph::_update_shader);
-
- ClassDB::bind_method(D_METHOD("node_add","shader_type","node_type","id"),&ShaderGraph::node_add);
- ClassDB::bind_method(D_METHOD("node_remove","shader_type","id"),&ShaderGraph::node_remove);
- ClassDB::bind_method(D_METHOD("node_set_position","shader_type","id","position"),&ShaderGraph::node_set_position);
- ClassDB::bind_method(D_METHOD("node_get_position","shader_type","id"),&ShaderGraph::node_get_position);
-
- ClassDB::bind_method(D_METHOD("node_get_type","shader_type","id"),&ShaderGraph::node_get_type);
-
- ClassDB::bind_method(D_METHOD("get_node_list","shader_type"),&ShaderGraph::_get_node_list);
-
- ClassDB::bind_method(D_METHOD("default_set_value","shader_type","id","param_id","value"), &ShaderGraph::default_set_value);
- ClassDB::bind_method(D_METHOD("default_get_value","shader_type","id","param_id"), &ShaderGraph::default_get_value);
-
- ClassDB::bind_method(D_METHOD("scalar_const_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_const_node_set_value);
- ClassDB::bind_method(D_METHOD("scalar_const_node_get_value","shader_type","id"),&ShaderGraph::scalar_const_node_get_value);
-
- ClassDB::bind_method(D_METHOD("vec_const_node_set_value","shader_type","id","value"),&ShaderGraph::vec_const_node_set_value);
- ClassDB::bind_method(D_METHOD("vec_const_node_get_value","shader_type","id"),&ShaderGraph::vec_const_node_get_value);
-
- ClassDB::bind_method(D_METHOD("rgb_const_node_set_value","shader_type","id","value"),&ShaderGraph::rgb_const_node_set_value);
- ClassDB::bind_method(D_METHOD("rgb_const_node_get_value","shader_type","id"),&ShaderGraph::rgb_const_node_get_value);
-
- ClassDB::bind_method(D_METHOD("xform_const_node_set_value","shader_type","id","value"),&ShaderGraph::xform_const_node_set_value);
- ClassDB::bind_method(D_METHOD("xform_const_node_get_value","shader_type","id"),&ShaderGraph::xform_const_node_get_value);
-
-
- //void get_node_list(ShaderType p_which,List<int> *p_node_list) const;
-
- ClassDB::bind_method(D_METHOD("texture_node_set_filter_size","shader_type","id","filter_size"),&ShaderGraph::texture_node_set_filter_size);
- ClassDB::bind_method(D_METHOD("texture_node_get_filter_size","shader_type","id"),&ShaderGraph::texture_node_get_filter_size);
-
- ClassDB::bind_method(D_METHOD("texture_node_set_filter_strength","shader_type","id","filter_strength"),&ShaderGraph::texture_node_set_filter_strength);
- ClassDB::bind_method(D_METHOD("texture_node_get_filter_strength","shader_type","id"),&ShaderGraph::texture_node_get_filter_strength);
-
- ClassDB::bind_method(D_METHOD("scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::scalar_op_node_set_op);
- ClassDB::bind_method(D_METHOD("scalar_op_node_get_op","shader_type","id"),&ShaderGraph::scalar_op_node_get_op);
-
- ClassDB::bind_method(D_METHOD("vec_op_node_set_op","shader_type","id","op"),&ShaderGraph::vec_op_node_set_op);
- ClassDB::bind_method(D_METHOD("vec_op_node_get_op","shader_type","id"),&ShaderGraph::vec_op_node_get_op);
-
- ClassDB::bind_method(D_METHOD("vec_scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::vec_scalar_op_node_set_op);
- ClassDB::bind_method(D_METHOD("vec_scalar_op_node_get_op","shader_type","id"),&ShaderGraph::vec_scalar_op_node_get_op);
-
- ClassDB::bind_method(D_METHOD("rgb_op_node_set_op","shader_type","id","op"),&ShaderGraph::rgb_op_node_set_op);
- ClassDB::bind_method(D_METHOD("rgb_op_node_get_op","shader_type","id"),&ShaderGraph::rgb_op_node_get_op);
-
-
- ClassDB::bind_method(D_METHOD("xform_vec_mult_node_set_no_translation","shader_type","id","disable"),&ShaderGraph::xform_vec_mult_node_set_no_translation);
- ClassDB::bind_method(D_METHOD("xform_vec_mult_node_get_no_translation","shader_type","id"),&ShaderGraph::xform_vec_mult_node_get_no_translation);
-
- ClassDB::bind_method(D_METHOD("scalar_func_node_set_function","shader_type","id","func"),&ShaderGraph::scalar_func_node_set_function);
- ClassDB::bind_method(D_METHOD("scalar_func_node_get_function","shader_type","id"),&ShaderGraph::scalar_func_node_get_function);
-
- ClassDB::bind_method(D_METHOD("vec_func_node_set_function","shader_type","id","func"),&ShaderGraph::vec_func_node_set_function);
- ClassDB::bind_method(D_METHOD("vec_func_node_get_function","shader_type","id"),&ShaderGraph::vec_func_node_get_function);
-
- ClassDB::bind_method(D_METHOD("input_node_set_name","shader_type","id","name"),&ShaderGraph::input_node_set_name);
- ClassDB::bind_method(D_METHOD("input_node_get_name","shader_type","id"),&ShaderGraph::input_node_get_name);
-
- ClassDB::bind_method(D_METHOD("scalar_input_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_input_node_set_value);
- ClassDB::bind_method(D_METHOD("scalar_input_node_get_value","shader_type","id"),&ShaderGraph::scalar_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("vec_input_node_set_value","shader_type","id","value"),&ShaderGraph::vec_input_node_set_value);
- ClassDB::bind_method(D_METHOD("vec_input_node_get_value","shader_type","id"),&ShaderGraph::vec_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("rgb_input_node_set_value","shader_type","id","value"),&ShaderGraph::rgb_input_node_set_value);
- ClassDB::bind_method(D_METHOD("rgb_input_node_get_value","shader_type","id"),&ShaderGraph::rgb_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("xform_input_node_set_value","shader_type","id","value"),&ShaderGraph::xform_input_node_set_value);
- ClassDB::bind_method(D_METHOD("xform_input_node_get_value","shader_type","id"),&ShaderGraph::xform_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("texture_input_node_set_value","shader_type","id","value"),&ShaderGraph::texture_input_node_set_value);
- ClassDB::bind_method(D_METHOD("texture_input_node_get_value","shader_type","id"),&ShaderGraph::texture_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("cubemap_input_node_set_value","shader_type","id","value"),&ShaderGraph::cubemap_input_node_set_value);
- ClassDB::bind_method(D_METHOD("cubemap_input_node_get_value","shader_type","id"),&ShaderGraph::cubemap_input_node_get_value);
-
- ClassDB::bind_method(D_METHOD("comment_node_set_text","shader_type","id","text"),&ShaderGraph::comment_node_set_text);
- ClassDB::bind_method(D_METHOD("comment_node_get_text","shader_type","id"),&ShaderGraph::comment_node_get_text);
-
- ClassDB::bind_method(D_METHOD("color_ramp_node_set_ramp","shader_type","id","colors","offsets"),&ShaderGraph::color_ramp_node_set_ramp);
- ClassDB::bind_method(D_METHOD("color_ramp_node_get_colors","shader_type","id"),&ShaderGraph::color_ramp_node_get_colors);
- ClassDB::bind_method(D_METHOD("color_ramp_node_get_offsets","shader_type","id"),&ShaderGraph::color_ramp_node_get_offsets);
-
- ClassDB::bind_method(D_METHOD("curve_map_node_set_points","shader_type","id","points"),&ShaderGraph::curve_map_node_set_points);
- ClassDB::bind_method(D_METHOD("curve_map_node_get_points","shader_type","id"),&ShaderGraph::curve_map_node_get_points);
-
- ClassDB::bind_method(D_METHOD("connect_node","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::connect_node);
- ClassDB::bind_method(D_METHOD("is_node_connected","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::is_node_connected);
- ClassDB::bind_method(D_METHOD("disconnect_node","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::disconnect_node);
- ClassDB::bind_method(D_METHOD("get_node_connections","shader_type"),&ShaderGraph::_get_connections);
-
- ClassDB::bind_method(D_METHOD("clear","shader_type"),&ShaderGraph::clear);
-
- ClassDB::bind_method(D_METHOD("node_set_state","shader_type","id","state"),&ShaderGraph::node_set_state);
- ClassDB::bind_method(D_METHOD("node_get_state","shader_type","id"),&ShaderGraph::node_get_state);
-
- ClassDB::bind_method(D_METHOD("_set_data"),&ShaderGraph::_set_data);
- ClassDB::bind_method(D_METHOD("_get_data"),&ShaderGraph::_get_data);
-
- ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data","_get_data");
-
- //void get_connections(ShaderType p_which,List<Connection> *p_connections) const;
-
-
- BIND_ENUM_CONSTANT( NODE_INPUT ); // all inputs (shader type dependent)
- BIND_ENUM_CONSTANT( NODE_SCALAR_CONST ); //scalar constant
- BIND_ENUM_CONSTANT( NODE_VEC_CONST ); //vec3 constant
- BIND_ENUM_CONSTANT( NODE_RGB_CONST ); //rgb constant (shows a color picker instead)
- BIND_ENUM_CONSTANT( NODE_XFORM_CONST ); // 4x4 matrix constant
- BIND_ENUM_CONSTANT( NODE_TIME ); // time in seconds
- BIND_ENUM_CONSTANT( NODE_SCREEN_TEX ); // screen texture sampler (takes UV) (only usable in fragment shader)
- BIND_ENUM_CONSTANT( NODE_SCALAR_OP ); // scalar vs scalar op (mul ); add ); div ); etc)
- BIND_ENUM_CONSTANT( NODE_VEC_OP ); // vec3 vs vec3 op (mul );ad );div );crossprod );etc)
- BIND_ENUM_CONSTANT( NODE_VEC_SCALAR_OP ); // vec3 vs scalar op (mul ); add ); div ); etc)
- BIND_ENUM_CONSTANT( NODE_RGB_OP ); // vec3 vs vec3 rgb op (with scalar amount) ); like brighten ); darken ); burn ); dodge ); multiply ); etc.
- BIND_ENUM_CONSTANT( NODE_XFORM_MULT ); // mat4 x mat4
- BIND_ENUM_CONSTANT( NODE_XFORM_VEC_MULT ); // mat4 x vec3 mult (with no-translation option)
- BIND_ENUM_CONSTANT( NODE_XFORM_VEC_INV_MULT ); // mat4 x vec3 inverse mult (with no-translation option)
- BIND_ENUM_CONSTANT( NODE_SCALAR_FUNC ); // scalar function (sin ); cos ); etc)
- BIND_ENUM_CONSTANT( NODE_VEC_FUNC ); // vector function (normalize ); negate ); reciprocal ); rgb2hsv ); hsv2rgb ); etc ); etc)
- BIND_ENUM_CONSTANT( NODE_VEC_LEN ); // vec3 length
- BIND_ENUM_CONSTANT( NODE_DOT_PROD ); // vec3 . vec3 (dot product -> scalar output)
- BIND_ENUM_CONSTANT( NODE_VEC_TO_SCALAR ); // 1 vec3 input ); 3 scalar outputs
- BIND_ENUM_CONSTANT( NODE_SCALAR_TO_VEC ); // 3 scalar input ); 1 vec3 output
- BIND_ENUM_CONSTANT( NODE_VEC_TO_XFORM ); // 3 vec input ); 1 xform output
- BIND_ENUM_CONSTANT( NODE_XFORM_TO_VEC ); // 3 vec input ); 1 xform output
- BIND_ENUM_CONSTANT( NODE_SCALAR_INTERP ); // scalar interpolation (with optional curve)
- BIND_ENUM_CONSTANT( NODE_VEC_INTERP ); // vec3 interpolation (with optional curve)
- BIND_ENUM_CONSTANT( NODE_COLOR_RAMP );
- BIND_ENUM_CONSTANT( NODE_CURVE_MAP );
- BIND_ENUM_CONSTANT( NODE_SCALAR_INPUT ); // scalar uniform (assignable in material)
- BIND_ENUM_CONSTANT( NODE_VEC_INPUT ); // vec3 uniform (assignable in material)
- BIND_ENUM_CONSTANT( NODE_RGB_INPUT ); // color uniform (assignable in material)
- BIND_ENUM_CONSTANT( NODE_XFORM_INPUT ); // mat4 uniform (assignable in material)
- BIND_ENUM_CONSTANT( NODE_TEXTURE_INPUT ); // texture input (assignable in material)
- BIND_ENUM_CONSTANT( NODE_CUBEMAP_INPUT ); // cubemap input (assignable in material)
- BIND_ENUM_CONSTANT( NODE_DEFAULT_TEXTURE );
- BIND_ENUM_CONSTANT( NODE_OUTPUT ); // output (shader type dependent)
- BIND_ENUM_CONSTANT( NODE_COMMENT ); // comment
- BIND_ENUM_CONSTANT( NODE_TYPE_MAX );
-
- BIND_ENUM_CONSTANT( SLOT_TYPE_SCALAR );
- BIND_ENUM_CONSTANT( SLOT_TYPE_VEC );
- BIND_ENUM_CONSTANT( SLOT_TYPE_XFORM );
- BIND_ENUM_CONSTANT( SLOT_TYPE_TEXTURE );
- BIND_ENUM_CONSTANT( SLOT_MAX );
-
- BIND_ENUM_CONSTANT( SHADER_TYPE_VERTEX );
- BIND_ENUM_CONSTANT( SHADER_TYPE_FRAGMENT );
- BIND_ENUM_CONSTANT( SHADER_TYPE_LIGHT );
- BIND_ENUM_CONSTANT( SHADER_TYPE_MAX );
-
-
- BIND_ENUM_CONSTANT( SLOT_IN );
- BIND_ENUM_CONSTANT( SLOT_OUT );
-
- BIND_ENUM_CONSTANT( GRAPH_OK );
- BIND_ENUM_CONSTANT( GRAPH_ERROR_CYCLIC );
- BIND_ENUM_CONSTANT( GRAPH_ERROR_MISSING_CONNECTIONS );
-
- BIND_ENUM_CONSTANT( SCALAR_OP_ADD );
- BIND_ENUM_CONSTANT( SCALAR_OP_SUB );
- BIND_ENUM_CONSTANT( SCALAR_OP_MUL );
- BIND_ENUM_CONSTANT( SCALAR_OP_DIV );
- BIND_ENUM_CONSTANT( SCALAR_OP_MOD );
- BIND_ENUM_CONSTANT( SCALAR_OP_POW );
- BIND_ENUM_CONSTANT( SCALAR_OP_MAX );
- BIND_ENUM_CONSTANT( SCALAR_OP_MIN );
- BIND_ENUM_CONSTANT( SCALAR_OP_ATAN2 );
- BIND_ENUM_CONSTANT( SCALAR_MAX_OP );
-
- BIND_ENUM_CONSTANT( VEC_OP_ADD );
- BIND_ENUM_CONSTANT( VEC_OP_SUB );
- BIND_ENUM_CONSTANT( VEC_OP_MUL );
- BIND_ENUM_CONSTANT( VEC_OP_DIV );
- BIND_ENUM_CONSTANT( VEC_OP_MOD );
- BIND_ENUM_CONSTANT( VEC_OP_POW );
- BIND_ENUM_CONSTANT( VEC_OP_MAX );
- BIND_ENUM_CONSTANT( VEC_OP_MIN );
- BIND_ENUM_CONSTANT( VEC_OP_CROSS );
- BIND_ENUM_CONSTANT( VEC_MAX_OP );
-
- BIND_ENUM_CONSTANT( VEC_SCALAR_OP_MUL );
- BIND_ENUM_CONSTANT( VEC_SCALAR_OP_DIV );
- BIND_ENUM_CONSTANT( VEC_SCALAR_OP_POW );
- BIND_ENUM_CONSTANT( VEC_SCALAR_MAX_OP );
-
- BIND_ENUM_CONSTANT( RGB_OP_SCREEN );
- BIND_ENUM_CONSTANT( RGB_OP_DIFFERENCE );
- BIND_ENUM_CONSTANT( RGB_OP_DARKEN );
- BIND_ENUM_CONSTANT( RGB_OP_LIGHTEN );
- BIND_ENUM_CONSTANT( RGB_OP_OVERLAY );
- BIND_ENUM_CONSTANT( RGB_OP_DODGE );
- BIND_ENUM_CONSTANT( RGB_OP_BURN );
- BIND_ENUM_CONSTANT( RGB_OP_SOFT_LIGHT );
- BIND_ENUM_CONSTANT( RGB_OP_HARD_LIGHT );
- BIND_ENUM_CONSTANT( RGB_MAX_OP );
-
- BIND_ENUM_CONSTANT( SCALAR_FUNC_SIN );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_COS );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_TAN );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_ASIN );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_ACOS );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_ATAN );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_SINH );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_COSH );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_TANH );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_LOG );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_EXP );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_SQRT );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_ABS );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_SIGN );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_FLOOR );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_ROUND );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_CEIL );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_FRAC );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_SATURATE );
- BIND_ENUM_CONSTANT( SCALAR_FUNC_NEGATE );
- BIND_ENUM_CONSTANT( SCALAR_MAX_FUNC );
-
- BIND_ENUM_CONSTANT( VEC_FUNC_NORMALIZE );
- BIND_ENUM_CONSTANT( VEC_FUNC_SATURATE );
- BIND_ENUM_CONSTANT( VEC_FUNC_NEGATE );
- BIND_ENUM_CONSTANT( VEC_FUNC_RECIPROCAL );
- BIND_ENUM_CONSTANT( VEC_FUNC_RGB2HSV );
- BIND_ENUM_CONSTANT( VEC_FUNC_HSV2RGB );
- BIND_ENUM_CONSTANT( VEC_MAX_FUNC );
-
- ADD_SIGNAL(MethodInfo("updated"));
-}
-
-
-String ShaderGraph::_find_unique_name(const String& p_base) {
-
-
-
- int idx=1;
- while(true) {
- String tocmp=p_base;
- if (idx>1) {
- tocmp+="_"+itos(idx);
- }
- bool valid=true;
- for(int i=0;i<3;i++) {
- if (!valid)
- break;
- for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
- if (E->get().type!=NODE_SCALAR_INPUT && E->get().type!=NODE_VEC_INPUT && E->get().type==NODE_RGB_INPUT && E->get().type==NODE_XFORM_INPUT && E->get().type==NODE_TEXTURE_INPUT && E->get().type==NODE_CUBEMAP_INPUT)
- continue;
- String name = E->get().param1;
- if (name==tocmp) {
- valid=false;
- break;
- }
-
- }
- }
-
- if (!valid) {
- idx++;
- continue;
- }
- return tocmp;
- }
- return String();
-}
-
-void ShaderGraph::node_add(ShaderType p_type, NodeType p_node_type,int p_id) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(p_id==0);
- ERR_FAIL_COND(p_node_type==NODE_OUTPUT); //can't create output
- ERR_FAIL_COND( shader[p_type].node_map.has(p_id ) );
- ERR_FAIL_INDEX( p_node_type, NODE_TYPE_MAX );
- Node node;
-
- if (p_node_type==NODE_INPUT) {
- //see if it already exists
- for(Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
- if (E->get().type==NODE_INPUT) {
- ERR_EXPLAIN("Only one input node can be added to the graph.");
- ERR_FAIL_COND(E->get().type==NODE_INPUT);
- }
- }
- }
- node.type=p_node_type;
- node.id=p_id;
-
- switch(p_node_type) {
- case NODE_INPUT: {} break; // all inputs (shader type dependent)
- case NODE_SCALAR_CONST: { node.param1=0;} break; //scalar constant
- case NODE_VEC_CONST: {node.param1=Vector3();} break; //vec3 constant
- case NODE_RGB_CONST: {node.param1=Color();} break; //rgb constant (shows a color picker instead)
- case NODE_XFORM_CONST: {node.param1=Transform();} break; // 4x4 matrix constant
- case NODE_TIME: {} break; // time in seconds
- case NODE_SCREEN_TEX: {Array arr; arr.push_back(0); arr.push_back(0); node.param2=arr;} break; // screen texture sampler (takes UV) (only usable in fragment shader)
- case NODE_SCALAR_OP: {node.param1=SCALAR_OP_ADD;} break; // scalar vs scalar op (mul: {} break; add: {} break; div: {} break; etc)
- case NODE_VEC_OP: {node.param1=VEC_OP_ADD;} break; // vec3 vs vec3 op (mul: {} break;ad: {} break;div: {} break;crossprod: {} break;etc)
- case NODE_VEC_SCALAR_OP: {node.param1=VEC_SCALAR_OP_MUL;} break; // vec3 vs scalar op (mul: {} break; add: {} break; div: {} break; etc)
- case NODE_RGB_OP: {node.param1=RGB_OP_SCREEN;} break; // vec3 vs vec3 rgb op (with scalar amount): {} break; like brighten: {} break; darken: {} break; burn: {} break; dodge: {} break; multiply: {} break; etc.
- case NODE_XFORM_MULT: {} break; // mat4 x mat4
- case NODE_XFORM_VEC_MULT: {} break; // mat4 x vec3 mult (with no-translation option)
- case NODE_XFORM_VEC_INV_MULT: {} break; // mat4 x vec3 inverse mult (with no-translation option)
- case NODE_SCALAR_FUNC: {node.param1=SCALAR_FUNC_SIN;} break; // scalar function (sin: {} break; cos: {} break; etc)
- case NODE_VEC_FUNC: {node.param1=VEC_FUNC_NORMALIZE;} break; // vector function (normalize: {} break; negate: {} break; reciprocal: {} break; rgb2hsv: {} break; hsv2rgb: {} break; etc: {} break; etc)
- case NODE_VEC_LEN: {} break; // vec3 length
- case NODE_DOT_PROD: {} break; // vec3 . vec3 (dot product -> scalar output)
- case NODE_VEC_TO_SCALAR: {} break; // 1 vec3 input: {} break; 3 scalar outputs
- case NODE_SCALAR_TO_VEC: {} break; // 3 scalar input: {} break; 1 vec3 output
- case NODE_VEC_TO_XFORM: {} break; // 3 scalar input: {} break; 1 vec3 output
- case NODE_XFORM_TO_VEC: {} break; // 3 scalar input: {} break; 1 vec3 output
- case NODE_SCALAR_INTERP: {} break; // scalar interpolation (with optional curve)
- case NODE_VEC_INTERP: {} break; // vec3 interpolation (with optional curve)
- case NODE_COLOR_RAMP: { node.param1=PoolVector<Color>(); node.param2=PoolVector<real_t>();} break; // vec3 interpolation (with optional curve)
- case NODE_CURVE_MAP: { node.param1=PoolVector<Vector2>();} break; // vec3 interpolation (with optional curve)
- case NODE_SCALAR_INPUT: {node.param1=_find_unique_name("Scalar"); node.param2=0;} break; // scalar uniform (assignable in material)
- case NODE_VEC_INPUT: {node.param1=_find_unique_name("Vec3");node.param2=Vector3();} break; // vec3 uniform (assignable in material)
- case NODE_RGB_INPUT: {node.param1=_find_unique_name("Color");node.param2=Color();} break; // color uniform (assignable in material)
- case NODE_XFORM_INPUT: {node.param1=_find_unique_name("XForm"); node.param2=Transform();} break; // mat4 uniform (assignable in material)
- case NODE_TEXTURE_INPUT: {node.param1=_find_unique_name("Tex"); } break; // texture input (assignable in material)
- case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material)
- case NODE_DEFAULT_TEXTURE: {}; break;
- case NODE_OUTPUT: {} break; // output (shader type dependent)
- case NODE_COMMENT: {} break; // comment
- case NODE_TYPE_MAX: {};
- }
-
- shader[p_type].node_map[p_id]=node;
- _request_update();
-}
-
-void ShaderGraph::node_set_position(ShaderType p_type,int p_id, const Vector2& p_pos) {
- ERR_FAIL_INDEX(p_type,3);
-
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- shader[p_type].node_map[p_id].pos=p_pos;
- _request_update();
-
-}
-Vector2 ShaderGraph::node_get_position(ShaderType p_type,int p_id) const {
- ERR_FAIL_INDEX_V(p_type,3,Vector2());
-
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector2());
- return shader[p_type].node_map[p_id].pos;
-}
-
-
-void ShaderGraph::node_remove(ShaderType p_type,int p_id) {
-
- ERR_FAIL_COND(p_id==0);
- ERR_FAIL_INDEX(p_type,3);
-
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
-
- //erase connections associated with node
- for(Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
- if (E->key()==p_id)
- continue; //no self
-
- for (Map<int,SourceSlot>::Element *F=E->get().connections.front();F;) {
- Map<int,SourceSlot>::Element *N=F->next();
-
- if (F->get().id==p_id) {
- E->get().connections.erase(F);
- }
-
- F=N;
- }
- }
-
- shader[p_type].node_map.erase(p_id);
-
- _request_update();
-
-}
-
-
-
-void ShaderGraph::get_node_list(ShaderType p_type,List<int> *p_node_list) const {
-
- ERR_FAIL_INDEX(p_type,3);
-
- Map<int,Node>::Element *E = shader[p_type].node_map.front();
-
- while(E) {
-
- p_node_list->push_back(E->key());
- E=E->next();
- }
-}
-
-
-ShaderGraph::NodeType ShaderGraph::node_get_type(ShaderType p_type,int p_id) const {
-
- ERR_FAIL_INDEX_V(p_type,3,NODE_TYPE_MAX);
-
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),NODE_TYPE_MAX);
- return shader[p_type].node_map[p_id].type;
-}
-
-
-Error ShaderGraph::connect_node(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
- ERR_FAIL_INDEX_V(p_type,3,ERR_INVALID_PARAMETER);
-
- ERR_FAIL_COND_V(p_src_id==p_dst_id, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_src_id), ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_dst_id), ERR_INVALID_PARAMETER);
- NodeType type_src=shader[p_type].node_map[p_src_id].type;
- NodeType type_dst=shader[p_type].node_map[p_dst_id].type;
- ERR_FAIL_INDEX_V( p_src_slot, get_node_output_slot_count(get_mode(),p_type,type_src), ERR_INVALID_PARAMETER );
- ERR_FAIL_INDEX_V( p_dst_slot, get_node_input_slot_count(get_mode(),p_type,type_dst), ERR_INVALID_PARAMETER );
- ERR_FAIL_COND_V(get_node_output_slot_type(get_mode(),p_type,type_src,p_src_slot) != get_node_input_slot_type(get_mode(),p_type,type_dst,p_dst_slot), ERR_INVALID_PARAMETER );
-
-
- SourceSlot ts;
- ts.id=p_src_id;
- ts.slot=p_src_slot;
- shader[p_type].node_map[p_dst_id].connections[p_dst_slot]=ts;
- _request_update();
-
- return OK;
-}
-
-bool ShaderGraph::is_node_connected(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const {
-
- ERR_FAIL_INDEX_V(p_type,3,false);
-
- SourceSlot ts;
- ts.id=p_src_id;
- ts.slot=p_src_slot;
- return shader[p_type].node_map.has(p_dst_id) && shader[p_type].node_map[p_dst_id].connections.has(p_dst_slot) &&
- shader[p_type].node_map[p_dst_id].connections[p_dst_slot]==ts;
-}
-
-void ShaderGraph::disconnect_node(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
- ERR_FAIL_INDEX(p_type,3);
-
- SourceSlot ts;
- ts.id=p_src_id;
- ts.slot=p_src_slot;
- if (shader[p_type].node_map.has(p_dst_id) && shader[p_type].node_map[p_dst_id].connections.has(p_dst_slot) &&
- shader[p_type].node_map[p_dst_id].connections[p_dst_slot]==ts) {
- shader[p_type].node_map[p_dst_id].connections.erase(p_dst_slot);
-
- }
- _request_update();
-
-}
-
-void ShaderGraph::get_node_connections(ShaderType p_type,List<Connection> *p_connections) const {
-
- ERR_FAIL_INDEX(p_type,3);
-
- for(const Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
- for (const Map<int,SourceSlot>::Element *F=E->get().connections.front();F;F=F->next()) {
-
- Connection c;
- c.dst_id=E->key();
- c.dst_slot=F->key();
- c.src_id=F->get().id;
- c.src_slot=F->get().slot;
- p_connections->push_back(c);
- }
- }
-}
-
-bool ShaderGraph::is_slot_connected(ShaderGraph::ShaderType p_type, int p_dst_id, int slot_id)
-{
- for(const Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
- for (const Map<int,SourceSlot>::Element *F=E->get().connections.front();F;F=F->next()) {
-
- if (p_dst_id == E->key() && slot_id==F->key())
- return true;
- }
- }
- return false;
-}
-
-
-void ShaderGraph::clear(ShaderType p_type) {
-
- ERR_FAIL_INDEX(p_type,3);
- shader[p_type].node_map.clear();
- Node out;
- out.pos=Vector2(300,300);
- out.type=NODE_OUTPUT;
- shader[p_type].node_map.insert(0,out);
-
- _request_update();
-
-}
-
-
-void ShaderGraph::scalar_const_node_set_value(ShaderType p_type,int p_id,float p_value) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_SCALAR_CONST);
- n.param1=p_value;
- _request_update();
-
-}
-
-float ShaderGraph::scalar_const_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,0);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_SCALAR_CONST,0);
- return n.param1;
-}
-
-void ShaderGraph::vec_const_node_set_value(ShaderType p_type,int p_id,const Vector3& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_VEC_CONST);
- n.param1=p_value;
- _request_update();
-
-
-}
-Vector3 ShaderGraph::vec_const_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Vector3());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector3());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_VEC_CONST,Vector3());
- return n.param1;
-
-}
-
-void ShaderGraph::rgb_const_node_set_value(ShaderType p_type,int p_id,const Color& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_RGB_CONST);
- n.param1=p_value;
- _request_update();
-
-}
-Color ShaderGraph::rgb_const_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Color());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Color());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_RGB_CONST,Color());
- return n.param1;
-
-}
-
-void ShaderGraph::xform_const_node_set_value(ShaderType p_type,int p_id,const Transform& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_XFORM_CONST);
- n.param1=p_value;
- _request_update();
-
-}
-Transform ShaderGraph::xform_const_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Transform());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Transform());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_XFORM_CONST,Transform());
- return n.param1;
-
-}
-
-void ShaderGraph::texture_node_set_filter_size(ShaderType p_type,int p_id,int p_size){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX);
- Array arr = n.param2;
- arr[0]=p_size;
- n.param2=arr;
- _request_update();
-
-}
-int ShaderGraph::texture_node_get_filter_size(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,0);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX,0);
- Array arr = n.param2;
- return arr[0];
-
-}
-
-void ShaderGraph::texture_node_set_filter_strength(ShaderType p_type,float p_id,float p_strength){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX);
- Array arr = n.param2;
- arr[1]=p_strength;
- n.param2=arr;
- _request_update();
-
-}
-float ShaderGraph::texture_node_get_filter_strength(ShaderType p_type,float p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,0);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX,0);
- Array arr = n.param2;
- return arr[1];
-}
-
-void ShaderGraph::duplicate_nodes(ShaderType p_which, List<int> &p_nodes)
-{
- //Create new node IDs
- Map<int,int> duplicates = Map<int,int>();
- int i=1;
- for(List<int>::Element *E=p_nodes.front();E; E=E->next()) {
- while (shader[p_which].node_map.has(i))
- i++;
- duplicates.insert(E->get(), i);
- i++;
- }
-
- for(List<int>::Element *E = p_nodes.front();E; E=E->next()) {
-
- const Node &n=shader[p_which].node_map[E->get()];
- Node nn=n;
- nn.id=duplicates.find(n.id)->get();
- nn.pos += Vector2(0,100);
- for (Map<int,SourceSlot>::Element *C=nn.connections.front();C;C=C->next()) {
- SourceSlot &c=C->get();
- if (p_nodes.find(c.id))
- c.id=duplicates.find(c.id)->get();
- }
- shader[p_which].node_map[nn.id]=nn;
- }
- _request_update();
-}
-
-List<int> ShaderGraph::generate_ids(ShaderType p_type, int count)
-{
- List<int> ids = List<int>();
- int i=1;
- while (ids.size() < count) {
- while (shader[p_type].node_map.has(i))
- i++;
- ids.push_back(i);
- i++;
- }
- return ids;
-}
-
-
-void ShaderGraph::scalar_op_node_set_op(ShaderType p_type,float p_id,ScalarOp p_op){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_SCALAR_OP);
- n.param1=p_op;
- _request_update();
-
-}
-ShaderGraph::ScalarOp ShaderGraph::scalar_op_node_get_op(ShaderType p_type,float p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,SCALAR_MAX_OP);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),SCALAR_MAX_OP);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_SCALAR_OP,SCALAR_MAX_OP);
- int op = n.param1;
- return ScalarOp(op);
-
-}
-
-
-void ShaderGraph::vec_op_node_set_op(ShaderType p_type,float p_id,VecOp p_op){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_VEC_OP);
- n.param1=p_op;
- _request_update();
-
-}
-ShaderGraph::VecOp ShaderGraph::vec_op_node_get_op(ShaderType p_type,float p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,VEC_MAX_OP);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_MAX_OP);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_VEC_OP,VEC_MAX_OP);
- int op = n.param1;
- return VecOp(op);
-
-}
-
-
-void ShaderGraph::vec_scalar_op_node_set_op(ShaderType p_type,float p_id,VecScalarOp p_op){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_VEC_SCALAR_OP);
- n.param1=p_op;
- _request_update();
-
-}
-ShaderGraph::VecScalarOp ShaderGraph::vec_scalar_op_node_get_op(ShaderType p_type,float p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,VEC_SCALAR_MAX_OP);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_SCALAR_MAX_OP);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_VEC_SCALAR_OP,VEC_SCALAR_MAX_OP);
- int op = n.param1;
- return VecScalarOp(op);
-
-}
-
-void ShaderGraph::rgb_op_node_set_op(ShaderType p_type,float p_id,RGBOp p_op){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_RGB_OP);
- n.param1=p_op;
-
- _request_update();
-
-}
-ShaderGraph::RGBOp ShaderGraph::rgb_op_node_get_op(ShaderType p_type,float p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,RGB_MAX_OP);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),RGB_MAX_OP);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_RGB_OP,RGB_MAX_OP);
- int op = n.param1;
- return RGBOp(op);
-
-}
-
-
-void ShaderGraph::xform_vec_mult_node_set_no_translation(ShaderType p_type,int p_id,bool p_no_translation){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_XFORM_VEC_MULT && n.type!=NODE_XFORM_VEC_INV_MULT);
- n.param1=p_no_translation;
- _request_update();
-
-}
-bool ShaderGraph::xform_vec_mult_node_get_no_translation(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,false);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),false);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_XFORM_VEC_MULT && n.type!=NODE_XFORM_VEC_INV_MULT,false);
- return n.param1;
-
-}
-
-void ShaderGraph::scalar_func_node_set_function(ShaderType p_type,int p_id,ScalarFunc p_func){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_SCALAR_FUNC);
- int func = p_func;
- ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC);
- n.param1=func;
- _request_update();
-
-}
-ShaderGraph::ScalarFunc ShaderGraph::scalar_func_node_get_function(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,SCALAR_MAX_FUNC);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),SCALAR_MAX_FUNC);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_SCALAR_FUNC,SCALAR_MAX_FUNC);
- int func = n.param1;
- return ScalarFunc(func);
-}
-
-void ShaderGraph::default_set_value(ShaderGraph::ShaderType p_which, int p_id, int p_param, const Variant &p_value)
-{
- ERR_FAIL_INDEX(p_which,3);
- ERR_FAIL_COND(!shader[p_which].node_map.has(p_id));
- Node& n = shader[p_which].node_map[p_id];
- if(p_value.get_type()==Variant::NIL)
- n.defaults.erase(n.defaults.find(p_param));
- else
- n.defaults[p_param]=p_value;
-
- _request_update();
-
-}
-
-Variant ShaderGraph::default_get_value(ShaderGraph::ShaderType p_which, int p_id, int p_param)
-{
- ERR_FAIL_INDEX_V(p_which,3,Variant());
- ERR_FAIL_COND_V(!shader[p_which].node_map.has(p_id),Variant());
- const Node& n = shader[p_which].node_map[p_id];
-
- if (!n.defaults.has(p_param))
- return Variant();
- return n.defaults[p_param];
-}
-
-
-
-void ShaderGraph::vec_func_node_set_function(ShaderType p_type,int p_id,VecFunc p_func){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_VEC_FUNC);
- int func = p_func;
- ERR_FAIL_INDEX(func,VEC_MAX_FUNC);
- n.param1=func;
-
- _request_update();
-
-}
-ShaderGraph::VecFunc ShaderGraph::vec_func_node_get_function(ShaderType p_type, int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,VEC_MAX_FUNC);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_MAX_FUNC);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_VEC_FUNC,VEC_MAX_FUNC);
- int func = n.param1;
- return VecFunc(func);
-}
-
-void ShaderGraph::color_ramp_node_set_ramp(ShaderType p_type,int p_id,const PoolVector<Color>& p_colors, const PoolVector<real_t>& p_offsets){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- ERR_FAIL_COND(p_colors.size()!=p_offsets.size());
- Node& n = shader[p_type].node_map[p_id];
- n.param1=p_colors;
- n.param2=p_offsets;
- _request_update();
-
-}
-
-PoolVector<Color> ShaderGraph::color_ramp_node_get_colors(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,PoolVector<Color>());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),PoolVector<Color>());
- const Node& n = shader[p_type].node_map[p_id];
- return n.param1;
-
-
-}
-
-PoolVector<real_t> ShaderGraph::color_ramp_node_get_offsets(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,PoolVector<real_t>());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),PoolVector<real_t>());
- const Node& n = shader[p_type].node_map[p_id];
- return n.param2;
-
-}
-
-
-void ShaderGraph::curve_map_node_set_points(ShaderType p_type,int p_id,const PoolVector<Vector2>& p_points) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- n.param1=p_points;
- _request_update();
-
-}
-
-PoolVector<Vector2> ShaderGraph::curve_map_node_get_points(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,PoolVector<Vector2>());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),PoolVector<Vector2>());
- const Node& n = shader[p_type].node_map[p_id];
- return n.param1;
-
-}
-
-
-
-void ShaderGraph::input_node_set_name(ShaderType p_type,int p_id,const String& p_name){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- ERR_FAIL_COND(!p_name.is_valid_identifier());
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_SCALAR_INPUT && n.type!=NODE_VEC_INPUT && n.type==NODE_RGB_INPUT && n.type==NODE_XFORM_INPUT && n.type==NODE_TEXTURE_INPUT && n.type==NODE_CUBEMAP_INPUT);
-
- n.param1="";
- n.param1=_find_unique_name(p_name);
- _request_update();
-
-}
-String ShaderGraph::input_node_get_name(ShaderType p_type,int p_id){
-
- ERR_FAIL_INDEX_V(p_type,3,String());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),String());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_SCALAR_INPUT && n.type!=NODE_VEC_INPUT && n.type==NODE_RGB_INPUT && n.type==NODE_XFORM_INPUT && n.type==NODE_TEXTURE_INPUT && n.type==NODE_CUBEMAP_INPUT,String());
- return n.param1;
-}
-
-
-void ShaderGraph::scalar_input_node_set_value(ShaderType p_type,int p_id,float p_value) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_SCALAR_INPUT);
- n.param2=p_value;
- _request_update();
-
-}
-
-float ShaderGraph::scalar_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,0);
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_SCALAR_INPUT,0);
-
- return n.param2;
-}
-
-void ShaderGraph::vec_input_node_set_value(ShaderType p_type,int p_id,const Vector3& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_VEC_INPUT);
-
- n.param2=p_value;
- _request_update();
-
-}
-Vector3 ShaderGraph::vec_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Vector3());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector3());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_VEC_INPUT,Vector3());
- return n.param2;
-}
-
-void ShaderGraph::rgb_input_node_set_value(ShaderType p_type,int p_id,const Color& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_RGB_INPUT);
- n.param2=p_value;
- _request_update();
-
-}
-Color ShaderGraph::rgb_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Color());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Color());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_RGB_INPUT,Color());
- return n.param2;
-}
-
-void ShaderGraph::xform_input_node_set_value(ShaderType p_type,int p_id,const Transform& p_value){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_XFORM_INPUT);
- n.param2=p_value;
- _request_update();
-
-}
-Transform ShaderGraph::xform_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Transform());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Transform());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_XFORM_INPUT,Transform());
- return n.param2;
-}
-
-
-void ShaderGraph::texture_input_node_set_value(ShaderType p_type,int p_id,const Ref<Texture>& p_texture) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT);
- n.param2=p_texture;
- _request_update();
-
-}
-
-Ref<Texture> ShaderGraph::texture_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Ref<Texture>());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Ref<Texture>());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT,Ref<Texture>());
- return n.param2;
-}
-
-void ShaderGraph::cubemap_input_node_set_value(ShaderType p_type,int p_id,const Ref<CubeMap>& p_cubemap){
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_CUBEMAP_INPUT);
- n.param2=p_cubemap;
- _request_update();
-
-}
-
-Ref<CubeMap> ShaderGraph::cubemap_input_node_get_value(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,Ref<CubeMap>());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Ref<CubeMap>());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_CUBEMAP_INPUT,Ref<CubeMap>());
- return n.param2;
-
-}
-
-
-void ShaderGraph::comment_node_set_text(ShaderType p_type,int p_id,const String& p_comment) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND(n.type!=NODE_COMMENT);
- n.param1=p_comment;
-
-}
-
-String ShaderGraph::comment_node_get_text(ShaderType p_type,int p_id) const{
-
- ERR_FAIL_INDEX_V(p_type,3,String());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),String());
- const Node& n = shader[p_type].node_map[p_id];
- ERR_FAIL_COND_V(n.type!=NODE_COMMENT,String());
- return n.param1;
-
-}
-
-void ShaderGraph::_request_update() {
-
- if (_pending_update_shader)
- return;
-
- _pending_update_shader=true;
- call_deferred("_update_shader");
-
-}
-
-Variant ShaderGraph::node_get_state(ShaderType p_type,int p_id) const {
-
- ERR_FAIL_INDEX_V(p_type,3,Variant());
- ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Variant());
- const Node& n = shader[p_type].node_map[p_id];
- Dictionary s;
- s["position"]=n.pos;
- s["param1"]=n.param1;
- s["param2"]=n.param2;
- Array keys;
- for (Map<int,Variant>::Element *E=n.defaults.front();E;E=E->next()) {
- keys.append(E->key());
- s[E->key()]=E->get();
- }
- s["default_keys"]=keys;
- return s;
-
-}
-void ShaderGraph::node_set_state(ShaderType p_type,int p_id,const Variant& p_state) {
-
- ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
- Node& n = shader[p_type].node_map[p_id];
- Dictionary d = p_state;
- ERR_FAIL_COND(!d.has("position"));
- ERR_FAIL_COND(!d.has("param1"));
- ERR_FAIL_COND(!d.has("param2"));
- ERR_FAIL_COND(!d.has("default_keys"));
-
- n.pos=d["position"];
- n.param1=d["param1"];
- n.param2=d["param2"];
- Array keys = d["default_keys"];
- for(int i=0;i<keys.size();i++) {
- n.defaults[keys[i]]=d[keys[i]];
- }
-}
-
-ShaderGraph::ShaderGraph(Mode p_mode) : Shader(p_mode) {
-
- //shader = VisualServer::get_singleton()->shader_create();
- _pending_update_shader=false;
-
- Node input;
- input.id=1;
- input.pos=Vector2(50,40);
- input.type=NODE_INPUT;
-
- Node output;
- output.id=0;
- output.pos=Vector2(350,40);
- output.type=NODE_OUTPUT;
-
- for(int i=0;i<3;i++) {
-
- shader[i].node_map.insert(0,output);
- shader[i].node_map.insert(1,input);
- }
-}
-
-ShaderGraph::~ShaderGraph() {
-
- //VisualServer::get_singleton()->free(shader);
-}
-
-
-const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
- //material vertex in
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","SRC_VERTEX","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","SRC_NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","SRC_TANGENT","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"BinormalF","SRC_BINORMALF","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","SRC_COLOR","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","SRC_ALPHA","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","SRC_UV2","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ModelviewMatrix","MODELVIEW_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InstanceID","INSTANCE_ID","",SLOT_TYPE_SCALAR,SLOT_IN},
-
- //material vertex out
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","UV2",".xy",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"SpecExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT},
- //pixel vertex in
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Position","POSITION.xyz","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","IN_NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV2","vec3(UV2,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","vec3(SCREEN_UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- //pixel vertex out
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Discard","DISCARD",">0.5",SLOT_TYPE_SCALAR,SLOT_OUT},
- //light in
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDir","LIGHT_DIR","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDiffuse","LIGHT_DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightSpecular","LIGHT_SPECULAR","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"EyeVec","EYE_VEC","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Diffuse","DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"SpecExp","SPECULAR_EXP","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_IN},
- //light out
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Shadow", "SHADOW", "",SLOT_TYPE_VEC, SLOT_OUT },
- //canvas item vertex in
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","vec3(SRC_VERTEX,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ExtraMatrix","EXTRA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
- //canvas item vertex out
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","VERTEX",".xy",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT},
- //canvas item fragment in
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UVScreen","vec3(SCREEN_UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Position","POSITION","",SLOT_TYPE_VEC,SLOT_IN},
- //canvas item fragment out
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH","",SLOT_TYPE_SCALAR,SLOT_OUT},
- //canvas item light in
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightHeight","LIGHT_HEIGHT","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowColor","LIGHT_SHADOW.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowAlpha","LIGHT_SHADOW.a","",SLOT_TYPE_SCALAR,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Position","POSITION","",SLOT_TYPE_VEC,SLOT_IN},
- //canvas item light out
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowColor","SHADOW.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
- {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"ShadowAlpha","SHADOW.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
- //end
- {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT},
-
-
-
-};
-
-void ShaderGraph::get_input_output_node_slot_info(Mode p_mode, ShaderType p_type, List<SlotInfo> *r_slots) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- while(iop->name) {
- if (p_mode==iop->shader_mode && p_type==iop->shader_type) {
-
- SlotInfo si;
- si.dir=iop->dir;
- si.name=iop->name;
- si.type=iop->slot_type;
- r_slots->push_back(si);
- }
- iop++;
- }
-}
-
-
-const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= {
-
- {NODE_SCALAR_CONST,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, //scalar constant
- {NODE_VEC_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, //vec3 constant
- {NODE_RGB_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, //rgb constant (shows a color picker instead)
- {NODE_XFORM_CONST,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // 4x4 matrix constant
- {NODE_TIME,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // time in seconds
- {NODE_SCREEN_TEX,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // screen texture sampler (takes UV) (only usable in fragment shader)
- {NODE_SCALAR_OP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_VEC_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_VEC_SCALAR_OP,{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_RGB_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_XFORM_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 x mat4
- {NODE_XFORM_VEC_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 mult (with no-translation option)
- {NODE_XFORM_VEC_INV_MULT,{SLOT_TYPE_VEC,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 inverse mult (with no-translation option)
- {NODE_SCALAR_FUNC,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar function (sin,{SLOT_MAX},{SLOT_MAX}}, cos,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_VEC_FUNC,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vector function (normalize,{SLOT_MAX},{SLOT_MAX}}, negate,{SLOT_MAX},{SLOT_MAX}}, reciprocal,{SLOT_MAX},{SLOT_MAX}}, rgb2hsv,{SLOT_MAX},{SLOT_MAX}}, hsv2rgb,{SLOT_MAX},{SLOT_MAX}}, etc,{SLOT_MAX},{SLOT_MAX}}, etc)
- {NODE_VEC_LEN,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 length
- {NODE_DOT_PROD,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 . vec3 (dot product -> scalar output)
- {NODE_VEC_TO_SCALAR,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR}}, // 1 vec3 input,{SLOT_MAX},{SLOT_MAX}}, 3 scalar outputs
- {NODE_SCALAR_TO_VEC,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // 3 scalar input,{SLOT_MAX},{SLOT_MAX}}, 1 vec3 output
- {NODE_SCALAR_INTERP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar interpolation (with optional curve)
- {NODE_VEC_INTERP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve)
- {NODE_COLOR_RAMP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve)
- {NODE_CURVE_MAP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve)
- {NODE_SCALAR_INPUT,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar uniform (assignable in material)
- {NODE_VEC_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 uniform (assignable in material)
- {NODE_RGB_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // color uniform (assignable in material)
- {NODE_XFORM_INPUT,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 uniform (assignable in material)
- {NODE_TEXTURE_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // texture input (assignable in material)
- {NODE_CUBEMAP_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material)
- {NODE_DEFAULT_TEXTURE,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material)
- {NODE_COMMENT,{SLOT_MAX},{SLOT_MAX}}, // comment
- {NODE_TYPE_MAX,{SLOT_MAX},{SLOT_MAX}}
-};
-
-int ShaderGraph::get_node_input_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type) {
-
- if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- int pc=0;
- while(iop->name) {
- if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
-
- if (iop->dir==SLOT_OUT)
- pc++;
- }
- iop++;
- }
- return pc;
- } else if (p_type==NODE_VEC_TO_XFORM){
- return 4;
- } else if (p_type==NODE_XFORM_TO_VEC){
- return 1;
- } else {
-
- const NodeSlotInfo*nsi=&node_slot_info[0];
- while(nsi->type!=NODE_TYPE_MAX) {
-
- if (nsi->type==p_type) {
- int pc=0;
- for(int i=0;i<NodeSlotInfo::MAX_INS;i++) {
- if (nsi->ins[i]==SLOT_MAX)
- break;
- pc++;
- }
- return pc;
- }
-
- nsi++;
- }
-
- return 0;
-
- }
-}
-
-int ShaderGraph::get_node_output_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type){
-
- if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- int pc=0;
- while(iop->name) {
- if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
-
- if (iop->dir==SLOT_IN)
- pc++;
- }
- iop++;
- }
- return pc;
- } else if (p_type==NODE_VEC_TO_XFORM){
- return 1;
- } else if (p_type==NODE_XFORM_TO_VEC){
- return 4;
- } else {
-
- const NodeSlotInfo*nsi=&node_slot_info[0];
- while(nsi->type!=NODE_TYPE_MAX) {
-
- if (nsi->type==p_type) {
- int pc=0;
- for(int i=0;i<NodeSlotInfo::MAX_OUTS;i++) {
- if (nsi->outs[i]==SLOT_MAX)
- break;
- pc++;
- }
- return pc;
- }
-
- nsi++;
- }
-
- return 0;
-
- }
-}
-ShaderGraph::SlotType ShaderGraph::get_node_input_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx){
-
- if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- int pc=0;
- while(iop->name) {
- if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
-
- if (iop->dir==SLOT_OUT) {
- if (pc==p_idx)
- return iop->slot_type;
- pc++;
- }
- }
- iop++;
- }
- ERR_FAIL_V(SLOT_MAX);
- } else if (p_type==NODE_VEC_TO_XFORM){
- return SLOT_TYPE_VEC;
- } else if (p_type==NODE_XFORM_TO_VEC){
- return SLOT_TYPE_XFORM;
- } else {
-
- const NodeSlotInfo*nsi=&node_slot_info[0];
- while(nsi->type!=NODE_TYPE_MAX) {
-
- if (nsi->type==p_type) {
- for(int i=0;i<NodeSlotInfo::MAX_INS;i++) {
-
- if (nsi->ins[i]==SLOT_MAX)
- break;
- if (i==p_idx)
- return nsi->ins[i];
- }
- }
-
- nsi++;
- }
-
- ERR_FAIL_V(SLOT_MAX);
-
- }
-}
-ShaderGraph::SlotType ShaderGraph::get_node_output_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx){
-
- if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- int pc=0;
- while(iop->name) {
- if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
-
- if (iop->dir==SLOT_IN) {
- if (pc==p_idx)
- return iop->slot_type;
- pc++;
- }
- }
- iop++;
- }
- ERR_FAIL_V(SLOT_MAX);
- } else if (p_type==NODE_VEC_TO_XFORM){
- return SLOT_TYPE_XFORM;
- } else if (p_type==NODE_XFORM_TO_VEC){
- return SLOT_TYPE_VEC;
- } else {
-
- const NodeSlotInfo*nsi=&node_slot_info[0];
- while(nsi->type!=NODE_TYPE_MAX) {
-
- if (nsi->type==p_type) {
- for(int i=0;i<NodeSlotInfo::MAX_OUTS;i++) {
- if (nsi->outs[i]==SLOT_MAX)
- break;
- if (i==p_idx)
- return nsi->outs[i];
- }
- }
-
- nsi++;
- }
-
- ERR_FAIL_V(SLOT_MAX);
- }
-}
-
-
-
-
-
-void ShaderGraph::_update_shader() {
-
-
- String code[3];
-
- List<StringName> names;
- get_default_texture_param_list(&names);
-
- for (List<StringName>::Element *E=names.front();E;E=E->next()) {
-
- set_default_texture_param(E->get(),Ref<Texture>());
- }
-
-
- for(int i=0;i<3;i++) {
-
- int idx=0;
- for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
-
- E->get().sort_order=idx++;
- }
- //simple method for graph solving using bubblesort derived algorithm
- int iters=0;
- int iter_max=shader[i].node_map.size()*shader[i].node_map.size();
-
- while(true) {
- if (iters>iter_max)
- break;
-
- int swaps=0;
- for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
-
- for(Map<int,SourceSlot>::Element *F=E->get().connections.front();F;F=F->next()) {
-
- //this is kinda slow, could be sped up
- Map<int,Node>::Element *G = shader[i].node_map.find(F->get().id);
- ERR_FAIL_COND(!G);
- if (G->get().sort_order > E->get().sort_order) {
-
- SWAP(G->get().sort_order,E->get().sort_order);
- swaps++;
- }
- }
- }
-
- iters++;
- if (swaps==0) {
- iters=0;
- break;
- }
- }
-
- if (iters>0) {
-
- shader[i].error=GRAPH_ERROR_CYCLIC;
- continue;
- }
-
- Vector<Node*> order;
- order.resize(shader[i].node_map.size());
-
- for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
-
- order[E->get().sort_order]=&E->get();
- }
-
- //generate code for the ordered graph
- bool failed=false;
-
- if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
- code[i]+="vec3 DIFFUSE_OUT=vec3(0,0,0);\n";
- code[i]+="float ALPHA_OUT=0;\n";
- }
-
-
- Map<String,String> inputs_xlate;
- Map<String,String> input_names_xlate;
- Set<String> inputs_used;
-
- for(int j=0;j<order.size();j++) {
-
- Node *n=order[j];
- if (n->type==NODE_INPUT) {
-
- const InOutParamInfo* iop = &inout_param_info[0];
- int idx=0;
- while(iop->name) {
- if (get_mode()==iop->shader_mode && i==iop->shader_type && SLOT_IN==iop->dir) {
-
- const char *typestr[4]={"float","vec3","mat4","texture"};
-
- String vname=("nd"+itos(n->id)+"sl"+itos(idx));
- inputs_xlate[vname]=String(typestr[iop->slot_type])+" "+vname+"="+iop->variable+";\n";
- input_names_xlate[vname]=iop->variable;
- idx++;
- }
- iop++;
- }
-
- } else if (n->type==NODE_OUTPUT) {
-
-
- bool use_alpha=false;
- const InOutParamInfo* iop = &inout_param_info[0];
- int idx=0;
- while(iop->name) {
- if (get_mode()==iop->shader_mode && i==iop->shader_type && SLOT_OUT==iop->dir) {
-
- if (n->connections.has(idx)) {
- String iname=("nd"+itos(n->connections[idx].id)+"sl"+itos(n->connections[idx].slot));
- if (node_get_type(ShaderType(i),n->connections[idx].id)==NODE_INPUT)
- inputs_used.insert(iname);
- code[i]+=String(iop->variable)+"="+iname+String(iop->postfix)+";\n";
- if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL && String(iop->name)=="DiffuseAlpha")
- use_alpha=true;
- }
- idx++;
- }
- iop++;
- }
-
- if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
-
- if (use_alpha) {
- code[i]+="DIFFUSE_ALPHA=vec4(DIFFUSE_OUT,ALPHA_OUT);\n";
- } else {
- code[i]+="DIFFUSE=DIFFUSE_OUT;\n";
- }
- }
-
- } else {
- Vector<String> inputs;
- int max = get_node_input_slot_count(get_mode(),ShaderType(i),n->type);
- for(int k=0;k<max;k++) {
- String iname;
- if (!n->connections.has(k)) {
- iname="nd"+itos(n->id)+"sl"+itos(k)+"def";
- } else {
- iname="nd"+itos(n->connections[k].id)+"sl"+itos(n->connections[k].slot);
- if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) {
- inputs_used.insert(iname);
- }
-
- }
- inputs.push_back(iname);
- }
-
- if (failed)
- break;
-
- if (n->type==NODE_TEXTURE_INPUT || n->type==NODE_CUBEMAP_INPUT) {
-
- set_default_texture_param(n->param1,n->param2);
-
- }
- _add_node_code(ShaderType(i),n,inputs,code[i]);
- }
-
- }
-
- if (failed)
- continue;
-
-
- for(Set<String>::Element *E=inputs_used.front();E;E=E->next()) {
-
- ERR_CONTINUE( !inputs_xlate.has(E->get()));
- code[i]=inputs_xlate[E->get()]+code[i];
- String name=input_names_xlate[E->get()];
-
- if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_MATERIAL) {
- if (name==("SRC_COLOR"))
- code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i];
- if (name==("SRC_ALPHA"))
- code[i]="float SRC_ALPHA=COLOR.a;\n"+code[i];
- if (name==("SRC_UV"))
- code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i];
- if (name==("SRC_UV2"))
- code[i]="float SRC_UV2=vec3(UV2,0);\n"+code[i];
- } else if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
- if (name==("IN_NORMAL"))
- code[i]="vec3 IN_NORMAL=NORMAL;\n"+code[i];
- } else if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_CANVAS_ITEM) {
- if (name==("SRC_COLOR"))
- code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i];
- if (name==("SRC_UV"))
- code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i];
- }
-
- }
-
-
-
- shader[i].error=GRAPH_OK;
-
- }
-
- bool all_ok=true;
- for(int i=0;i<3;i++) {
- if (shader[i].error!=GRAPH_OK)
- all_ok=false;
- }
-
- /*print_line("VERTEX: \n"+code[0]);
- print_line("FRAGMENT: \n"+code[1]);
- print_line("LIGHT: \n"+code[2]);*/
-
- if (all_ok) {
- set_code(code[0],code[1],code[2]);
- }
- //do shader here
-
- _pending_update_shader=false;
- emit_signal(SceneStringNames::get_singleton()->updated);
-}
-
-void ShaderGraph::_plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d,uint8_t* p_heights,bool *p_useds) {
-
- float geometry[4][4];
- float tmp1[4][4];
- float tmp2[4][4];
- float deltas[4][4];
- double x, dx, dx2, dx3;
- double y, dy, dy2, dy3;
- double d, d2, d3;
- int lastx, lasty;
- int newx, newy;
- int ntimes;
- int i,j;
-
- int xmax=255;
- int ymax=255;
-
- /* construct the geometry matrix from the segment */
- for (i = 0; i < 4; i++) {
- geometry[i][2] = 0;
- geometry[i][3] = 0;
- }
-
- geometry[0][0] = (p_a[0] * xmax);
- geometry[1][0] = (p_b[0] * xmax);
- geometry[2][0] = (p_c[0] * xmax);
- geometry[3][0] = (p_d[0] * xmax);
-
- geometry[0][1] = (p_a[1] * ymax);
- geometry[1][1] = (p_b[1] * ymax);
- geometry[2][1] = (p_c[1] * ymax);
- geometry[3][1] = (p_d[1] * ymax);
-
- /* subdivide the curve ntimes (1000) times */
- ntimes = 4 * xmax;
- /* ntimes can be adjusted to give a finer or coarser curve */
- d = 1.0 / ntimes;
- d2 = d * d;
- d3 = d * d * d;
-
- /* construct a temporary matrix for determining the forward differencing deltas */
- tmp2[0][0] = 0; tmp2[0][1] = 0; tmp2[0][2] = 0; tmp2[0][3] = 1;
- tmp2[1][0] = d3; tmp2[1][1] = d2; tmp2[1][2] = d; tmp2[1][3] = 0;
- tmp2[2][0] = 6*d3; tmp2[2][1] = 2*d2; tmp2[2][2] = 0; tmp2[2][3] = 0;
- tmp2[3][0] = 6*d3; tmp2[3][1] = 0; tmp2[3][2] = 0; tmp2[3][3] = 0;
-
- /* compose the basis and geometry matrices */
-
- static const float CR_basis[4][4] = {
- { -0.5, 1.5, -1.5, 0.5 },
- { 1.0, -2.5, 2.0, -0.5 },
- { -0.5, 0.0, 0.5, 0.0 },
- { 0.0, 1.0, 0.0, 0.0 },
- };
-
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < 4; j++)
- {
- tmp1[i][j] = (CR_basis[i][0] * geometry[0][j] +
- CR_basis[i][1] * geometry[1][j] +
- CR_basis[i][2] * geometry[2][j] +
- CR_basis[i][3] * geometry[3][j]);
- }
- }
- /* compose the above results to get the deltas matrix */
-
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < 4; j++)
- {
- deltas[i][j] = (tmp2[i][0] * tmp1[0][j] +
- tmp2[i][1] * tmp1[1][j] +
- tmp2[i][2] * tmp1[2][j] +
- tmp2[i][3] * tmp1[3][j]);
- }
- }
-
-
- /* extract the x deltas */
- x = deltas[0][0];
- dx = deltas[1][0];
- dx2 = deltas[2][0];
- dx3 = deltas[3][0];
-
- /* extract the y deltas */
- y = deltas[0][1];
- dy = deltas[1][1];
- dy2 = deltas[2][1];
- dy3 = deltas[3][1];
-
-
- lastx = CLAMP (x, 0, xmax);
- lasty = CLAMP (y, 0, ymax);
-
- p_heights[lastx] = lasty;
- p_useds[lastx] = true;
-
- /* loop over the curve */
- for (i = 0; i < ntimes; i++)
- {
- /* increment the x values */
- x += dx;
- dx += dx2;
- dx2 += dx3;
-
- /* increment the y values */
- y += dy;
- dy += dy2;
- dy2 += dy3;
-
- newx = CLAMP ((Math::round (x)), 0, xmax);
- newy = CLAMP ((Math::round (y)), 0, ymax);
-
- /* if this point is different than the last one...then draw it */
- if ((lastx != newx) || (lasty != newy))
- {
- p_useds[newx]=true;
- p_heights[newx]=newy;
- }
-
- lastx = newx;
- lasty = newy;
- }
-}
-
-
-void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<String>& p_inputs,String& code) {
-
-
- const char *typestr[4]={"float","vec3","mat4","texture"};
-#define OUTNAME(id, slot) (String(typestr[get_node_output_slot_type(get_mode(), p_type, p_node->type, slot)]) + " " + ("nd" + itos(id) + "sl" + itos(slot)))
-#define OUTVAR(id, slot) ("nd" + itos(id) + "sl" + itos(slot))
-#define DEF_VEC(slot) \
- if (p_inputs[slot].ends_with("def")) { \
- Vector3 v = p_node->defaults[slot]; \
- code += String(typestr[1]) + " " + p_inputs[slot] + "=vec3(" + v + ");\n"; \
- }
-#define DEF_SCALAR(slot) \
- if (p_inputs[slot].ends_with("def")) { \
- double v = p_node->defaults[slot]; \
- code += String(typestr[0]) + " " + p_inputs[slot] + "=" + rtos(v) + ";\n"; \
- }
-#define DEF_COLOR(slot) \
- if (p_inputs[slot].ends_with("def")) { \
- Color col = p_node->defaults[slot]; \
- code += String(typestr[1]) + " " + p_inputs[slot] + "=vec3(" + rtos(col.r) + "," + rtos(col.g) + "," + rtos(col.b) + ");\n"; \
- }
-#define DEF_MATRIX(slot) \
- if (p_inputs[slot].ends_with("def")) { \
- Transform xf = p_node->defaults[slot]; \
- code += String(typestr[2]) + " " + p_inputs[slot] + "=mat4(\n"; \
- code += "\tvec4(vec3(" + rtos(xf.basis.get_axis(0).x) + "," + rtos(xf.basis.get_axis(0).y) + "," + rtos(xf.basis.get_axis(0).z) + "),0),\n"; \
- code += "\tvec4(vec3(" + rtos(xf.basis.get_axis(1).x) + "," + rtos(xf.basis.get_axis(1).y) + "," + rtos(xf.basis.get_axis(1).z) + "),0),\n"; \
- code += "\tvec4(vec3(" + rtos(xf.basis.get_axis(2).x) + "," + rtos(xf.basis.get_axis(2).y) + "," + rtos(xf.basis.get_axis(2).z) + "),0),\n"; \
- code += "\tvec4(vec3(" + rtos(xf.origin.x) + "," + rtos(xf.origin.y) + "," + rtos(xf.origin.z) + "),1)\n"; \
- code += ");\n"; \
- }
-
- switch(p_node->type) {
-
- case NODE_INPUT: {
-
-
- }break;
- case NODE_SCALAR_CONST: {
-
- double scalar = p_node->param1;
- code+=OUTNAME(p_node->id,0)+"="+rtos(scalar)+";\n";
- }break;
- case NODE_VEC_CONST: {
- Vector3 vec = p_node->param1;
- code+=OUTNAME(p_node->id,0)+"=vec3("+rtos(vec.x)+","+rtos(vec.y)+","+rtos(vec.z)+");\n";
- }break;
- case NODE_RGB_CONST: {
- Color col = p_node->param1;
- code+=OUTNAME(p_node->id,0)+"=vec3("+rtos(col.r)+","+rtos(col.g)+","+rtos(col.b)+");\n";
- code+=OUTNAME(p_node->id,1)+"="+rtos(col.a)+";\n";
- }break;
- case NODE_XFORM_CONST: {
-
- Transform xf = p_node->param1;
- code+=OUTNAME(p_node->id,0)+"=mat4(\n";
- code+="\tvec4(vec3("+rtos(xf.basis.get_axis(0).x)+","+rtos(xf.basis.get_axis(0).y)+","+rtos(xf.basis.get_axis(0).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(xf.basis.get_axis(1).x)+","+rtos(xf.basis.get_axis(1).y)+","+rtos(xf.basis.get_axis(1).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(xf.basis.get_axis(2).x)+","+rtos(xf.basis.get_axis(2).y)+","+rtos(xf.basis.get_axis(2).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(xf.origin.x)+","+rtos(xf.origin.y)+","+rtos(xf.origin.z)+"),1)\n";
- code+=");";
-
- }break;
- case NODE_TIME: {
- code+=OUTNAME(p_node->id,0)+"=TIME;\n";
- }break;
- case NODE_SCREEN_TEX: {
- DEF_VEC(0);
- code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+".xy);\n";
- }break;
- case NODE_SCALAR_OP: {
- DEF_SCALAR(0);
- DEF_SCALAR(1);
- int op = p_node->param1;
- String optxt;
- switch(op) {
-
- case SCALAR_OP_ADD: optxt = p_inputs[0]+"+"+p_inputs[1]+";"; break;
- case SCALAR_OP_SUB: optxt = p_inputs[0]+"-"+p_inputs[1]+";"; break;
- case SCALAR_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
- case SCALAR_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
- case SCALAR_OP_MOD: optxt = "mod("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case SCALAR_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case SCALAR_OP_MAX: optxt = "max("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case SCALAR_OP_MIN: optxt = "min("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case SCALAR_OP_ATAN2: optxt = "atan2("+p_inputs[0]+","+p_inputs[1]+");"; break;
-
- }
- code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";
-
- }break;
- case NODE_VEC_OP: {
- DEF_VEC(0);
- DEF_VEC(1);
- int op = p_node->param1;
- String optxt;
- switch(op) {
- case VEC_OP_ADD: optxt = p_inputs[0]+"+"+p_inputs[1]+";"; break;
- case VEC_OP_SUB: optxt = p_inputs[0]+"-"+p_inputs[1]+";"; break;
- case VEC_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
- case VEC_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
- case VEC_OP_MOD: optxt = "mod("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case VEC_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case VEC_OP_MAX: optxt = "max("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case VEC_OP_MIN: optxt = "min("+p_inputs[0]+","+p_inputs[1]+");"; break;
- case VEC_OP_CROSS: optxt = "cross("+p_inputs[0]+","+p_inputs[1]+");"; break;
- }
- code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";
-
- }break;
- case NODE_VEC_SCALAR_OP: {
- DEF_VEC(0);
- DEF_SCALAR(1);
- int op = p_node->param1;
- String optxt;
- switch(op) {
- case VEC_SCALAR_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
- case VEC_SCALAR_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
- case VEC_SCALAR_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
- }
- code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";
-
- }break;
- case NODE_RGB_OP: {
- DEF_COLOR(0);
- DEF_COLOR(1);
-
- int op = p_node->param1;
- static const char*axisn[3]={"x","y","z"};
- switch(op) {
- case RGB_OP_SCREEN: {
-
- code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")*(vec3(1.0)-"+p_inputs[1]+");\n";
- } break;
- case RGB_OP_DIFFERENCE: {
-
- code += OUTNAME(p_node->id,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n";
- } break;
- case RGB_OP_DARKEN: {
-
- code += OUTNAME(p_node->id,0)+"=min("+p_inputs[0]+","+p_inputs[1]+");\n";
- } break;
- case RGB_OP_LIGHTEN: {
-
- code += OUTNAME(p_node->id,0)+"=max("+p_inputs[0]+","+p_inputs[1]+");\n";
-
- } break;
- case RGB_OP_OVERLAY: {
-
- code += OUTNAME(p_node->id,0)+";\n";
- for(int i=0;i<3;i++) {
- code += "{\n";
- code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
- code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
- code += "\tif (base < 0.5) {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 2.0 * base * blend;\n";
- code += "\t} else {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
- code += "\t}\n";
- code += "}\n";
- }
-
- } break;
- case RGB_OP_DODGE: {
-
- code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+")/(vec3(1.0)-"+p_inputs[1]+");\n";
-
- } break;
- case RGB_OP_BURN: {
-
- code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")/("+p_inputs[1]+");\n";
- } break;
- case RGB_OP_SOFT_LIGHT: {
-
- code += OUTNAME(p_node->id,0)+";\n";
- for(int i=0;i<3;i++) {
- code += "{\n";
- code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
- code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
- code += "\tif (base < 0.5) {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (blend+0.5));\n";
- code += "\t} else {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-(blend-0.5)));\n";
- code += "\t}\n";
- code += "}\n";
- }
-
- } break;
- case RGB_OP_HARD_LIGHT: {
-
- code += OUTNAME(p_node->id,0)+";\n";
- for(int i=0;i<3;i++) {
- code += "{\n";
- code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
- code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
- code += "\tif (base < 0.5) {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (2*blend));\n";
- code += "\t} else {\n";
- code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-2*(blend-0.5)));\n";
- code += "\t}\n";
- code += "}\n";
- }
-
- } break;
- }
- }break;
- case NODE_XFORM_MULT: {
- DEF_MATRIX(0);
- DEF_MATRIX(1);
-
- code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+"*"+p_inputs[1]+";\n";
-
- }break;
- case NODE_XFORM_VEC_MULT: {
- DEF_MATRIX(0);
- DEF_VEC(1);
-
- bool no_translation = p_node->param1;
- if (no_translation) {
- code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",0)).xyz;\n";
- } else {
- code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",1)).xyz;\n";
- }
-
- }break;
- case NODE_XFORM_VEC_INV_MULT: {
- DEF_VEC(0);
- DEF_MATRIX(1);
- bool no_translation = p_node->param1;
- if (no_translation) {
- code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",0)).xyz;\n";
- } else {
- code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",1)).xyz;\n";
- }
- }break;
- case NODE_SCALAR_FUNC: {
- DEF_SCALAR(0);
- static const char*scalar_func_id[SCALAR_MAX_FUNC]={
- "sin($)",
- "cos($)",
- "tan($)",
- "asin($)",
- "acos($)",
- "atan($)",
- "sinh($)",
- "cosh($)",
- "tanh($)",
- "log($)",
- "exp($)",
- "sqrt($)",
- "abs($)",
- "sign($)",
- "floor($)",
- "round($)",
- "ceil($)",
- "fract($)",
- "min(max($,0),1)",
- "-($)",
- };
-
- int func = p_node->param1;
- ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC);
- code += OUTNAME(p_node->id,0)+"="+String(scalar_func_id[func]).replace("$",p_inputs[0])+";\n";
-
- } break;
- case NODE_VEC_FUNC: {
- DEF_VEC(0);
- static const char*vec_func_id[VEC_MAX_FUNC]={
- "normalize($)",
- "max(min($,vec3(1,1,1)),vec3(0,0,0))",
- "-($)",
- "1.0/($)",
- "",
- "",
- };
-
-
- int func = p_node->param1;
- ERR_FAIL_INDEX(func,VEC_MAX_FUNC);
- if (func==VEC_FUNC_RGB2HSV) {
- code += OUTNAME(p_node->id,0)+";\n";
- code+="{\n";
- code+="\tvec3 c = "+p_inputs[0]+";\n";
- code+="\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
- code+="\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
- code+="\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
- code+="\tfloat d = q.x - min(q.w, q.y);\n";
- code+="\tfloat e = 1.0e-10;\n";
- code+="\t"+OUTVAR(p_node->id,0)+"=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
- code+="}\n";
- } else if (func==VEC_FUNC_HSV2RGB) {
- code += OUTNAME(p_node->id,0)+";\n";
- code+="{\n";
- code+="\tvec3 c = "+p_inputs[0]+";\n";
- code+="\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
- code+="\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
- code+="\t"+OUTVAR(p_node->id,0)+"=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
- code+="}\n";
-
- } else {
- code += OUTNAME(p_node->id,0)+"="+String(vec_func_id[func]).replace("$",p_inputs[0])+";\n";
- }
- }break;
- case NODE_VEC_LEN: {
- DEF_VEC(0);
-
- code += OUTNAME(p_node->id,0)+"=length("+p_inputs[0]+");\n";
-
- }break;
- case NODE_DOT_PROD: {
- DEF_VEC(0);
- DEF_VEC(1);
- code += OUTNAME(p_node->id,0)+"=dot("+p_inputs[1]+","+p_inputs[0]+");\n";
-
- }break;
- case NODE_VEC_TO_SCALAR: {
- DEF_VEC(0);
- code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+".x;\n";
- code += OUTNAME(p_node->id,1)+"="+p_inputs[0]+".y;\n";
- code += OUTNAME(p_node->id,2)+"="+p_inputs[0]+".z;\n";
-
- }break;
- case NODE_SCALAR_TO_VEC: {
- DEF_SCALAR(0);
- DEF_SCALAR(1);
- DEF_SCALAR(2);
- code += OUTNAME(p_node->id,0)+"=vec3("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+""+");\n";
-
- }break;
- case NODE_VEC_TO_XFORM: {
- DEF_VEC(0);
- DEF_VEC(1);
- DEF_VEC(2);
- DEF_VEC(3);
- code += OUTNAME(p_node->id, 0) + "=mat4(" +
- "vec4(" + p_inputs[0] + ".x," + p_inputs[0] + ".y," + p_inputs[0] + ".z, 0.0),"
- "vec4(" + p_inputs[1] + ".x," + p_inputs[1] + ".y," + p_inputs[1] + ".z, 0.0),"
- "vec4(" + p_inputs[2] + ".x," + p_inputs[2] + ".y," + p_inputs[2] + ".z, 0.0),"
- "vec4(" + p_inputs[3] + ".x," + p_inputs[3] + ".y," + p_inputs[3] + ".z, 1.0));\n";
-
- }break;
- case NODE_XFORM_TO_VEC: {
- DEF_MATRIX(0);
- code += OUTNAME(p_node->id, 0) + ";\n";
- code += OUTNAME(p_node->id, 1) + ";\n";
- code += OUTNAME(p_node->id, 2) + ";\n";
- code += OUTNAME(p_node->id, 3) + ";\n";
- code += "{\n";
- code += "\tvec4 xform_row_01=" + p_inputs[0] + ".x;\n";
- code += "\tvec4 xform_row_02=" + p_inputs[0] + ".y;\n";
- code += "\tvec4 xform_row_03=" + p_inputs[0] + ".z;\n";
- code += "\tvec4 xform_row_04=" + p_inputs[0] + ".w;\n";
- code += "\t" + OUTVAR(p_node->id, 0) + "=vec3(xform_row_01.x, xform_row_01.y, xform_row_01.z);\n";
- code += "\t" + OUTVAR(p_node->id, 1) + "=vec3(xform_row_02.x, xform_row_02.y, xform_row_02.z);\n";
- code += "\t" + OUTVAR(p_node->id, 2) + "=vec3(xform_row_03.x, xform_row_03.y, xform_row_03.z);\n";
- code += "\t" + OUTVAR(p_node->id, 3) + "=vec3(xform_row_04.x, xform_row_04.y, xform_row_04.z);\n";
- code += "}\n";
- }break;
- case NODE_SCALAR_INTERP: {
- DEF_SCALAR(0);
- DEF_SCALAR(1);
- DEF_SCALAR(2);
-
- code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n";
-
- }break;
- case NODE_VEC_INTERP: {
- DEF_VEC(0);
- DEF_VEC(1);
- DEF_SCALAR(2);
- code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n";
-
- }break;
- case NODE_COLOR_RAMP: {
- DEF_SCALAR(0);
-
- static const int color_ramp_len=512;
- PoolVector<uint8_t> cramp;
- cramp.resize(color_ramp_len*4);
- {
-
- PoolVector<Color> colors=p_node->param1;
- PoolVector<real_t> offsets=p_node->param2;
- int cc =colors.size();
- PoolVector<uint8_t>::Write crw = cramp.write();
- PoolVector<Color>::Read cr = colors.read();
- PoolVector<real_t>::Read ofr = offsets.read();
-
- int at=0;
- Color color_at(0,0,0,1);
- for(int i=0;i<=cc;i++) {
-
- int pos;
- Color to;
- if (i==cc) {
- if (at==color_ramp_len)
- break;
- pos=color_ramp_len;
- to=Color(1,1,1,1);
- } else {
- to=cr[i];
- pos= MIN(ofr[i]*color_ramp_len,color_ramp_len);
- }
- for(int j=at;j<pos;j++) {
- float t = (j-at)/float(pos-at);
- Color c = color_at.linear_interpolate(to,t);
- crw[j*4+0]=Math::fast_ftoi( CLAMP(c.r*255.0,0,255) );
- crw[j*4+1]=Math::fast_ftoi( CLAMP(c.g*255.0,0,255) );
- crw[j*4+2]=Math::fast_ftoi( CLAMP(c.b*255.0,0,255) );
- crw[j*4+3]=Math::fast_ftoi( CLAMP(c.a*255.0,0,255) );
- }
-
- at=pos;
- color_at=to;
- }
- }
-
- Image gradient(color_ramp_len,1,0,Image::FORMAT_RGBA8,cramp);
- Ref<ImageTexture> it = memnew( ImageTexture );
- it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS);
-
- String crampname= "cramp_"+itos(p_node->id);
- set_default_texture_param(crampname,it);
-
- code +="uniform texture "+crampname+";\n";
- code +="vec4 "+crampname+"_r=tex("+crampname+",vec2("+p_inputs[0]+",0));\n";
- code += OUTNAME(p_node->id,0)+"="+crampname+"_r.rgb;\n";
- code += OUTNAME(p_node->id,1)+"="+crampname+"_r.a;\n";
-
- }break;
- case NODE_CURVE_MAP: {
- DEF_SCALAR(0);
- static const int curve_map_len=256;
- bool mapped[256];
- zeromem(mapped,sizeof(mapped));
- PoolVector<uint8_t> cmap;
- cmap.resize(curve_map_len);
- {
-
- PoolVector<Point2> points=p_node->param1;
- int pc =points.size();
- PoolVector<uint8_t>::Write cmw = cmap.write();
- PoolVector<Point2>::Read pr = points.read();
-
- Vector2 prev=Vector2(0,0);
- Vector2 prev2=Vector2(0,0);
-
- for(int i=-1;i<pc;i++) {
-
- Vector2 next;
- Vector2 next2;
- if (i+1>=pc) {
- next=Vector2(1,1);
- } else {
- next=Vector2(pr[i+1].x,pr[i+1].y);
- }
-
- if (i+2>=pc) {
- next2=Vector2(1,1);
- } else {
- next2=Vector2(pr[i+2].x,pr[i+2].y);
- }
-
- /*if (i==-1 && prev.offset==next.offset) {
- prev=next;
- continue;
- }*/
-
- _plot_curve(prev2,prev,next,next2,cmw.ptr(),mapped);
-
- prev2=prev;
- prev=next;
- }
-
- uint8_t pp=0;
- for(int i=0;i<curve_map_len;i++) {
-
- if (!mapped[i]) {
- cmw[i]=pp;
- } else {
- pp=cmw[i];
- }
- }
- }
-
-
-
- Image gradient(curve_map_len,1,0,Image::FORMAT_L8,cmap);
- Ref<ImageTexture> it = memnew( ImageTexture );
- it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS);
-
- String cmapname= "cmap_"+itos(p_node->id);
- set_default_texture_param(cmapname,it);
-
- code +="uniform texture "+cmapname+";\n";
- code += OUTNAME(p_node->id,0)+"=tex("+cmapname+",vec2("+p_inputs[0]+",0)).r;\n";
-
- }break;
- case NODE_SCALAR_INPUT: {
- String name = p_node->param1;
- float dv=p_node->param2;
- code +="uniform float "+name+"="+rtos(dv)+";\n";
- code += OUTNAME(p_node->id,0)+"="+name+";\n";
- }break;
- case NODE_VEC_INPUT: {
-
- String name = p_node->param1;
- Vector3 dv=p_node->param2;
- code +="uniform vec3 "+name+"=vec3("+rtos(dv.x)+","+rtos(dv.y)+","+rtos(dv.z)+");\n";
- code += OUTNAME(p_node->id,0)+"="+name+";\n";
- }break;
- case NODE_RGB_INPUT: {
-
- String name = p_node->param1;
- Color dv= p_node->param2;
-
- code +="uniform color "+name+"=vec4("+rtos(dv.r)+","+rtos(dv.g)+","+rtos(dv.b)+","+rtos(dv.a)+");\n";
- code += OUTNAME(p_node->id,0)+"="+name+".rgb;\n";
- code += OUTNAME(p_node->id,1)+"="+name+".a;\n";
-
- }break;
- case NODE_XFORM_INPUT: {
-
- String name = p_node->param1;
- Transform dv= p_node->param2;
-
- code +="uniform mat4 "+name+"=mat4(\n";
- code+="\tvec4(vec3("+rtos(dv.basis.get_axis(0).x)+","+rtos(dv.basis.get_axis(0).y)+","+rtos(dv.basis.get_axis(0).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(dv.basis.get_axis(1).x)+","+rtos(dv.basis.get_axis(1).y)+","+rtos(dv.basis.get_axis(1).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(dv.basis.get_axis(2).x)+","+rtos(dv.basis.get_axis(2).y)+","+rtos(dv.basis.get_axis(2).z)+"),0),\n";
- code+="\tvec4(vec3("+rtos(dv.origin.x)+","+rtos(dv.origin.y)+","+rtos(dv.origin.z)+"),1)\n";
- code+=");";
-
- code += OUTNAME(p_node->id,0)+"="+name+";\n";
-
- }break;
- case NODE_TEXTURE_INPUT: {
- DEF_VEC(0);
- String name = p_node->param1;
- String rname="rt_read_tex"+itos(p_node->id);
- code +="uniform texture "+name+";";
- code +="vec4 "+rname+"=tex("+name+","+p_inputs[0]+".xy);\n";
- code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n";
- code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
-
- }break;
- case NODE_CUBEMAP_INPUT: {
- DEF_VEC(0);
- String name = p_node->param1;
- code +="uniform cubemap "+name+";";
- String rname="rt_read_tex"+itos(p_node->id);
- code +="vec4 "+rname+"=texcube("+name+","+p_inputs[0]+".xy);\n";
- code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n";
- code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
- }break;
- case NODE_DEFAULT_TEXTURE: {
- DEF_VEC(0);
-
- if (get_mode()==MODE_CANVAS_ITEM && p_type==SHADER_TYPE_FRAGMENT) {
-
- String rname="rt_default_tex"+itos(p_node->id);
- code +="vec4 "+rname+"=tex(TEXTURE,"+p_inputs[0]+".xy);\n";
- code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n";
- code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
-
- } else {
- //not supported
- code += OUTNAME(p_node->id,0)+"=vec3(0,0,0);\n";
- code += OUTNAME(p_node->id,1)+"=1.0;\n";
-
- }
- } break;
- case NODE_OUTPUT: {
-
-
- }break;
- case NODE_COMMENT: {
-
- }break;
- case NODE_TYPE_MAX: {
-
- }
- }
-#undef DEF_SCALAR
-#undef DEF_COLOR
-#undef DEF_MATRIX
-#undef DEF_VEC
-}
-
-#endif
diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h
deleted file mode 100644
index e3a68f8572..0000000000
--- a/scene/resources/shader_graph.h
+++ /dev/null
@@ -1,446 +0,0 @@
-/*************************************************************************/
-/* shader_graph.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 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. */
-/*************************************************************************/
-
-#ifndef SHADER_GRAPH_H
-#define SHADER_GRAPH_H
-
-// FIXME: Needs to be ported to the new 3.0 shader API
-#if 0
-#include "map.h"
-#include "scene/resources/shader.h"
-
-class ShaderGraph : public Shader {
-
- GDCLASS( ShaderGraph, Shader );
- RES_BASE_EXTENSION("vshader");
-
-public:
-
- enum NodeType {
- NODE_INPUT, // all inputs (shader type dependent)
- NODE_SCALAR_CONST, //scalar constant
- NODE_VEC_CONST, //vec3 constant
- NODE_RGB_CONST, //rgb constant (shows a color picker instead)
- NODE_XFORM_CONST, // 4x4 matrix constant
- NODE_TIME, // time in seconds
- NODE_SCREEN_TEX, // screen texture sampler (takes UV) (only usable in fragment shader)
- NODE_SCALAR_OP, // scalar vs scalar op (mul, add, div, etc)
- NODE_VEC_OP, // vec3 vs vec3 op (mul,ad,div,crossprod,etc)
- NODE_VEC_SCALAR_OP, // vec3 vs scalar op (mul, add, div, etc)
- NODE_RGB_OP, // vec3 vs vec3 rgb op (with scalar amount), like brighten, darken, burn, dodge, multiply, etc.
- NODE_XFORM_MULT, // mat4 x mat4
- NODE_XFORM_VEC_MULT, // mat4 x vec3 mult (with no-translation option)
- NODE_XFORM_VEC_INV_MULT, // mat4 x vec3 inverse mult (with no-translation option)
- NODE_SCALAR_FUNC, // scalar function (sin, cos, etc)
- NODE_VEC_FUNC, // vector function (normalize, negate, reciprocal, rgb2hsv, hsv2rgb, etc, etc)
- NODE_VEC_LEN, // vec3 length
- NODE_DOT_PROD, // vec3 . vec3 (dot product -> scalar output)
- NODE_VEC_TO_SCALAR, // 1 vec3 input, 3 scalar outputs
- NODE_SCALAR_TO_VEC, // 3 scalar input, 1 vec3 output
- NODE_XFORM_TO_VEC, // 3 vec input, 1 xform output
- NODE_VEC_TO_XFORM, // 3 vec input, 1 xform output
- NODE_SCALAR_INTERP, // scalar interpolation (with optional curve)
- NODE_VEC_INTERP, // vec3 interpolation (with optional curve)
- NODE_COLOR_RAMP, //take scalar, output vec3
- NODE_CURVE_MAP, //take scalar, otput scalar
- NODE_SCALAR_INPUT, // scalar uniform (assignable in material)
- NODE_VEC_INPUT, // vec3 uniform (assignable in material)
- NODE_RGB_INPUT, // color uniform (assignable in material)
- NODE_XFORM_INPUT, // mat4 uniform (assignable in material)
- NODE_TEXTURE_INPUT, // texture input (assignable in material)
- NODE_CUBEMAP_INPUT, // cubemap input (assignable in material)
- NODE_DEFAULT_TEXTURE,
- NODE_OUTPUT, // output (shader type dependent)
- NODE_COMMENT, // comment
- NODE_TYPE_MAX
- };
-
-
- struct Connection {
-
- int src_id;
- int src_slot;
- int dst_id;
- int dst_slot;
- };
-
- enum SlotType {
-
- SLOT_TYPE_SCALAR,
- SLOT_TYPE_VEC,
- SLOT_TYPE_XFORM,
- SLOT_TYPE_TEXTURE,
- SLOT_MAX
- };
-
- enum ShaderType {
- SHADER_TYPE_VERTEX,
- SHADER_TYPE_FRAGMENT,
- SHADER_TYPE_LIGHT,
- SHADER_TYPE_MAX
- };
-
- enum SlotDir {
- SLOT_IN,
- SLOT_OUT
- };
-
- enum GraphError {
- GRAPH_OK,
- GRAPH_ERROR_CYCLIC,
- GRAPH_ERROR_MISSING_CONNECTIONS
- };
-
-private:
-
- String _find_unique_name(const String& p_base);
-
- enum {SLOT_DEFAULT_VALUE = 0x7FFFFFFF};
- struct SourceSlot {
-
- int id;
- int slot;
- bool operator==(const SourceSlot& p_slot) const {
- return id==p_slot.id && slot==p_slot.slot;
- }
- };
-
- struct Node {
-
- Vector2 pos;
- NodeType type;
- Variant param1;
- Variant param2;
- Map<int, Variant> defaults;
- int id;
- mutable int order; // used for sorting
- int sort_order;
- Map<int,SourceSlot> connections;
-
- };
-
- struct ShaderData {
- Map<int,Node> node_map;
- GraphError error;
- } shader[3];
-
-
-
- struct InOutParamInfo {
- Mode shader_mode;
- ShaderType shader_type;
- const char *name;
- const char *variable;
- const char *postfix;
- SlotType slot_type;
- SlotDir dir;
- };
-
- static const InOutParamInfo inout_param_info[];
-
- struct NodeSlotInfo {
-
- enum { MAX_INS=3, MAX_OUTS=3 };
- NodeType type;
- const SlotType ins[MAX_INS];
- const SlotType outs[MAX_OUTS];
- };
-
- static const NodeSlotInfo node_slot_info[];
-
- bool _pending_update_shader;
- void _update_shader();
- void _request_update();
-
- void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d,uint8_t* p_heights,bool *p_useds);
- void _add_node_code(ShaderType p_type,Node *p_node,const Vector<String>& p_inputs,String& code);
-
- Array _get_node_list(ShaderType p_type) const;
- Array _get_connections(ShaderType p_type) const;
-
- void _set_data(const Dictionary& p_data);
- Dictionary _get_data() const;
-protected:
-
- static void _bind_methods();
-
-public:
-
-
- void node_add(ShaderType p_type, NodeType p_node_type, int p_id);
- void node_remove(ShaderType p_which,int p_id);
- void node_set_position(ShaderType p_which,int p_id,const Point2& p_pos);
- Point2 node_get_position(ShaderType p_which,int p_id) const;
-
- void get_node_list(ShaderType p_which,List<int> *p_node_list) const;
- NodeType node_get_type(ShaderType p_which,int p_id) const;
-
- void scalar_const_node_set_value(ShaderType p_which,int p_id,float p_value);
- float scalar_const_node_get_value(ShaderType p_which,int p_id) const;
-
- void vec_const_node_set_value(ShaderType p_which,int p_id,const Vector3& p_value);
- Vector3 vec_const_node_get_value(ShaderType p_which,int p_id) const;
-
- void rgb_const_node_set_value(ShaderType p_which,int p_id,const Color& p_value);
- Color rgb_const_node_get_value(ShaderType p_which,int p_id) const;
-
- void xform_const_node_set_value(ShaderType p_which,int p_id,const Transform& p_value);
- Transform xform_const_node_get_value(ShaderType p_which,int p_id) const;
-
- void texture_node_set_filter_size(ShaderType p_which,int p_id,int p_size);
- int texture_node_get_filter_size(ShaderType p_which,int p_id) const;
-
- void texture_node_set_filter_strength(ShaderType p_which,float p_id,float p_strength);
- float texture_node_get_filter_strength(ShaderType p_which,float p_id) const;
-
- void duplicate_nodes(ShaderType p_which, List<int> &p_nodes);
-
- List<int> generate_ids(ShaderType p_type, int count);
-
- enum ScalarOp {
- SCALAR_OP_ADD,
- SCALAR_OP_SUB,
- SCALAR_OP_MUL,
- SCALAR_OP_DIV,
- SCALAR_OP_MOD,
- SCALAR_OP_POW,
- SCALAR_OP_MAX,
- SCALAR_OP_MIN,
- SCALAR_OP_ATAN2,
- SCALAR_MAX_OP
- };
-
- void scalar_op_node_set_op(ShaderType p_which,float p_id,ScalarOp p_op);
- ScalarOp scalar_op_node_get_op(ShaderType p_which,float p_id) const;
-
- enum VecOp {
- VEC_OP_ADD,
- VEC_OP_SUB,
- VEC_OP_MUL,
- VEC_OP_DIV,
- VEC_OP_MOD,
- VEC_OP_POW,
- VEC_OP_MAX,
- VEC_OP_MIN,
- VEC_OP_CROSS,
- VEC_MAX_OP
- };
-
- void vec_op_node_set_op(ShaderType p_which,float p_id,VecOp p_op);
- VecOp vec_op_node_get_op(ShaderType p_which,float p_id) const;
-
- enum VecScalarOp {
- VEC_SCALAR_OP_MUL,
- VEC_SCALAR_OP_DIV,
- VEC_SCALAR_OP_POW,
- VEC_SCALAR_MAX_OP
- };
-
- void vec_scalar_op_node_set_op(ShaderType p_which,float p_id,VecScalarOp p_op);
- VecScalarOp vec_scalar_op_node_get_op(ShaderType p_which,float p_id) const;
-
- enum RGBOp {
- RGB_OP_SCREEN,
- RGB_OP_DIFFERENCE,
- RGB_OP_DARKEN,
- RGB_OP_LIGHTEN,
- RGB_OP_OVERLAY,
- RGB_OP_DODGE,
- RGB_OP_BURN,
- RGB_OP_SOFT_LIGHT,
- RGB_OP_HARD_LIGHT,
- RGB_MAX_OP
- };
-
- void rgb_op_node_set_op(ShaderType p_which,float p_id,RGBOp p_op);
- RGBOp rgb_op_node_get_op(ShaderType p_which,float p_id) const;
-
- void xform_vec_mult_node_set_no_translation(ShaderType p_which,int p_id,bool p_no_translation);
- bool xform_vec_mult_node_get_no_translation(ShaderType p_which,int p_id) const;
-
- enum ScalarFunc {
- SCALAR_FUNC_SIN,
- SCALAR_FUNC_COS,
- SCALAR_FUNC_TAN,
- SCALAR_FUNC_ASIN,
- SCALAR_FUNC_ACOS,
- SCALAR_FUNC_ATAN,
- SCALAR_FUNC_SINH,
- SCALAR_FUNC_COSH,
- SCALAR_FUNC_TANH,
- SCALAR_FUNC_LOG,
- SCALAR_FUNC_EXP,
- SCALAR_FUNC_SQRT,
- SCALAR_FUNC_ABS,
- SCALAR_FUNC_SIGN,
- SCALAR_FUNC_FLOOR,
- SCALAR_FUNC_ROUND,
- SCALAR_FUNC_CEIL,
- SCALAR_FUNC_FRAC,
- SCALAR_FUNC_SATURATE,
- SCALAR_FUNC_NEGATE,
- SCALAR_MAX_FUNC
- };
-
- void scalar_func_node_set_function(ShaderType p_which,int p_id,ScalarFunc p_func);
- ScalarFunc scalar_func_node_get_function(ShaderType p_which,int p_id) const;
-
- enum VecFunc {
- VEC_FUNC_NORMALIZE,
- VEC_FUNC_SATURATE,
- VEC_FUNC_NEGATE,
- VEC_FUNC_RECIPROCAL,
- VEC_FUNC_RGB2HSV,
- VEC_FUNC_HSV2RGB,
- VEC_MAX_FUNC
- };
-
- void default_set_value(ShaderType p_which,int p_id,int p_param, const Variant& p_value);
- Variant default_get_value(ShaderType p_which,int p_id,int p_param);
-
- void vec_func_node_set_function(ShaderType p_which,int p_id,VecFunc p_func);
- VecFunc vec_func_node_get_function(ShaderType p_which,int p_id) const;
-
- void color_ramp_node_set_ramp(ShaderType p_which,int p_id,const PoolVector<Color>& p_colors, const PoolVector<real_t>& p_offsets);
- PoolVector<Color> color_ramp_node_get_colors(ShaderType p_which,int p_id) const;
- PoolVector<real_t> color_ramp_node_get_offsets(ShaderType p_which,int p_id) const;
-
- void curve_map_node_set_points(ShaderType p_which, int p_id, const PoolVector<Vector2>& p_points);
- PoolVector<Vector2> curve_map_node_get_points(ShaderType p_which,int p_id) const;
-
- void input_node_set_name(ShaderType p_which,int p_id,const String& p_name);
- String input_node_get_name(ShaderType p_which,int p_id);
-
- void scalar_input_node_set_value(ShaderType p_which,int p_id,float p_value);
- float scalar_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void vec_input_node_set_value(ShaderType p_which,int p_id,const Vector3& p_value);
- Vector3 vec_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void rgb_input_node_set_value(ShaderType p_which,int p_id,const Color& p_value);
- Color rgb_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void xform_input_node_set_value(ShaderType p_which,int p_id,const Transform& p_value);
- Transform xform_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void texture_input_node_set_value(ShaderType p_which,int p_id,const Ref<Texture>& p_texture);
- Ref<Texture> texture_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void cubemap_input_node_set_value(ShaderType p_which,int p_id,const Ref<CubeMap>& p_cubemap);
- Ref<CubeMap> cubemap_input_node_get_value(ShaderType p_which,int p_id) const;
-
- void comment_node_set_text(ShaderType p_which,int p_id,const String& p_comment);
- String comment_node_get_text(ShaderType p_which,int p_id) const;
-
- Error connect_node(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
- bool is_node_connected(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const;
- void disconnect_node(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
-
- void get_node_connections(ShaderType p_which,List<Connection> *p_connections) const;
-
- bool is_slot_connected(ShaderType p_which,int p_dst_id,int slot_id);
-
- void clear(ShaderType p_which);
-
- Variant node_get_state(ShaderType p_type, int p_node) const;
- void node_set_state(ShaderType p_type, int p_id, const Variant& p_state);
-
- GraphError get_graph_error(ShaderType p_type) const;
-
- int node_count(ShaderType p_which, int p_type);
-
- static int get_type_input_count(NodeType p_type);
- static int get_type_output_count(NodeType p_type);
- static SlotType get_type_input_type(NodeType p_type,int p_idx);
- static SlotType get_type_output_type(NodeType p_type,int p_idx);
- static bool is_type_valid(Mode p_mode,ShaderType p_type);
-
-
- struct SlotInfo {
- String name;
- SlotType type;
- SlotDir dir;
- };
-
- static void get_input_output_node_slot_info(Mode p_mode, ShaderType p_type, List<SlotInfo> *r_slots);
-
- static int get_node_input_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type);
- static int get_node_output_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type);
- static SlotType get_node_input_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx);
- static SlotType get_node_output_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx);
-
-
- ShaderGraph(Mode p_mode);
- ~ShaderGraph();
-};
-
-//helper functions
-
-
-
-
-VARIANT_ENUM_CAST( ShaderGraph::NodeType );
-VARIANT_ENUM_CAST( ShaderGraph::ShaderType );
-VARIANT_ENUM_CAST( ShaderGraph::SlotType );
-VARIANT_ENUM_CAST( ShaderGraph::ScalarOp );
-VARIANT_ENUM_CAST( ShaderGraph::VecOp );
-VARIANT_ENUM_CAST( ShaderGraph::VecScalarOp );
-VARIANT_ENUM_CAST( ShaderGraph::RGBOp );
-VARIANT_ENUM_CAST( ShaderGraph::ScalarFunc );
-VARIANT_ENUM_CAST( ShaderGraph::VecFunc );
-VARIANT_ENUM_CAST( ShaderGraph::GraphError );
-
-
-class MaterialShaderGraph : public ShaderGraph {
-
- GDCLASS( MaterialShaderGraph, ShaderGraph );
-
-public:
-
-
- MaterialShaderGraph() : ShaderGraph(MODE_MATERIAL) {
-
- }
-};
-
-class CanvasItemShaderGraph : public ShaderGraph {
-
- GDCLASS( CanvasItemShaderGraph, ShaderGraph );
-
-public:
-
-
- CanvasItemShaderGraph() : ShaderGraph(MODE_CANVAS_ITEM) {
-
- }
-};
-
-#endif
-#endif // SHADER_GRAPH_H
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index ec489e5c5b..81fabf40fe 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -755,15 +755,11 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
for (List<int>::Element *E = nindices.front(); E; E = E->next()) {
int dst_index = E->get() + vfrom;
- /*
- if (dst_index <0 || dst_index>=vertex_array.size()) {
- print_line("invalid index!");
- }
- */
index_array.push_back(dst_index);
}
- if (index_array.size() % 3)
- print_line("IA not div of 3?");
+ if (index_array.size() % 3) {
+ WARN_PRINT("SurfaceTool: Index array not a multiple of 3.");
+ }
}
//mikktspace callbacks
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index c763c9bc79..811e5c3d2c 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -480,7 +480,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
flags = f->get_32(); //texture flags!
uint32_t df = f->get_32(); //data format
-/*
+ /*
print_line("width: " + itos(tw));
print_line("height: " + itos(th));
print_line("flags: " + itos(flags));
@@ -1022,30 +1022,12 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
//this might not necessarily work well if using a rect, needs to be fixed properly
- Rect2 rc = region;
-
if (!atlas.is_valid())
return;
- Rect2 src = p_src_rect;
- src.position += (rc.position - margin.position);
- Rect2 src_c = rc.clip(src);
- if (src_c.size == Size2())
- return;
- Vector2 ofs = (src_c.position - src.position);
-
- Vector2 scale = p_rect.size / p_src_rect.size;
- if (scale.x < 0) {
- float mx = (margin.size.width - margin.position.x);
- mx -= margin.position.x;
- ofs.x = -(ofs.x + mx);
- }
- if (scale.y < 0) {
- float my = margin.size.height - margin.position.y;
- my -= margin.position.y;
- ofs.y = -(ofs.y + my);
- }
- Rect2 dr(p_rect.position + ofs * scale, src_c.size * scale);
+ Rect2 dr;
+ Rect2 src_c;
+ get_rect_region(p_rect, p_src_rect, dr, src_c);
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), src_c, p_modulate, p_transpose, normal_rid, filter_clip);
@@ -1059,13 +1041,17 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
return false;
Rect2 src = p_src_rect;
+ if (src.size == Size2()) {
+ src.size = rc.size;
+ }
+ Vector2 scale = p_rect.size / src.size;
+
src.position += (rc.position - margin.position);
Rect2 src_c = rc.clip(src);
if (src_c.size == Size2())
return false;
Vector2 ofs = (src_c.position - src.position);
- Vector2 scale = p_rect.size / p_src_rect.size;
if (scale.x < 0) {
float mx = (margin.size.width - margin.position.x);
mx -= margin.position.x;
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 3d2b6c36de..8112d6be00 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -59,7 +59,13 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
tile_set_region(id, p_value);
else if (what == "tile_mode")
tile_set_tile_mode(id, (TileMode)((int)p_value));
- else if (what.left(9) == "autotile/") {
+ else if (what == "is_autotile") {
+ // backward compatibility for Godot 3.0.x
+ // autotile used to be a bool, it's now an enum
+ bool is_autotile = p_value;
+ if (is_autotile)
+ tile_set_tile_mode(id, AUTO_TILE);
+ } else if (what.left(9) == "autotile/") {
what = what.right(9);
if (what == "bitmask_mode")
autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value));
@@ -950,6 +956,8 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("tile_get_region", "id"), &TileSet::tile_get_region);
ClassDB::bind_method(D_METHOD("tile_set_shape", "id", "shape_id", "shape"), &TileSet::tile_set_shape);
ClassDB::bind_method(D_METHOD("tile_get_shape", "id", "shape_id"), &TileSet::tile_get_shape);
+ ClassDB::bind_method(D_METHOD("tile_set_shape_offset", "id", "shape_id", "shape_offset"), &TileSet::tile_set_shape_offset);
+ ClassDB::bind_method(D_METHOD("tile_get_shape_offset", "id", "shape_id"), &TileSet::tile_get_shape_offset);
ClassDB::bind_method(D_METHOD("tile_set_shape_transform", "id", "shape_id", "shape_transform"), &TileSet::tile_set_shape_transform);
ClassDB::bind_method(D_METHOD("tile_get_shape_transform", "id", "shape_id"), &TileSet::tile_get_shape_transform);
ClassDB::bind_method(D_METHOD("tile_set_shape_one_way", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way);
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index d8fc3677fb..dac12205b6 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -431,7 +431,6 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
global_code += "\n\n";
String final_code = global_code;
final_code += code;
- //print_line(final_code);
return final_code;
}
@@ -914,7 +913,6 @@ void VisualShader::_update_shader() const {
String final_code = global_code;
final_code += code;
const_cast<VisualShader *>(this)->set_code(final_code);
- //print_line(final_code);
for (int i = 0; i < default_tex_params.size(); i++) {
const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].param);
}