diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/visual/rasterizer.h | 8 | ||||
-rw-r--r-- | servers/visual/rasterizer_dummy.cpp | 5 | ||||
-rw-r--r-- | servers/visual/rasterizer_dummy.h | 3 | ||||
-rw-r--r-- | servers/visual/shader_language.cpp | 5 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 32 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 8 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 3 | ||||
-rw-r--r-- | servers/visual_server.h | 2 |
8 files changed, 55 insertions, 11 deletions
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index ecd44fddfd..92c7b8ac14 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -210,6 +210,8 @@ public: virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0; virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0; + virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name)=0; + /* COMMON MATERIAL API */ virtual RID material_create()=0; @@ -701,6 +703,7 @@ public: Matrix32 final_transform; Rect2 final_clip_rect; CanvasItem* final_clip_owner; + CanvasItem* shader_owner; ViewportRender *vp_render; const Rect2& get_rect() const { @@ -827,8 +830,8 @@ public: return rect; } - void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true; final_clip_owner=NULL; } - CanvasItem() { vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_opacity=1; blend_mode=VS::MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; shader_version=0;} + void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true; final_clip_owner=NULL; shader_owner=NULL;} + CanvasItem() { vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_opacity=1; blend_mode=VS::MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; shader_version=0; shader_owner=NULL;} virtual ~CanvasItem() { clear(); } }; @@ -849,6 +852,7 @@ public: virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width)=0; virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor)=0; virtual void canvas_set_transform(const Matrix32& p_transform)=0; + virtual void canvas_render_items(CanvasItem *p_item_list)=0; diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index 1275b2308c..6c1b6697c1 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -231,6 +231,11 @@ RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const String return RID(); } +Variant RasterizerDummy::shader_get_default_param(RID p_shader, const StringName& p_name) { + + return Variant(); +} + /* COMMON MATERIAL API */ diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index 2944bbbaf1..c72149f88f 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -433,6 +433,8 @@ public: virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture); virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const; + virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name); + /* COMMON MATERIAL API */ virtual RID material_create(); @@ -707,6 +709,7 @@ public: virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width); virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor); virtual void canvas_set_transform(const Matrix32& p_transform); + virtual void canvas_render_items(CanvasItem *p_item_list); /* ENVIRONMENT */ diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 1b076176f4..f5bff29f47 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -1120,18 +1120,19 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={ //builtins { "WORLD_MATRIX", TYPE_MAT4}, { "PROJECTION_MATRIX", TYPE_MAT4}, - { "EXTRA_MATRIX", TYPE_MAT4}, - { "MODELVIEW_MATRIX", TYPE_MAT4}, + { "EXTRA_MATRIX", TYPE_MAT4}, { "TIME", TYPE_FLOAT}, { NULL, TYPE_VOID}, }; const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={ + { "SRC_COLOR", TYPE_VEC4}, { "POSITION", TYPE_VEC4}, { "NORMAL", TYPE_VEC3}, { "UV", TYPE_VEC2}, { "COLOR", TYPE_VEC4}, { "TEXTURE", TYPE_TEXTURE}, + { "TEXTURE_PIXEL_SIZE", TYPE_VEC2}, { "VAR1", TYPE_VEC4}, { "VAR2", TYPE_VEC4}, { "SCREEN_UV", TYPE_VEC2}, diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 7e915be3d5..dfa1e849b7 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3699,6 +3699,15 @@ void VisualServerRaster::canvas_item_set_z(RID p_item, int p_z) { } +void VisualServerRaster::canvas_item_set_use_parent_shader(RID p_item, bool p_enable) { + + VS_CHANGED; + CanvasItem *canvas_item = canvas_item_owner.get( p_item ); + ERR_FAIL_COND(!canvas_item); + canvas_item->use_parent_shader=p_enable; + +} + void VisualServerRaster::canvas_item_set_shader(RID p_item, RID p_shader) { VS_CHANGED; @@ -3730,7 +3739,10 @@ Variant VisualServerRaster::canvas_item_get_shader_param(RID p_canvas_item, cons CanvasItem *canvas_item = canvas_item_owner.get( p_canvas_item ); ERR_FAIL_COND_V(!canvas_item,Variant()); - ERR_FAIL_COND_V(!canvas_item->shader_param.has(p_param),Variant()); + if (!canvas_item->shader_param.has(p_param)) { + ERR_FAIL_COND_V(!canvas_item->shader.is_valid(),Variant()); + return rasterizer->shader_get_default_param(canvas_item->shader,p_param); + } return canvas_item->shader_param[p_param]; } @@ -6136,7 +6148,7 @@ void VisualServerRaster::_render_canvas_item_tree(CanvasItem *p_canvas_item,cons } - _render_canvas_item(p_canvas_item,p_transform,p_clip_rect,1.0,z_list,z_last_list,NULL); + _render_canvas_item(p_canvas_item,p_transform,p_clip_rect,1.0,z_list,z_last_list,NULL,NULL); for(int i=0;i<CANVAS_ITEM_Z_MAX;i++) { if (!z_list[i]) @@ -6153,9 +6165,10 @@ void VisualServerRaster::_render_canvas_item_viewport(VisualServer* p_self,void Viewport *vp=(Viewport*)p_vp; self->_draw_viewport(vp,p_rect.pos.x,p_rect.pos.y,p_rect.size.x,p_rect.size.y); self->rasterizer->canvas_begin(); + } -void VisualServerRaster::_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 VisualServerRaster::_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) { CanvasItem *ci = p_canvas_item; @@ -6200,6 +6213,12 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat ci->vp_render=NULL; } + if (ci->use_parent_shader && p_shader_owner) + ci->shader_owner=p_shader_owner; + else { + p_shader_owner=ci; + ci->shader_owner=NULL; + } float opacity = ci->opacity * p_opacity; @@ -6228,7 +6247,7 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat if (child_items[i]->ontop) continue; - _render_canvas_item(child_items[i],xform,p_clip_rect,opacity,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner); + _render_canvas_item(child_items[i],xform,p_clip_rect,opacity,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner,p_shader_owner); } @@ -6254,7 +6273,7 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat if (!child_items[i]->ontop) continue; - _render_canvas_item(child_items[i],xform,p_clip_rect,opacity,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner); + _render_canvas_item(child_items[i],xform,p_clip_rect,opacity,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner,p_shader_owner); } } @@ -6263,6 +6282,7 @@ void VisualServerRaster::_render_canvas(Canvas *p_canvas,const Matrix32 &p_trans rasterizer->canvas_begin(); + int l = p_canvas->child_items.size(); for(int i=0;i<l;i++) { @@ -6449,7 +6469,7 @@ void VisualServerRaster::_draw_viewports() { rasterizer->set_viewport(viewport_rect); } - rasterizer->canvas_begin(); + rasterizer->canvas_begin(); rasterizer->canvas_disable_blending(); rasterizer->canvas_begin_rect(Matrix32()); rasterizer->canvas_draw_rect(E->get()->rt_to_screen_rect,0,Rect2(Point2(),E->get()->rt_to_screen_rect.size),E->get()->render_target_texture,Color(1,1,1)); 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<Point2> 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<CanvasItem*> 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<Vector3> _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max); Vector<Plane> _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; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 300aba4551..c344161445 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -1136,6 +1136,9 @@ public: FUNC2(canvas_item_set_shader,RID, RID ); FUNC1RC(RID,canvas_item_get_shader,RID ); + FUNC2(canvas_item_set_use_parent_shader,RID, bool ); + + FUNC3(canvas_item_set_shader_param,RID,const StringName&,const Variant&); FUNC2RC(Variant,canvas_item_get_shader_param,RID,const StringName&); diff --git a/servers/visual_server.h b/servers/visual_server.h index 6f759dcf05..5edf333e65 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -992,6 +992,8 @@ public: virtual void canvas_item_set_shader(RID p_item, RID p_shader)=0; virtual RID canvas_item_get_shader(RID p_item) const=0; + virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable)=0; + virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value)=0; virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const=0; |