diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 35 | ||||
-rw-r--r-- | scene/resources/sky_material.cpp | 17 | ||||
-rw-r--r-- | scene/resources/sky_material.h | 4 |
3 files changed, 27 insertions, 29 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 67617a946f..de39fac627 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -52,20 +52,9 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, fl } else { texture = Ref<ImageTexture>(memnew(ImageTexture)); Ref<Image> img = memnew(Image(p_src)); - - if (scale > 1) { - Size2 orig_size = Size2(img->get_width(), img->get_height()); - - img->convert(Image::FORMAT_RGBA8); - img->expand_x2_hq2x(); - if (scale != 2.0) { - img->resize(orig_size.x * scale, orig_size.y * scale); - } - } else if (scale < 1) { - Size2 orig_size = Size2(img->get_width(), img->get_height()); - img->convert(Image::FORMAT_RGBA8); - img->resize(orig_size.x * scale, orig_size.y * scale); - } + const Size2 orig_size = Size2(img->get_width(), img->get_height()); + img->convert(Image::FORMAT_RGBA8); + img->resize(orig_size.x * scale, orig_size.y * scale); texture->create_from_image(img); (*tex_cache)[p_src] = texture; @@ -98,19 +87,9 @@ template <class T> static Ref<Texture2D> make_icon(T p_src) { Ref<ImageTexture> texture(memnew(ImageTexture)); Ref<Image> img = memnew(Image(p_src)); - if (scale > 1) { - Size2 orig_size = Size2(img->get_width(), img->get_height()); - - img->convert(Image::FORMAT_RGBA8); - img->expand_x2_hq2x(); - if (scale != 2.0) { - img->resize(orig_size.x * scale, orig_size.y * scale); - } - } else if (scale < 1) { - Size2 orig_size = Size2(img->get_width(), img->get_height()); - img->convert(Image::FORMAT_RGBA8); - img->resize(orig_size.x * scale, orig_size.y * scale); - } + const Size2 orig_size = Size2(img->get_width(), img->get_height()); + img->convert(Image::FORMAT_RGBA8); + img->resize(orig_size.x * scale, orig_size.y * scale); texture->create_from_image(img); return texture; @@ -702,7 +681,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_color("font_color_disabled", "TabContainer", control_font_color_disabled); theme->set_constant("side_margin", "TabContainer", 8 * scale); - theme->set_constant("hseparation", "TabContainer", 4 * scale); + theme->set_constant("icon_separation", "TabContainer", 4 * scale); // Tabs diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp index 92c5151d7a..69e8e0b5bd 100644 --- a/scene/resources/sky_material.cpp +++ b/scene/resources/sky_material.cpp @@ -410,6 +410,15 @@ float PhysicalSkyMaterial::get_dither_strength() const { return dither_strength; } +void PhysicalSkyMaterial::set_night_sky(const Ref<Texture2D> &p_night_sky) { + night_sky = p_night_sky; + RS::get_singleton()->material_set_param(_get_material(), "night_sky", night_sky); +} + +Ref<Texture2D> PhysicalSkyMaterial::get_night_sky() const { + return night_sky; +} + bool PhysicalSkyMaterial::_can_do_next_pass() const { return false; } @@ -453,6 +462,9 @@ void PhysicalSkyMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_dither_strength", "strength"), &PhysicalSkyMaterial::set_dither_strength); ClassDB::bind_method(D_METHOD("get_dither_strength"), &PhysicalSkyMaterial::get_dither_strength); + ClassDB::bind_method(D_METHOD("set_night_sky", "night_sky"), &PhysicalSkyMaterial::set_night_sky); + ClassDB::bind_method(D_METHOD("get_night_sky"), &PhysicalSkyMaterial::get_night_sky); + ADD_GROUP("Rayleigh", "rayleigh_"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rayleigh_coefficient", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_rayleigh_coefficient", "get_rayleigh_coefficient"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "rayleigh_color"), "set_rayleigh_color", "get_rayleigh_color"); @@ -467,6 +479,7 @@ void PhysicalSkyMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_color"), "set_ground_color", "get_ground_color"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "exposure", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_exposure", "get_exposure"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dither_strength", PROPERTY_HINT_RANGE, "0,10,0.01"), "set_dither_strength", "get_dither_strength"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "night_sky", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_night_sky", "get_night_sky"); } PhysicalSkyMaterial::PhysicalSkyMaterial() { @@ -484,6 +497,8 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() { code += "uniform float exposure : hint_range(0, 128) = 0.1;\n"; code += "uniform float dither_strength : hint_range(0, 10) = 1.0;\n\n"; + code += "uniform sampler2D night_sky : hint_black;"; + code += "const float PI = 3.141592653589793238462643383279502884197169;\n"; code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n"; @@ -547,7 +562,7 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() { code += "\tfloat sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);\n"; code += "\tfloat sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);\n"; code += "\tvec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;\n"; - code += "\t// Note: Add nightime here: L0 += night_sky * extinction\n\n"; + code += "\tL0 += texture(night_sky, SKY_COORDS).xyz * extinction;\n\n"; code += "\tvec3 color = (Lin + L0) * 0.04;\n"; code += "\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n"; diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h index cd245a2897..e470137d9e 100644 --- a/scene/resources/sky_material.h +++ b/scene/resources/sky_material.h @@ -139,6 +139,7 @@ private: Color ground_color; float exposure; float dither_strength; + Ref<Texture2D> night_sky; protected: static void _bind_methods(); @@ -175,6 +176,9 @@ public: void set_dither_strength(float p_dither_strength); float get_dither_strength() const; + void set_night_sky(const Ref<Texture2D> &p_night_sky); + Ref<Texture2D> get_night_sky() const; + virtual Shader::Mode get_shader_mode() const; RID get_shader_rid() const; |