diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/material.cpp | 6 | ||||
-rw-r--r-- | scene/resources/material.h | 3 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 6 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 69 | ||||
-rw-r--r-- | scene/resources/texture.h | 27 |
5 files changed, 107 insertions, 4 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 79f642a09b..15710f4c14 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -689,6 +689,10 @@ void SpatialMaterial::_update_shader() { } } + if (flags[FLAG_ALBEDO_TEXTURE_FORCE_SRGB]) { + code += "\talbedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045)));\n"; + } + if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) { code += "\talbedo_tex *= COLOR;\n"; } @@ -1833,6 +1837,7 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_use_point_size"), "set_flag", "get_flag", FLAG_USE_POINT_SIZE); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_world_triplanar"), "set_flag", "get_flag", FLAG_TRIPLANAR_USE_WORLD); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_fixed_size"), "set_flag", "get_flag", FLAG_FIXED_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_albedo_tex_force_srgb"), "set_flag", "get_flag", FLAG_ALBEDO_TEXTURE_FORCE_SRGB); ADD_GROUP("Vertex Color", "vertex_color"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_use_as_albedo"), "set_flag", "get_flag", FLAG_ALBEDO_FROM_VERTEX_COLOR); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_is_srgb"), "set_flag", "get_flag", FLAG_SRGB_VERTEX_COLOR); @@ -2019,6 +2024,7 @@ void SpatialMaterial::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_AO_ON_UV2); BIND_ENUM_CONSTANT(FLAG_USE_ALPHA_SCISSOR); BIND_ENUM_CONSTANT(FLAG_TRIPLANAR_USE_WORLD); + BIND_ENUM_CONSTANT(FLAG_ALBEDO_TEXTURE_FORCE_SRGB); BIND_ENUM_CONSTANT(FLAG_MAX); BIND_ENUM_CONSTANT(DIFFUSE_BURLEY); diff --git a/scene/resources/material.h b/scene/resources/material.h index 877d4dfd41..374ec853dc 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -181,6 +181,7 @@ public: FLAG_TRIPLANAR_USE_WORLD, FLAG_AO_ON_UV2, FLAG_USE_ALPHA_SCISSOR, + FLAG_ALBEDO_TEXTURE_FORCE_SRGB, FLAG_MAX }; @@ -229,7 +230,7 @@ private: uint64_t blend_mode : 2; uint64_t depth_draw_mode : 2; uint64_t cull_mode : 2; - uint64_t flags : 12; + uint64_t flags : 13; uint64_t detail_blend_mode : 2; uint64_t diffuse_mode : 3; uint64_t specular_mode : 2; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 5d6f44dfef..06829089be 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -232,11 +232,11 @@ Node *SceneState::instance(GenEditState p_edit_state) const { Node *base = i == 0 ? node : ret_nodes[0]; if (p_edit_state == GEN_EDIT_STATE_MAIN) { - - res->local_scene = base; - resources_local_to_scene[res] = res; + //for the main scene, use the resource as is + res->configure_for_local_scene(base, resources_local_to_scene); } else { + //for instances, a copy must be made Node *base = i == 0 ? node : ret_nodes[0]; Ref<Resource> local_dupe = res->duplicate_for_local_scene(base, resources_local_to_scene); resources_local_to_scene[res] = local_dupe; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 162edd0d1c..987d6c5f6a 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1601,3 +1601,72 @@ int GradientTexture::get_width() const { Ref<Image> GradientTexture::get_data() const { return VisualServer::get_singleton()->texture_get_data(texture); } + +////////////////////////////////////// + +void ProxyTexture::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_base", "base"), &ProxyTexture::set_base); + ClassDB::bind_method(D_METHOD("get_base"), &ProxyTexture::get_base); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "base", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_base", "get_base"); +} + +void ProxyTexture::set_base(const Ref<Texture> &p_texture) { + + base = p_texture; + if (base.is_valid()) { + VS::get_singleton()->texture_set_proxy(proxy, base->get_rid()); + } else { + VS::get_singleton()->texture_set_proxy(proxy, RID()); + } +} + +Ref<Texture> ProxyTexture::get_base() const { + + return base; +} + +int ProxyTexture::get_width() const { + + if (base.is_valid()) + return base->get_width(); + return 1; +} +int ProxyTexture::get_height() const { + + if (base.is_valid()) + return base->get_height(); + return 1; +} +RID ProxyTexture::get_rid() const { + + return proxy; +} + +bool ProxyTexture::has_alpha() const { + + if (base.is_valid()) + return base->has_alpha(); + return false; +} + +void ProxyTexture::set_flags(uint32_t p_flags) { +} + +uint32_t ProxyTexture::get_flags() const { + + if (base.is_valid()) + return base->get_flags(); + return 0; +} + +ProxyTexture::ProxyTexture() { + + proxy = VS::get_singleton()->texture_create(); +} + +ProxyTexture::~ProxyTexture() { + + VS::get_singleton()->free(proxy); +} diff --git a/scene/resources/texture.h b/scene/resources/texture.h index ee54156647..76c0195ef9 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -493,4 +493,31 @@ public: virtual ~GradientTexture(); }; +class ProxyTexture : public Texture { + GDCLASS(ProxyTexture, Texture) + +private: + RID proxy; + Ref<Texture> base; + +protected: + static void _bind_methods(); + +public: + void set_base(const Ref<Texture> &p_texture); + Ref<Texture> get_base() const; + + virtual int get_width() const; + virtual int get_height() const; + virtual RID get_rid() const; + + virtual bool has_alpha() const; + + virtual void set_flags(uint32_t p_flags); + virtual uint32_t get_flags() const; + + ProxyTexture(); + ~ProxyTexture(); +}; + #endif |