diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 2 | ||||
-rw-r--r-- | scene/resources/material.cpp | 75 | ||||
-rw-r--r-- | scene/resources/theme.cpp | 115 | ||||
-rw-r--r-- | scene/resources/theme.h | 72 | ||||
-rw-r--r-- | scene/resources/video_stream.h | 2 |
5 files changed, 172 insertions, 94 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 0dcc184a1d..1a053a18c9 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -432,7 +432,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_font("font", "TextEdit", default_font); - theme->set_color("background_color", "TextEdit", Color(0, 0, 0)); + theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0)); theme->set_color("completion_background_color", "TextEdit", Color(0.17, 0.16, 0.2)); theme->set_color("completion_selected_color", "TextEdit", Color(0.26, 0.26, 0.27)); theme->set_color("completion_existing_color", "TextEdit", Color(0.87, 0.87, 0.87, 0.13)); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 3a15025ce2..b10db9ee61 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -476,7 +476,9 @@ void SpatialMaterial::_update_shader() { code += ";\n"; code += "uniform vec4 albedo : hint_color;\n"; - code += "uniform sampler2D texture_albedo : hint_albedo;\n"; + if (textures[TEXTURE_ALBEDO] != NULL) { + code += "uniform sampler2D texture_albedo : hint_albedo;\n"; + } code += "uniform float specular;\n"; code += "uniform float metallic;\n"; if (grow_enabled) { @@ -496,10 +498,16 @@ void SpatialMaterial::_update_shader() { } code += "uniform float roughness : hint_range(0,1);\n"; code += "uniform float point_size : hint_range(0,128);\n"; - code += "uniform sampler2D texture_metallic : hint_white;\n"; - code += "uniform vec4 metallic_texture_channel;\n"; - code += "uniform sampler2D texture_roughness : hint_white;\n"; - code += "uniform vec4 roughness_texture_channel;\n"; + + if (textures[TEXTURE_METALLIC] != NULL) { + code += "uniform sampler2D texture_metallic : hint_white;\n"; + code += "uniform vec4 metallic_texture_channel;\n"; + } + + if (textures[TEXTURE_ROUGHNESS] != NULL) { + code += "uniform sampler2D texture_roughness : hint_white;\n"; + code += "uniform vec4 roughness_texture_channel;\n"; + } if (billboard_mode == BILLBOARD_PARTICLES) { code += "uniform int particles_anim_h_frames;\n"; code += "uniform int particles_anim_v_frames;\n"; @@ -773,37 +781,51 @@ void SpatialMaterial::_update_shader() { code += "\t}\n"; } - if (flags[FLAG_USE_POINT_SIZE]) { - code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n"; - } else { - if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n"; + if (textures[TEXTURE_ALBEDO] != NULL) { + if (flags[FLAG_USE_POINT_SIZE]) { + code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n"; } else { - code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n"; + } else { + code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n"; + } } - } - 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_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"; + } + } else { + code += "\tvec4 albedo_tex = vec4(1.0, 1.0, 1.0, 1.0);\n"; } if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) { code += "\talbedo_tex *= COLOR;\n"; } - code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n"; - if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n"; + + if (textures[TEXTURE_METALLIC] != NULL) { + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n"; + } else { + code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n"; + } + code += "\tMETALLIC = metallic_tex * metallic;\n"; } else { - code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n"; + code += "\tMETALLIC = metallic;\n"; } - code += "\tMETALLIC = metallic_tex * metallic;\n"; - if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n"; + + if (textures[TEXTURE_ROUGHNESS] != NULL) { + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n"; + } else { + code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n"; + } + code += "\tROUGHNESS = roughness_tex * roughness;\n"; } else { - code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n"; + code += "\tROUGHNESS = roughness;\n"; } - code += "\tROUGHNESS = roughness_tex * roughness;\n"; + code += "\tSPECULAR = specular;\n"; if (features[FEATURE_NORMAL_MAPPING]) { @@ -1806,10 +1828,9 @@ RID SpatialMaterial::get_material_rid_for_2d(bool p_shaded, bool p_transparent, material->set_flag(FLAG_SRGB_VERTEX_COLOR, true); material->set_flag(FLAG_ALBEDO_FROM_VERTEX_COLOR, true); material->set_flag(FLAG_USE_ALPHA_SCISSOR, p_cut_alpha); - if (p_billboard) { - material->set_billboard_mode(BILLBOARD_ENABLED); - } else if (p_billboard_y) { - material->set_billboard_mode(BILLBOARD_FIXED_Y); + if (p_billboard || p_billboard_y) { + material->set_flag(FLAG_BILLBOARD_KEEP_SCALE, true); + material->set_billboard_mode(p_billboard_y ? BILLBOARD_FIXED_Y : BILLBOARD_ENABLED); } materials_for_2d[version] = material; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index ae18be1695..f1429a7d7b 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -37,6 +37,97 @@ void Theme::_emit_theme_changed() { emit_changed(); } +PoolVector<String> Theme::_get_icon_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_icon_list(p_type, &il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_stylebox_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_stylebox_list(p_type, &il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_stylebox_types(void) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_stylebox_types(&il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_font_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_font_list(p_type, &il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_color_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_color_list(p_type, &il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_constant_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_constant_list(p_type, &il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + +PoolVector<String> Theme::_get_type_list(const String &p_type) const { + + PoolVector<String> ilret; + List<StringName> il; + + get_type_list(&il); + ilret.resize(il.size()); + for (List<StringName>::Element *E = il.front(); E; E = E->next()) { + ilret.push_back(E->get()); + } + return ilret; +} + bool Theme::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -300,6 +391,8 @@ void Theme::clear_icon(const StringName &p_name, const StringName &p_type) { void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + if (!icon_map.has(p_type)) return; @@ -344,6 +437,9 @@ void Theme::clear_shader(const StringName &p_name, const StringName &p_type) { } void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const { + + ERR_FAIL_NULL(p_list); + if (!shader_map.has(p_type)) return; @@ -408,6 +504,8 @@ void Theme::clear_stylebox(const StringName &p_name, const StringName &p_type) { void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + if (!style_map.has(p_type)) return; @@ -420,6 +518,8 @@ void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const } void Theme::get_stylebox_types(List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + const StringName *key = NULL; while ((key = style_map.next(key))) { p_list->push_back(*key); @@ -478,6 +578,8 @@ void Theme::clear_font(const StringName &p_name, const StringName &p_type) { void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + if (!font_map.has(p_type)) return; @@ -526,6 +628,8 @@ void Theme::clear_color(const StringName &p_name, const StringName &p_type) { void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + if (!color_map.has(p_type)) return; @@ -574,6 +678,8 @@ void Theme::clear_constant(const StringName &p_name, const StringName &p_type) { void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const { + ERR_FAIL_NULL(p_list); + if (!constant_map.has(p_type)) return; @@ -637,6 +743,12 @@ void Theme::copy_default_theme() { void Theme::copy_theme(const Ref<Theme> &p_other) { + if (p_other.is_null()) { + clear(); + + return; + } + //these need reconnecting, so add normally { const StringName *K = NULL; @@ -680,8 +792,9 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { void Theme::get_type_list(List<StringName> *p_list) const { - Set<StringName> types; + ERR_FAIL_NULL(p_list); + Set<StringName> types; const StringName *key = NULL; while ((key = icon_map.next(key))) { diff --git a/scene/resources/theme.h b/scene/resources/theme.h index 187694de65..471e5b1a51 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -52,6 +52,14 @@ class Theme : public Resource { HashMap<StringName, HashMap<StringName, Color> > color_map; HashMap<StringName, HashMap<StringName, int> > constant_map; + PoolVector<String> _get_icon_list(const String &p_type) const; + PoolVector<String> _get_stylebox_list(const String &p_type) const; + PoolVector<String> _get_stylebox_types(void) const; + PoolVector<String> _get_font_list(const String &p_type) const; + PoolVector<String> _get_color_list(const String &p_type) const; + PoolVector<String> _get_constant_list(const String &p_type) const; + PoolVector<String> _get_type_list(const String &p_type) const; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -65,70 +73,6 @@ protected: Ref<Font> default_theme_font; - PoolVector<String> _get_icon_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_icon_list(p_type, &il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_stylebox_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_stylebox_list(p_type, &il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_stylebox_types(void) const { - PoolVector<String> ilret; - List<StringName> il; - get_stylebox_types(&il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_font_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_font_list(p_type, &il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_color_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_color_list(p_type, &il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_constant_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_constant_list(p_type, &il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - PoolVector<String> _get_type_list(const String &p_type) const { - PoolVector<String> ilret; - List<StringName> il; - get_type_list(&il); - for (List<StringName>::Element *E = il.front(); E; E = E->next()) { - ilret.push_back(E->get()); - } - return ilret; - } - static void _bind_methods(); public: diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h index eb3bf6770f..81c7b062cc 100644 --- a/scene/resources/video_stream.h +++ b/scene/resources/video_stream.h @@ -63,7 +63,7 @@ public: //virtual int mix(int16_t* p_buffer,int p_frames)=0; - virtual Ref<Texture> get_texture() = 0; + virtual Ref<Texture> get_texture() const = 0; virtual void update(float p_delta) = 0; virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) = 0; |