diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/material.cpp | 141 | ||||
-rw-r--r-- | scene/resources/material.h | 62 | ||||
-rw-r--r-- | scene/resources/shader.cpp | 2 | ||||
-rw-r--r-- | scene/resources/shader.h | 19 |
4 files changed, 41 insertions, 183 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index faba339fe1..355cc8884c 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -467,10 +467,20 @@ bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) { return true; } else { - String n = p_name; - if (n.begins_with("param/")) { - VisualServer::get_singleton()->material_set_param(material,String(n.ptr()+6),p_value); - return true; + if (shader.is_valid()) { + + + StringName pr = shader->remap_param(p_name); + if (!pr) { + String n = p_name; + if (n.find("param/")==0) { //backwards compatibility + pr = n.substr(6,n.length()); + } + } + if (pr) { + VisualServer::get_singleton()->material_set_param(material,pr,p_value); + return true; + } } } @@ -486,10 +496,13 @@ bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const { return true; } else { - String n = p_name; - if (n.begins_with("param/")) { - r_ret=VisualServer::get_singleton()->material_get_param(material,String(n.ptr()+6)); - return true; + if (shader.is_valid()) { + + StringName pr = shader->remap_param(p_name); + if (pr) { + r_ret=VisualServer::get_singleton()->material_get_param(material,pr); + return true; + } } } @@ -583,115 +596,3 @@ ShaderMaterial::ShaderMaterial() :Material(VisualServer::get_singleton()->materi ///////////////////////////////// - -void ParticleSystemMaterial::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_texture","texture"),&ParticleSystemMaterial::set_texture); - ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&ParticleSystemMaterial::get_texture); - - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture" ), _SCS("set_texture"), _SCS("get_texture")); - -} - -void ParticleSystemMaterial::set_texture(const Ref<Texture>& p_texture) { - texture=p_texture; - RID rid; - if (texture.is_valid()) - rid=texture->get_rid(); - - VS::get_singleton()->fixed_material_set_texture(material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,rid); -} - -Ref<Texture> ParticleSystemMaterial::get_texture() const { - - return texture; -} - - -ParticleSystemMaterial::ParticleSystemMaterial() :Material(VisualServer::get_singleton()->fixed_material_create()){ - - set_flag(FLAG_DOUBLE_SIDED,true); - set_flag(FLAG_UNSHADED,true); - set_depth_draw_mode(DEPTH_DRAW_NEVER); - VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,true); - VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); - set_flag(FLAG_COLOR_ARRAY_SRGB,true); - -} - -ParticleSystemMaterial::~ParticleSystemMaterial() { - - -} - -////////////////////////////// - - - -void UnshadedMaterial::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_texture","texture"),&UnshadedMaterial::set_texture); - ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&UnshadedMaterial::get_texture); - - ObjectTypeDB::bind_method(_MD("set_use_alpha","enable"),&UnshadedMaterial::set_use_alpha); - ObjectTypeDB::bind_method(_MD("is_using_alpha"),&UnshadedMaterial::is_using_alpha); - - ObjectTypeDB::bind_method(_MD("set_use_color_array","enable"),&UnshadedMaterial::set_use_color_array); - ObjectTypeDB::bind_method(_MD("is_using_color_array"),&UnshadedMaterial::is_using_color_array); - - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture" ), _SCS("set_texture"), _SCS("get_texture")); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "alpha" ), _SCS("set_use_alpha"), _SCS("is_using_alpha")); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "color_array" ), _SCS("set_use_color_array"), _SCS("is_using_color_array")); - -} - -void UnshadedMaterial::set_texture(const Ref<Texture>& p_texture) { - RID rid; - if (texture.is_valid()) - rid=texture->get_rid(); - - VS::get_singleton()->fixed_material_set_texture(material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,rid); -} -Ref<Texture> UnshadedMaterial::get_texture() const { - - return texture; -} - -void UnshadedMaterial::set_use_alpha(bool p_use_alpha) { - - alpha=p_use_alpha; - VS::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,p_use_alpha); - //set_depth_draw_mode(); - //set_hint(HINT,p_use_alpha); - -} - -bool UnshadedMaterial::is_using_alpha() const{ - - return alpha; -} - -void UnshadedMaterial::set_use_color_array(bool p_use_color_array){ - - color_array=p_use_color_array; - VS::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,p_use_color_array); - -} - -bool UnshadedMaterial::is_using_color_array() const{ - - return color_array; -} - -UnshadedMaterial::UnshadedMaterial() :Material(VisualServer::get_singleton()->fixed_material_create()){ - - set_flag(FLAG_UNSHADED,true); - set_use_alpha(true); - set_flag(FLAG_COLOR_ARRAY_SRGB,true); - -} - -UnshadedMaterial::~UnshadedMaterial() { - - -} diff --git a/scene/resources/material.h b/scene/resources/material.h index 2b10078e16..73d1a4e188 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -253,68 +253,6 @@ public: -class ParticleSystemMaterial : public Material { - - OBJ_TYPE( ParticleSystemMaterial, Material ); - REVERSE_GET_PROPERTY_LIST - -private: - - - - Ref<Texture> texture; - -protected: - - - static void _bind_methods(); - -public: - - void set_texture(const Ref<Texture>& p_texture); - Ref<Texture> get_texture() const; - - - ParticleSystemMaterial(); - ~ParticleSystemMaterial(); - -}; - -/////////////////////////////////////////// - - -class UnshadedMaterial : public Material { - - OBJ_TYPE( UnshadedMaterial, Material ); - REVERSE_GET_PROPERTY_LIST - -private: - - - bool alpha; - bool color_array; - Ref<Texture> texture; - -protected: - - - static void _bind_methods(); - -public: - - void set_texture(const Ref<Texture>& p_texture); - Ref<Texture> get_texture() const; - - void set_use_alpha(bool p_use_alpha); - bool is_using_alpha() const; - - void set_use_color_array(bool p_use_color_array); - bool is_using_color_array() const; - - UnshadedMaterial(); - ~UnshadedMaterial(); - -}; #endif diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index f3e625917a..42251124bd 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -84,7 +84,7 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { for(List<PropertyInfo>::Element *E=local.front();E;E=E->next()) { PropertyInfo pi=E->get(); - pi.name="param/"+pi.name; + pi.name="shader_param/"+pi.name; params_cache[pi.name]=E->get().name; if (p_params) { diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 8c15ca43d4..4a380d455b 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -80,6 +80,16 @@ public: Ref<Texture> get_default_texture_param(const StringName& p_param) const; void get_default_texture_param_list(List<StringName>* r_textures) const; + _FORCE_INLINE_ StringName remap_param(const StringName& p_param) const { + if (params_cache_dirty) + get_param_list(NULL); + + const Map<StringName,StringName>::Element *E=params_cache.find(p_param); + if (E) + return E->get(); + return StringName(); + } + virtual RID get_rid() const; Shader(Mode p_mode); @@ -98,6 +108,15 @@ public: MaterialShader() : Shader(MODE_MATERIAL) {}; }; +class CanvasItemShader : public Shader { + + OBJ_TYPE(CanvasItemShader,Shader); + +public: + + CanvasItemShader() : Shader(MODE_CANVAS_ITEM) {}; +}; + class ResourceFormatLoaderShader : public ResourceFormatLoader { |