summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp75
-rw-r--r--drivers/gles2/rasterizer_gles2.h11
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp54
-rw-r--r--drivers/gles2/shader_compiler_gles2.h3
-rw-r--r--drivers/gles2/shaders/canvas.glsl5
-rw-r--r--scene/2d/canvas_item.cpp17
-rw-r--r--scene/2d/canvas_item.h4
-rw-r--r--scene/gui/grid_container.cpp1
-rw-r--r--servers/visual/rasterizer.h8
-rw-r--r--servers/visual/rasterizer_dummy.cpp5
-rw-r--r--servers/visual/rasterizer_dummy.h3
-rw-r--r--servers/visual/shader_language.cpp5
-rw-r--r--servers/visual/visual_server_raster.cpp32
-rw-r--r--servers/visual/visual_server_raster.h8
-rw-r--r--servers/visual/visual_server_wrap_mt.h3
-rw-r--r--servers/visual_server.h2
16 files changed, 195 insertions, 41 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 2d60f0e928..44fb210526 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -1564,6 +1564,7 @@ void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const Strin
RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
const Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader,RID());
const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
if (!E)
@@ -1571,6 +1572,22 @@ RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const String
return E->get();
}
+Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName& p_name) {
+
+ Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader,Variant());
+
+ //update shader params if necesary
+ //make sure the shader is compiled and everything
+ //so the actual parameters can be properly retrieved!
+ if (shader->dirty_list.in_list()) {
+ _update_shader(shader);
+ }
+ if (shader->valid && shader->uniforms.has(p_name))
+ return shader->uniforms[p_name].default_value;
+
+ return Variant();
+}
/* COMMON MATERIAL API */
@@ -4567,6 +4584,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
if (fragment_flags.uses_screen_uv) {
enablers.push_back("#define ENABLE_SCREEN_UV\n");
}
+ if (fragment_flags.uses_texpixel_size) {
+ enablers.push_back("#define USE_TEXPIXEL_SIZE\n");
+ }
canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
@@ -4582,6 +4602,7 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
p_shader->can_zpass=!fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex;
p_shader->uses_normal=fragment_flags.uses_normal || light_flags.uses_normal;
p_shader->uses_time=uses_time;
+ p_shader->uses_texpixel_size=fragment_flags.uses_texpixel_size;
p_shader->version++;
}
@@ -4940,7 +4961,7 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
keep=false;
else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
//type changed between old and new
- /*if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
+ /* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
keep=false;
} else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type())
@@ -7778,7 +7799,7 @@ void RasterizerGLES2::canvas_begin() {
canvas_shader.bind();
canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0);
_set_color_attrib(Color(1,1,1));
- Transform canvas_transform;
+ canvas_transform=Transform();
canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
float csy = 1.0;
if (current_rt && current_rt_vflip)
@@ -7792,6 +7813,9 @@ void RasterizerGLES2::canvas_begin() {
canvas_opacity=1.0;
canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
+ canvas_texscreen_used=false;
+ uses_texpixel_size=false;
+ canvas_last_shader=RID();
}
@@ -7874,7 +7898,7 @@ void RasterizerGLES2::canvas_end_rect() {
RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_texture) {
- if (p_texture==canvas_tex) {
+ if (p_texture==canvas_tex && !rebind_texpixel_size) {
if (canvas_tex.is_valid()) {
Texture*texture=texture_owner.get(p_texture);
return texture;
@@ -7882,14 +7906,16 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
return NULL;
}
-
+ rebind_texpixel_size=false;
if (p_texture.is_valid()) {
+
Texture*texture=texture_owner.get(p_texture);
if (!texture) {
canvas_tex=RID();
glBindTexture(GL_TEXTURE_2D,white_tex);
+
return NULL;
}
@@ -7898,6 +7924,9 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
glBindTexture(GL_TEXTURE_2D,texture->tex_id);
canvas_tex=p_texture;
+ if (uses_texpixel_size) {
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXPIXEL_SIZE,Size2(1.0/texture->width,1.0/texture->height));
+ }
return texture;
@@ -8268,24 +8297,13 @@ void RasterizerGLES2::canvas_set_transform(const Matrix32& p_transform) {
//canvas_transform = Variant(p_transform);
}
+
void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
CanvasItem *current_clip=NULL;
- RID last_shader;
-
- Transform canvas_transform;
- canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
- float csy = 1.0;
- if (current_rt && current_rt_vflip)
- csy = -1.0;
-
- canvas_transform.scale( Vector3( 2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f ) );
-
-
- canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
- canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32());
+ canvas_opacity=1.0;
while(p_item_list) {
CanvasItem *ci=p_item_list;
@@ -8296,7 +8314,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
}
memdelete(ci->vp_render);
ci->vp_render=NULL;
- last_shader=RID();
+ canvas_last_shader=RID();
}
if (current_clip!=ci->final_clip_owner) {
@@ -8317,12 +8335,13 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
//begin rect
+ CanvasItem *shader_owner = ci->shader_owner?ci->shader_owner:ci;
- if (ci->shader!=last_shader) {
+ if (shader_owner->shader!=canvas_last_shader) {
Shader *shader = NULL;
- if (ci->shader.is_valid()) {
- shader = shader_owner.get(ci->shader);
+ if (shader_owner->shader.is_valid()) {
+ shader = this->shader_owner.get(shader_owner->shader);
if (shader && !shader->valid) {
shader=NULL;
}
@@ -8330,11 +8349,12 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
if (shader) {
canvas_shader.set_custom_shader(shader->custom_code_id);
- canvas_shader.bind();
+ if (canvas_shader.bind())
+ rebind_texpixel_size=true;
- if (ci->shader_version!=shader->version) {
+ if (shader_owner->shader_version!=shader->version) {
//todo optimize uniforms
- ci->shader_version=shader->version;
+ shader_owner->shader_version=shader->version;
}
//this can be optimized..
int tex_id=1;
@@ -8342,7 +8362,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
- Map<StringName,Variant>::Element *F=ci->shader_param.find(E->key());
+ Map<StringName,Variant>::Element *F=shader_owner->shader_param.find(E->key());
Variant &v=F?F->get():E->get().default_value;
if (v.get_type()==Variant::_RID || v.get_type()==Variant::OBJECT) {
int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
@@ -8383,14 +8403,17 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
}
//if uses TIME - draw_next_frame=true
+ uses_texpixel_size=shader->uses_texpixel_size;
+
} else {
canvas_shader.set_custom_shader(0);
canvas_shader.bind();
+ uses_texpixel_size=false;
}
canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
- last_shader=ci->shader;
+ canvas_last_shader=shader_owner->shader;
}
canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index f0dae00b53..0f77d18dee 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -192,6 +192,7 @@ class RasterizerGLES2 : public Rasterizer {
bool uses_discard;
bool uses_time;
bool uses_normal;
+ bool uses_texpixel_size;
Map<StringName,ShaderLanguage::Uniform> uniforms;
StringName first_texture;
@@ -1171,6 +1172,13 @@ class RasterizerGLES2 : public Rasterizer {
GLuint white_tex;
RID canvas_tex;
float canvas_opacity;
+ bool uses_texpixel_size;
+ bool rebind_texpixel_size;
+ Transform canvas_transform;
+ RID canvas_last_shader;
+ bool canvas_texscreen_used;
+
+
_FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
VS::MaterialBlendMode canvas_blend_mode;
@@ -1262,6 +1270,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();
@@ -1537,6 +1547,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/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index 163d146009..93b0ecc61f 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -147,6 +147,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
} break;
case SL::Node::TYPE_VARIABLE: {
SL::VariableNode *vnode=(SL::VariableNode*)p_node;
+
if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX) {
if (vnode->name==vname_vertex && p_assign_left) {
@@ -173,6 +174,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
}
+
+
+
if (type==ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
if (vnode->name==vname_discard) {
@@ -181,9 +185,6 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
if (vnode->name==vname_normalmap) {
uses_normalmap=true;
}
- if (vnode->name==vname_normal) {
- uses_normal=true;
- }
if (vnode->name==vname_screen_uv) {
uses_screen_uv=true;
}
@@ -217,6 +218,47 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
}
}
+ if (type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
+
+ if (vnode->name==vname_var1_interp) {
+ flags->use_var1_interp=true;
+ }
+ if (vnode->name==vname_var2_interp) {
+ flags->use_var2_interp=true;
+ }
+
+ }
+
+
+ if (type==ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
+
+
+ if (vnode->name==vname_texpixel_size) {
+ uses_texpixel_size=true;
+ }
+ if (vnode->name==vname_normal) {
+ uses_normal=true;
+ }
+
+ if (vnode->name==vname_screen_uv) {
+ uses_screen_uv=true;
+ }
+
+ if (vnode->name==vname_var1_interp) {
+ flags->use_var1_interp=true;
+ }
+ if (vnode->name==vname_var2_interp) {
+ flags->use_var2_interp=true;
+ }
+ }
+
+ if (type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
+
+ if (vnode->name==vname_light) {
+ uses_light=true;
+ }
+
+ }
if (vnode->name==vname_time) {
uses_time=true;
@@ -556,6 +598,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
uses_time=false;
uses_normalmap=false;
uses_normal=false;
+ uses_texpixel_size=false;
vertex_code_writes_vertex=false;
uniforms=r_uniforms;
flags=&r_flags;
@@ -590,6 +633,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
r_flags.uses_time=uses_time;
r_flags.uses_normalmap=uses_normalmap;
r_flags.uses_normal=uses_normalmap;
+ r_flags.uses_texpixel_size=uses_texpixel_size;
r_code_line=code;
r_globals_line=global_code;
@@ -742,14 +786,17 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
mode_replace_table[4]["POSITION"]="gl_Position";
mode_replace_table[4]["NORMAL"]="normal";
mode_replace_table[4]["UV"]="uv_interp";
+ mode_replace_table[4]["SRC_COLOR"]="color_interp";
mode_replace_table[4]["COLOR"]="color";
mode_replace_table[4]["TEXTURE"]="texture";
+ mode_replace_table[4]["TEXTURE_PIXEL_SIZE"]="texpixel_size";
mode_replace_table[4]["VAR1"]="var1_interp";
mode_replace_table[4]["VAR2"]="var2_interp";
mode_replace_table[4]["SCREEN_UV"]="screen_uv";
mode_replace_table[4]["POINT_COORD"]="gl_PointCoord";
mode_replace_table[4]["TIME"]="time";
+ mode_replace_table[5]["SRC_COLOR"]="color";
mode_replace_table[5]["COLOR"]="color";
mode_replace_table[5]["NORMAL"]="normal";
mode_replace_table[5]["LIGHT_DIR"]="light_dir";
@@ -781,5 +828,6 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
vname_time="TIME";
vname_normalmap="NORMALMAP";
vname_normal="NORMAL";
+ vname_texpixel_size="TEXTURE_PIXEL_SIZE";
}
diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h
index 47ba4aa474..a10fa6dfe0 100644
--- a/drivers/gles2/shader_compiler_gles2.h
+++ b/drivers/gles2/shader_compiler_gles2.h
@@ -52,6 +52,7 @@ private:
bool uses_screen_uv;
bool uses_normalmap;
bool uses_normal;
+ bool uses_texpixel_size;
bool vertex_code_writes_vertex;
Flags *flags;
@@ -70,6 +71,7 @@ private:
StringName vname_time;
StringName vname_normalmap;
StringName vname_normal;
+ StringName vname_texpixel_size;
Map<StringName,ShaderLanguage::Uniform> *uniforms;
@@ -104,6 +106,7 @@ public:
bool uses_light;
bool uses_time;
bool uses_normal;
+ bool uses_texpixel_size;
};
Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms=NULL);
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl
index 3e7e54e0fe..4ec601f0fc 100644
--- a/drivers/gles2/shaders/canvas.glsl
+++ b/drivers/gles2/shaders/canvas.glsl
@@ -132,6 +132,11 @@ uniform float shadow_attenuation;
#endif
+#if defined(USE_TEXPIXEL_SIZE)
+uniform vec2 texpixel_size;
+#endif
+
+
FRAGMENT_SHADER_GLOBALS
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index c28bf71e04..ae857bbce9 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -746,6 +746,17 @@ void CanvasItem::set_shader(const Ref<Shader>& p_shader) {
_change_notify(); //properties for shader exposed
}
+void CanvasItem::set_use_parent_shader(bool p_use_parent_shader) {
+
+ use_parent_shader=p_use_parent_shader;
+ VS::get_singleton()->canvas_item_set_use_parent_shader(canvas_item,p_use_parent_shader);
+}
+
+bool CanvasItem::get_use_parent_shader() const{
+
+ return use_parent_shader;
+}
+
Ref<Shader> CanvasItem::get_shader() const{
return shader;
@@ -868,17 +879,20 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_shader","shader"),&CanvasItem::set_shader);
ObjectTypeDB::bind_method(_MD("get_shader"),&CanvasItem::get_shader);
+ ObjectTypeDB::bind_method(_MD("set_use_parent_shader","enable"),&CanvasItem::set_use_parent_shader);
+ ObjectTypeDB::bind_method(_MD("get_use_parent_shader"),&CanvasItem::get_use_parent_shader);
BIND_VMETHOD(MethodInfo("_draw"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") );
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") );
//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled"));
@@ -955,6 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
block_transform_notify=false;
// viewport=NULL;
canvas_layer=NULL;
+ use_parent_shader;
global_invalid=true;
C=NULL;
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 7c162d9c81..ed3ade9df2 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -81,6 +81,7 @@ private:
bool block_transform_notify;
bool behind;
+ bool use_parent_shader;
Ref<Shader> shader;
mutable Matrix32 global_transform;
@@ -214,6 +215,9 @@ public:
void set_shader(const Ref<Shader>& p_shader);
Ref<Shader> get_shader() const;
+ void set_use_parent_shader(bool p_use_parent_shader);
+ bool get_use_parent_shader() const;
+
void set_shader_param(const StringName& p_param,const Variant& p_value);
Variant get_shader_param(const StringName& p_param) const;
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index f54345cdb8..582693eb3a 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -226,5 +226,6 @@ Size2 GridContainer::get_minimum_size() const {
GridContainer::GridContainer() {
+ set_stop_mouse(false);
columns=1;
}
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;