From 89970848311ee2d49040a148a56d80590091877c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 10 Jan 2015 17:35:26 -0300 Subject: 2D Rewrite Step [1] -=-=-=-=-=-=-=-=-=- -Moved drawing code to a single function that takes linked list (should make it easier to optimize in the future). -Implemented Z ordering of 2D nodes. Node2D and those that inherit have a visibility/Z property that affects drawing order (besides the tree order) -Removed OpenGL ES 1.x support. Good riddance! --- servers/visual/visual_server_raster.h | 141 ++++------------------------------ 1 file changed, 17 insertions(+), 124 deletions(-) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index ce52077550..81a492611b 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -372,139 +372,28 @@ class VisualServerRaster : public VisualServer { - struct CanvasItem { - - struct Command { - - enum Type { - - TYPE_LINE, - TYPE_RECT, - TYPE_STYLE, - TYPE_PRIMITIVE, - TYPE_POLYGON, - TYPE_POLYGON_PTR, - TYPE_CIRCLE, - TYPE_TRANSFORM, - TYPE_BLEND_MODE, - TYPE_CLIP_IGNORE, - }; - - Type type; - }; - - struct CommandLine : public Command { - - Point2 from,to; - Color color; - float width; - CommandLine() { type = TYPE_LINE; } - }; - - struct CommandRect : public Command { - - Rect2 rect; - RID texture; - Color modulate; - Rect2 source; - uint8_t flags; - - CommandRect() { flags=0; type = TYPE_RECT; } - }; - - struct CommandStyle : public Command { - - Rect2 rect; - RID texture; - float margin[4]; - float draw_center; - Color color; - CommandStyle() { draw_center=true; type = TYPE_STYLE; } - }; - - struct CommandPrimitive : public Command { - - Vector points; - Vector uvs; - Vector colors; - RID texture; - float width; - - CommandPrimitive() { type = TYPE_PRIMITIVE; width=1;} - }; - - struct CommandPolygon : public Command { - - Vector indices; - Vector points; - Vector uvs; - Vector colors; - RID texture; - int count; - - CommandPolygon() { type = TYPE_POLYGON; count = 0; } - }; + struct CanvasItem : public Rasterizer::CanvasItem { - struct CommandPolygonPtr : public Command { - - const int* indices; - const Point2* points; - const Point2* uvs; - const Color* colors; - RID texture; - int count; - - CommandPolygonPtr() { type = TYPE_POLYGON_PTR; count = 0; } - }; - - struct CommandCircle : public Command { - - Point2 pos; - float radius; - Color color; - CommandCircle() { type = TYPE_CIRCLE; } - }; - - struct CommandTransform : public Command { - - Matrix32 xform; - CommandTransform() { type = TYPE_TRANSFORM; } - }; - - struct CommandBlendMode : public Command { - - MaterialBlendMode blend_mode; - CommandBlendMode() { type = TYPE_BLEND_MODE; blend_mode = MATERIAL_BLEND_MODE_MIX; }; - }; - struct CommandClipIgnore : public Command { - - bool ignore; - CommandClipIgnore() { type = TYPE_CLIP_IGNORE; ignore=false; }; - }; RID parent; // canvas it belongs to List::Element *E; - Matrix32 xform; - bool clip; - bool visible; - bool ontop; + RID viewport; + int z; bool sort_y; float opacity; float self_opacity; - MaterialBlendMode blend_mode; - RID viewport; - mutable bool custom_rect; - mutable bool rect_dirty; - mutable Rect2 rect; - - Vector commands; + Vector child_items; - const Rect2& get_rect() const; - void clear() { for (int i=0;i _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); Vector _camera_generate_orthogonal_planes(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); @@ -1217,6 +1108,8 @@ public: virtual void canvas_item_add_set_blend_mode(RID p_item, MaterialBlendMode p_blend); virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore); virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable); + virtual void canvas_item_set_z(RID p_item, int p_z); + virtual void canvas_item_clear(RID p_item); virtual void canvas_item_raise(RID p_item); -- cgit v1.2.3 From 66afddb3e8db03a675e744f74b07acc4db8f2aa1 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 11 Jan 2015 11:43:31 -0300 Subject: -Initial (untested) implementation of 2D shaders. Probably broken, will be fixed later. -fixed issue of opacity not working --- servers/visual/visual_server_raster.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 81a492611b..098c57480a 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1110,6 +1110,11 @@ public: virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable); virtual void canvas_item_set_z(RID p_item, int p_z); + virtual void canvas_item_set_shader(RID p_item, RID p_shader); + virtual RID canvas_item_get_shader(RID p_item) const; + + virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value); + virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const; virtual void canvas_item_clear(RID p_item); virtual void canvas_item_raise(RID p_item); -- cgit v1.2.3 From 30d36581100f0bf71c6d2502be9a03443bdf8708 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 12 Jan 2015 20:44:02 -0300 Subject: -fixed issue with shader not being reset on layers, closes #1199 -ability for shader to use parent shader and params, closes #1198 --- servers/visual/visual_server_raster.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 098c57480a..d30ac17400 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -85,6 +85,7 @@ class VisualServerRaster : public VisualServer { Vector shape; Rect2 bounds; + Portal() { enabled=true; disable_distance=50; disable_color=Color(); connect_range=0.8; } }; @@ -382,6 +383,7 @@ class VisualServerRaster : public VisualServer { bool sort_y; float opacity; float self_opacity; + bool use_parent_shader; Vector child_items; @@ -393,6 +395,7 @@ class VisualServerRaster : public VisualServer { opacity=1; self_opacity=1; sort_y=false; + use_parent_shader=false; } }; @@ -597,7 +600,7 @@ class VisualServerRaster : public VisualServer { void _render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario); static void _render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect); void _render_canvas_item_tree(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect); - void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect,float p_opacity,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip); + void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect,float p_opacity,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip,CanvasItem *p_shader_owner); void _render_canvas(Canvas *p_canvas,const Matrix32 &p_transform); Vector _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); Vector _camera_generate_orthogonal_planes(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); @@ -1113,6 +1116,9 @@ public: virtual void canvas_item_set_shader(RID p_item, RID p_shader); virtual RID canvas_item_get_shader(RID p_item) const; + virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable); + + virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value); virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const; -- cgit v1.2.3 From 2ef5a342e34df3863ac512bb3673eba28f15e9f4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 13 Jan 2015 10:49:26 -0300 Subject: -begin work on unidirectional collision detection -fixed performance issue in new 2D engine -texscreen() working in shader 2D --- servers/visual/visual_server_raster.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index d30ac17400..3fd8d7355b 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -380,6 +380,7 @@ class VisualServerRaster : public VisualServer { List::Element *E; RID viewport; int z; + bool z_relative; bool sort_y; float opacity; float self_opacity; @@ -396,6 +397,7 @@ class VisualServerRaster : public VisualServer { self_opacity=1; sort_y=false; use_parent_shader=false; + z_relative=true; } }; @@ -600,7 +602,7 @@ class VisualServerRaster : public VisualServer { void _render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario); static void _render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect); void _render_canvas_item_tree(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect); - void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect,float p_opacity,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip,CanvasItem *p_shader_owner); + void _render_canvas_item(CanvasItem *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect, float p_opacity,int p_z,Rasterizer::CanvasItem **z_list,Rasterizer::CanvasItem **z_last_list,CanvasItem *p_canvas_clip,CanvasItem *p_shader_owner); void _render_canvas(Canvas *p_canvas,const Matrix32 &p_transform); Vector _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); Vector _camera_generate_orthogonal_planes(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); @@ -1112,6 +1114,7 @@ public: virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore); virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable); virtual void canvas_item_set_z(RID p_item, int p_z); + virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable); virtual void canvas_item_set_shader(RID p_item, RID p_shader); virtual RID canvas_item_get_shader(RID p_item) const; -- cgit v1.2.3 From 9012cd408e240d6039120e56fdd47a0983890993 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 13 Jan 2015 21:19:11 -0300 Subject: -Add support for one-way collision in 2D (only works for kinematic body so far) -Solve drawing order bug introduced in previous commit: solves #1214 --- servers/visual/visual_server_raster.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 3fd8d7355b..6c4e15827a 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -392,7 +392,7 @@ class VisualServerRaster : public VisualServer { CanvasItem() { E=NULL; - z=CANVAS_ITEM_Z_MAX/2; + z=0; opacity=1; self_opacity=1; sort_y=false; -- cgit v1.2.3 From 67d357191ff74b2cfc80015941363a97e7ee19fd Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 22 Jan 2015 11:07:16 -0300 Subject: begin work on lighting system for 2D nothing functional yet, just experimenting with API --- servers/visual/visual_server_raster.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'servers/visual/visual_server_raster.h') diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 6c4e15827a..57032ab441 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1122,9 +1122,43 @@ public: virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable); + virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value); virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const; + virtual RID canvas_light_create(); + virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas); + virtual void canvas_light_set_enabled(RID p_light, bool p_enabled); + virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform); + virtual void canvas_light_set_texture(RID p_light, RID p_texture); + virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset); + virtual void canvas_light_set_color(RID p_light, const Color& p_color); + virtual void canvas_light_set_height(RID p_light, float p_height); + virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z); + virtual void canvas_light_set_item_mask(RID p_light, int p_mask); + + enum CanvasightBlendMode { + CANVAS_LIGHT_BLEND_ADD, + CANVAS_LIGHT_BLEND_SUB, + CANVAS_LIGHT_BLEND_MULTIPLY, + CANVAS_LIGHT_BLEND_DODGE, + CANVAS_LIGHT_BLEND_BURN, + CANVAS_LIGHT_BLEND_LIGHTEN, + CANVAS_LIGHT_BLEND_DARKEN, + CANVAS_LIGHT_BLEND_OVERLAY, + CANVAS_LIGHT_BLEND_SCREEN, + }; + virtual void canvas_light_set_blend_mode(RID p_light, CanvasLightBlendMode p_blend_mode); + virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled); + virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size); + virtual void canvas_light_set_shadow_filter(RID p_light, int p_size); + + + virtual RID canvas_light_occluder_create(); + virtual void canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas); + virtual void canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled); + virtual void canvas_light_occluder_set_shape(RID p_occluder,const DVector& p_shape); + virtual void canvas_item_clear(RID p_item); virtual void canvas_item_raise(RID p_item); -- cgit v1.2.3