diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 5 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 3 | ||||
-rw-r--r-- | scene/resources/material.cpp | 4 | ||||
-rw-r--r-- | scene/resources/material.h | 1 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 12 | ||||
-rw-r--r-- | scene/resources/texture.h | 1 |
6 files changed, 22 insertions, 4 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index a94b2347fc..dea2411f1d 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -447,7 +447,7 @@ float CanvasItem::get_self_opacity() const { void CanvasItem::set_blend_mode(BlendMode p_blend_mode) { - ERR_FAIL_INDEX(p_blend_mode,4); + ERR_FAIL_INDEX(p_blend_mode,5); blend_mode=p_blend_mode; VisualServer::get_singleton()->canvas_item_set_blend_mode(canvas_item,VS::MaterialBlendMode(blend_mode)); @@ -794,7 +794,7 @@ void CanvasItem::_bind_methods() { ADD_PROPERTY( 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"), _SCS("set_blend_mode"),_SCS("get_blend_mode") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") ); //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")); @@ -810,6 +810,7 @@ void CanvasItem::_bind_methods() { BIND_CONSTANT( BLEND_MODE_ADD ); BIND_CONSTANT( BLEND_MODE_SUB ); BIND_CONSTANT( BLEND_MODE_MUL ); + BIND_CONSTANT( BLEND_MODE_PREMULT_ALPHA ); BIND_CONSTANT( NOTIFICATION_DRAW); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 1c104c5fc2..604eef0527 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -49,7 +49,8 @@ public: BLEND_MODE_MIX, //default BLEND_MODE_ADD, BLEND_MODE_SUB, - BLEND_MODE_MUL + BLEND_MODE_MUL, + BLEND_MODE_PREMULT_ALPHA }; private: diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 637a816112..2ddfa1078b 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -158,7 +158,7 @@ void Material::_bind_methods() { for(int i=0;i<HINT_MAX;i++) ADD_PROPERTYI( PropertyInfo( Variant::BOOL, String()+"hints/"+_hint_names[i] ),_SCS("set_hint"),_SCS("get_hint"),_hint_indices[i]); - ADD_PROPERTY( PropertyInfo( Variant::INT, "params/blend_mode",PROPERTY_HINT_ENUM,"Mix,Add,Sub" ), _SCS("set_blend_mode"),_SCS("get_blend_mode")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "params/blend_mode",PROPERTY_HINT_ENUM,"Mix,Add,Sub,PMAlpha" ), _SCS("set_blend_mode"),_SCS("get_blend_mode")); ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/line_width",PROPERTY_HINT_RANGE,"0.1,32.0,0.1" ), _SCS("set_line_width"),_SCS("get_line_width")); @@ -189,6 +189,8 @@ void Material::_bind_methods() { BIND_CONSTANT( BLEND_MODE_MIX ); BIND_CONSTANT( BLEND_MODE_ADD ); BIND_CONSTANT( BLEND_MODE_SUB ); + BIND_CONSTANT( BLEND_MODE_MUL ); + BIND_CONSTANT( BLEND_MODE_PREMULT_ALPHA ); } diff --git a/scene/resources/material.h b/scene/resources/material.h index 7bd8b70fa4..1f2afb70b9 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -75,6 +75,7 @@ public: BLEND_MODE_MUL = VS::MATERIAL_BLEND_MODE_MUL, BLEND_MODE_ADD = VS::MATERIAL_BLEND_MODE_ADD, BLEND_MODE_SUB = VS::MATERIAL_BLEND_MODE_SUB, + BLEND_MODE_PREMULT_ALPHA = VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA, }; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index baf6fa9d8d..5402a28d92 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -302,6 +302,16 @@ void ImageTexture::fix_alpha_edges() { } } +void ImageTexture::premultiply_alpha() { + + if (format==Image::FORMAT_RGBA /*&& !(flags&FLAG_CUBEMAP)*/) { + + Image img = get_data(); + img.premultiply_alpha(); + set_data(img); + } +} + bool ImageTexture::has_alpha() const { return ( format==Image::FORMAT_GRAYSCALE_ALPHA || format==Image::FORMAT_INDEXED_ALPHA || format==Image::FORMAT_RGBA ); @@ -386,8 +396,10 @@ void ImageTexture::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_lossy_storage_quality","quality"),&ImageTexture::set_lossy_storage_quality); ObjectTypeDB::bind_method(_MD("get_lossy_storage_quality"),&ImageTexture::get_lossy_storage_quality); ObjectTypeDB::bind_method(_MD("fix_alpha_edges"),&ImageTexture::fix_alpha_edges); + ObjectTypeDB::bind_method(_MD("premultiply_alpha"),&ImageTexture::premultiply_alpha); ObjectTypeDB::bind_method(_MD("set_size_override","size"),&ImageTexture::set_size_override); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("fix_alpha_edges"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::set_method_flags(get_type_static(),_SCS("premultiply_alpha"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::bind_method(_MD("_reload_hook","rid"),&ImageTexture::_reload_hook); diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 6259362882..b780d70e1a 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -143,6 +143,7 @@ public: float get_lossy_storage_quality() const; void fix_alpha_edges(); + void premultiply_alpha(); void set_size_override(const Size2& p_size); |