summaryrefslogtreecommitdiff
path: root/servers/visual
diff options
context:
space:
mode:
Diffstat (limited to 'servers/visual')
-rw-r--r--servers/visual/rasterizer.h7
-rw-r--r--servers/visual/shader_language.cpp97
-rw-r--r--servers/visual/shader_language.h9
-rw-r--r--servers/visual/visual_server_raster.cpp36
-rw-r--r--servers/visual/visual_server_raster.h5
-rw-r--r--servers/visual/visual_server_wrap_mt.h5
6 files changed, 157 insertions, 2 deletions
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 2d6298cc99..ecd44fddfd 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -692,6 +692,9 @@ public:
mutable bool rect_dirty;
mutable Rect2 rect;
CanvasItem*next;
+ RID shader;
+ Map<StringName,Variant> shader_param;
+ uint32_t shader_version;
float final_opacity;
@@ -824,8 +827,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; }
+ 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;}
virtual ~CanvasItem() { clear(); }
};
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index f2348bf59f..1b076176f4 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -1105,6 +1105,60 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::light_builtins_defs[]={
};
+
+
+const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={
+
+ { "SRC_VERTEX", TYPE_VEC2},
+ { "VERTEX", TYPE_VEC2},
+ { "UV", TYPE_VEC2},
+ { "COLOR", TYPE_VEC4},
+ { "VAR1", TYPE_VEC4},
+ { "VAR2", TYPE_VEC4},
+ { "POINT_SIZE", TYPE_FLOAT},
+
+ //builtins
+ { "WORLD_MATRIX", TYPE_MAT4},
+ { "PROJECTION_MATRIX", TYPE_MAT4},
+ { "EXTRA_MATRIX", TYPE_MAT4},
+ { "MODELVIEW_MATRIX", TYPE_MAT4},
+ { "TIME", TYPE_FLOAT},
+ { NULL, TYPE_VOID},
+};
+const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={
+
+ { "POSITION", TYPE_VEC4},
+ { "NORMAL", TYPE_VEC3},
+ { "UV", TYPE_VEC2},
+ { "COLOR", TYPE_VEC4},
+ { "TEXTURE", TYPE_TEXTURE},
+ { "VAR1", TYPE_VEC4},
+ { "VAR2", TYPE_VEC4},
+ { "SCREEN_UV", TYPE_VEC2},
+ { "POINT_COORD", TYPE_VEC2},
+
+// { "SCREEN_POS", TYPE_VEC2},
+// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
+ { "TIME", TYPE_FLOAT},
+ { NULL, TYPE_VOID}
+
+};
+
+const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={
+
+ { "COLOR", TYPE_VEC4},
+ { "NORMAL", TYPE_VEC3},
+ { "LIGHT_DIR", TYPE_VEC2},
+ { "LIGHT_DISTANCE", TYPE_FLOAT},
+ { "LIGHT", TYPE_VEC3},
+ { "POINT_COORD", TYPE_VEC2},
+// { "SCREEN_POS", TYPE_VEC2},
+// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
+ { "TIME", TYPE_FLOAT},
+ { NULL, TYPE_VOID}
+
+};
+
const ShaderLanguage::BuiltinsDef ShaderLanguage::postprocess_fragment_builtins_defs[]={
{ "IN_COLOR", TYPE_VEC3},
@@ -2471,6 +2525,27 @@ Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,Comp
idx++;
}
} break;
+ case SHADER_CANVAS_ITEM_VERTEX: {
+ int idx=0;
+ while (ci_vertex_builtins_defs[idx].name) {
+ parser.program->builtin_variables[ci_vertex_builtins_defs[idx].name]=ci_vertex_builtins_defs[idx].type;
+ idx++;
+ }
+ } break;
+ case SHADER_CANVAS_ITEM_FRAGMENT: {
+ int idx=0;
+ while (ci_fragment_builtins_defs[idx].name) {
+ parser.program->builtin_variables[ci_fragment_builtins_defs[idx].name]=ci_fragment_builtins_defs[idx].type;
+ idx++;
+ }
+ } break;
+ case SHADER_CANVAS_ITEM_LIGHT: {
+ int idx=0;
+ while (ci_light_builtins_defs[idx].name) {
+ parser.program->builtin_variables[ci_light_builtins_defs[idx].name]=ci_light_builtins_defs[idx].type;
+ idx++;
+ }
+ } break;
case SHADER_POST_PROCESS: {
int idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {
@@ -2568,6 +2643,28 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
idx++;
}
} break;
+ case SHADER_CANVAS_ITEM_VERTEX: {
+ idx=0;
+ while (ci_vertex_builtins_defs[idx].name) {
+ p_keywords->push_back(ci_vertex_builtins_defs[idx].name);
+ idx++;
+ }
+ } break;
+ case SHADER_CANVAS_ITEM_FRAGMENT: {
+ idx=0;
+ while (ci_fragment_builtins_defs[idx].name) {
+ p_keywords->push_back(ci_fragment_builtins_defs[idx].name);
+ idx++;
+ }
+ } break;
+ case SHADER_CANVAS_ITEM_LIGHT: {
+ idx=0;
+ while (ci_light_builtins_defs[idx].name) {
+ p_keywords->push_back(ci_light_builtins_defs[idx].name);
+ idx++;
+ }
+ } break;
+
case SHADER_POST_PROCESS: {
idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h
index 7e01368dd5..f79c219d85 100644
--- a/servers/visual/shader_language.h
+++ b/servers/visual/shader_language.h
@@ -105,6 +105,9 @@ public:
SHADER_MATERIAL_VERTEX,
SHADER_MATERIAL_FRAGMENT,
SHADER_MATERIAL_LIGHT,
+ SHADER_CANVAS_ITEM_VERTEX,
+ SHADER_CANVAS_ITEM_FRAGMENT,
+ SHADER_CANVAS_ITEM_LIGHT,
SHADER_POST_PROCESS,
};
@@ -376,6 +379,12 @@ private:
static const BuiltinsDef vertex_builtins_defs[];
static const BuiltinsDef fragment_builtins_defs[];
static const BuiltinsDef light_builtins_defs[];
+
+ static const BuiltinsDef ci_vertex_builtins_defs[];
+ static const BuiltinsDef ci_fragment_builtins_defs[];
+ static const BuiltinsDef ci_light_builtins_defs[];
+
+
static const BuiltinsDef postprocess_fragment_builtins_defs[];
static DataType get_token_datatype(TokenType p_type);
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 78094ee2aa..7e915be3d5 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -3699,6 +3699,42 @@ void VisualServerRaster::canvas_item_set_z(RID p_item, int p_z) {
}
+void VisualServerRaster::canvas_item_set_shader(RID p_item, RID p_shader) {
+
+ VS_CHANGED;
+ CanvasItem *canvas_item = canvas_item_owner.get( p_item );
+ ERR_FAIL_COND(!canvas_item);
+ canvas_item->shader=p_shader;
+}
+
+RID VisualServerRaster::canvas_item_get_shader(RID p_item) const{
+
+ CanvasItem *canvas_item = canvas_item_owner.get( p_item );
+ ERR_FAIL_COND_V(!canvas_item,RID());
+ return canvas_item->shader;
+
+}
+
+void VisualServerRaster::canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value){
+
+ VS_CHANGED;
+ CanvasItem *canvas_item = canvas_item_owner.get( p_canvas_item );
+ ERR_FAIL_COND(!canvas_item);
+ if (p_value.get_type()==Variant::NIL)
+ canvas_item->shader_param.erase(p_param);
+ else
+ canvas_item->shader_param[p_param]=p_value;
+
+}
+Variant VisualServerRaster::canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const{
+
+ 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());
+
+ return canvas_item->shader_param[p_param];
+}
+
void VisualServerRaster::canvas_item_set_sort_children_by_y(RID p_item, bool p_enable) {
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);
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 0aa992564f..300aba4551 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -1133,6 +1133,11 @@ public:
FUNC2(canvas_item_set_sort_children_by_y,RID,bool);
FUNC2(canvas_item_set_z,RID,int);
+ FUNC2(canvas_item_set_shader,RID, RID );
+ FUNC1RC(RID,canvas_item_get_shader,RID );
+
+ FUNC3(canvas_item_set_shader_param,RID,const StringName&,const Variant&);
+ FUNC2RC(Variant,canvas_item_get_shader_param,RID,const StringName&);
FUNC1(canvas_item_clear,RID);
FUNC1(canvas_item_raise,RID);