diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/environment.cpp | 38 | ||||
-rw-r--r-- | scene/resources/environment.h | 8 | ||||
-rw-r--r-- | scene/resources/material.cpp | 354 | ||||
-rw-r--r-- | scene/resources/material.h | 94 | ||||
-rw-r--r-- | scene/resources/world_2d.cpp | 1 |
5 files changed, 401 insertions, 94 deletions
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index b9dc428c2d..33e62e3a00 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -471,7 +471,7 @@ bool Environment::is_ssao_blur_enabled() const { void Environment::set_glow_enabled(bool p_enabled) { glow_enabled = p_enabled; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); _change_notify(); } @@ -489,7 +489,7 @@ void Environment::set_glow_level(int p_level, bool p_enabled) { else glow_levels &= ~(1 << p_level); - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } bool Environment::is_glow_level_enabled(int p_level) const { @@ -502,7 +502,7 @@ void Environment::set_glow_intensity(float p_intensity) { glow_intensity = p_intensity; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } float Environment::get_glow_intensity() const { @@ -512,18 +512,18 @@ float Environment::get_glow_intensity() const { void Environment::set_glow_strength(float p_strength) { glow_strength = p_strength; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } float Environment::get_glow_strength() const { return glow_strength; } -void Environment::set_glow_bloom(float p_treshold) { +void Environment::set_glow_bloom(float p_threshold) { - glow_bloom = p_treshold; + glow_bloom = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } float Environment::get_glow_bloom() const { @@ -534,29 +534,29 @@ void Environment::set_glow_blend_mode(GlowBlendMode p_mode) { glow_blend_mode = p_mode; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } Environment::GlowBlendMode Environment::get_glow_blend_mode() const { return glow_blend_mode; } -void Environment::set_glow_hdr_bleed_treshold(float p_treshold) { +void Environment::set_glow_hdr_bleed_threshold(float p_threshold) { - glow_hdr_bleed_treshold = p_treshold; + glow_hdr_bleed_threshold = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } -float Environment::get_glow_hdr_bleed_treshold() const { +float Environment::get_glow_hdr_bleed_threshold() const { - return glow_hdr_bleed_treshold; + return glow_hdr_bleed_threshold; } void Environment::set_glow_hdr_bleed_scale(float p_scale) { glow_hdr_bleed_scale = p_scale; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } float Environment::get_glow_hdr_bleed_scale() const { @@ -566,7 +566,7 @@ float Environment::get_glow_hdr_bleed_scale() const { void Environment::set_glow_bicubic_upscale(bool p_enable) { glow_bicubic_upscale = p_enable; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); } bool Environment::is_glow_bicubic_upscale_enabled() const { @@ -1064,8 +1064,8 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_glow_blend_mode", "mode"), &Environment::set_glow_blend_mode); ClassDB::bind_method(D_METHOD("get_glow_blend_mode"), &Environment::get_glow_blend_mode); - ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_treshold", "treshold"), &Environment::set_glow_hdr_bleed_treshold); - ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_treshold"), &Environment::get_glow_hdr_bleed_treshold); + ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_threshold", "threshold"), &Environment::set_glow_hdr_bleed_threshold); + ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_threshold"), &Environment::get_glow_hdr_bleed_threshold); ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_scale", "scale"), &Environment::set_glow_hdr_bleed_scale); ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_scale"), &Environment::get_glow_hdr_bleed_scale); @@ -1087,7 +1087,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_strength", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_glow_strength", "get_glow_strength"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_bloom", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_glow_bloom", "get_glow_bloom"); ADD_PROPERTY(PropertyInfo(Variant::INT, "glow_blend_mode", PROPERTY_HINT_ENUM, "Additive,Screen,Softlight,Replace"), "set_glow_blend_mode", "get_glow_blend_mode"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_treshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_treshold", "get_glow_hdr_bleed_treshold"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_threshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_threshold", "get_glow_hdr_bleed_threshold"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_scale", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_scale", "get_glow_hdr_bleed_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_bicubic_upscale"), "set_glow_bicubic_upscale", "is_glow_bicubic_upscale_enabled"); @@ -1185,7 +1185,7 @@ Environment::Environment() { glow_strength = 1.0; glow_bloom = 0.0; glow_blend_mode = GLOW_BLEND_MODE_SOFTLIGHT; - glow_hdr_bleed_treshold = 1.0; + glow_hdr_bleed_threshold = 1.0; glow_hdr_bleed_scale = 2.0; glow_bicubic_upscale = false; diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 7eda8506b5..a7c0e2a03d 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -121,7 +121,7 @@ private: float glow_strength; float glow_bloom; GlowBlendMode glow_blend_mode; - float glow_hdr_bleed_treshold; + float glow_hdr_bleed_threshold; float glow_hdr_bleed_scale; bool glow_bicubic_upscale; @@ -275,14 +275,14 @@ public: void set_glow_strength(float p_strength); float get_glow_strength() const; - void set_glow_bloom(float p_treshold); + void set_glow_bloom(float p_threshold); float get_glow_bloom() const; void set_glow_blend_mode(GlowBlendMode p_mode); GlowBlendMode get_glow_blend_mode() const; - void set_glow_hdr_bleed_treshold(float p_treshold); - float get_glow_hdr_bleed_treshold() const; + void set_glow_hdr_bleed_threshold(float p_threshold); + float get_glow_hdr_bleed_threshold() const; void set_glow_hdr_bleed_scale(float p_scale); float get_glow_hdr_bleed_scale() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 6209f99d9d..705702b8be 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -30,11 +30,36 @@ #include "material.h" #include "scene/scene_string_names.h" +void Material::set_next_pass(const Ref<Material> &p_pass) { + + if (next_pass == p_pass) + return; + + next_pass = p_pass; + RID next_pass_rid; + if (next_pass.is_valid()) + next_pass_rid = next_pass->get_rid(); + VS::get_singleton()->material_set_next_pass(material, next_pass_rid); +} + +Ref<Material> Material::get_next_pass() const { + + return next_pass; +} + RID Material::get_rid() const { return material; } +void Material::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_next_pass", "next_pass:Material"), &Material::set_next_pass); + ClassDB::bind_method(D_METHOD("get_next_pass:Material"), &Material::get_next_pass); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "next_pass", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_next_pass", "get_next_pass"); +} + Material::Material() { material = VisualServer::get_singleton()->material_create(); @@ -198,6 +223,8 @@ void SpatialMaterial::init_shaders() { shader_names->uv1_offset = "uv1_offset"; shader_names->uv2_scale = "uv2_scale"; shader_names->uv2_offset = "uv2_offset"; + shader_names->uv1_blend_sharpness = "uv1_blend_sharpness"; + shader_names->uv2_blend_sharpness = "uv2_blend_sharpness"; shader_names->particle_h_frames = "particle_h_frames"; shader_names->particle_v_frames = "particle_v_frames"; @@ -205,6 +232,8 @@ void SpatialMaterial::init_shaders() { shader_names->depth_min_layers = "depth_min_layers"; shader_names->depth_max_layers = "depth_max_layers"; + shader_names->grow = "grow"; + shader_names->texture_names[TEXTURE_ALBEDO] = "texture_albedo"; shader_names->texture_names[TEXTURE_METALLIC] = "texture_metallic"; shader_names->texture_names[TEXTURE_ROUGHNESS] = "texture_roughness"; @@ -289,6 +318,14 @@ void SpatialMaterial::_update_shader() { case DIFFUSE_HALF_LAMBERT: code += ",diffuse_half_lambert"; break; case DIFFUSE_OREN_NAYAR: code += ",diffuse_oren_nayar"; break; case DIFFUSE_BURLEY: code += ",diffuse_burley"; break; + case DIFFUSE_TOON: code += ",diffuse_toon"; break; + } + switch (specular_mode) { + case SPECULAR_SCHLICK_GGX: code += ",specular_schlick_ggx"; break; + case SPECULAR_BLINN: code += ",specular_blinn"; break; + case SPECULAR_PHONG: code += ",specular_phong"; break; + case SPECULAR_TOON: code += ",specular_toon"; break; + case SPECULAR_DISABLED: code += ",specular_disabled"; break; } if (flags[FLAG_UNSHADED]) { @@ -298,21 +335,23 @@ void SpatialMaterial::_update_shader() { code += ",ontop"; } + if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { + code += ",world_vertex_coords"; + } code += ";\n"; code += "uniform vec4 albedo : hint_color;\n"; code += "uniform sampler2D texture_albedo : hint_albedo;\n"; code += "uniform float specular;\n"; code += "uniform float metallic;\n"; + if (grow_enabled) { + code += "uniform float grow;\n"; + } 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 sampler2D texture_roughness : hint_white;\n"; - code += "uniform vec2 uv1_scale;\n"; - code += "uniform vec2 uv1_offset;\n"; - code += "uniform vec2 uv2_scale;\n"; - code += "uniform vec2 uv2_offset;\n"; if (billboard_mode == BILLBOARD_PARTICLES) { code += "uniform int particles_anim_h_frames;\n"; code += "uniform int particles_anim_v_frames;\n"; @@ -371,6 +410,26 @@ void SpatialMaterial::_update_shader() { code += "uniform int depth_min_layers;\n"; code += "uniform int depth_max_layers;\n"; } + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "varying vec3 uv1_world_pos;\n"; + } + if (flags[FLAG_UV2_USE_TRIPLANAR]) { + code += "varying vec3 uv2_world_pos;\n"; + } + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "uniform float uv1_blend_sharpness;\n"; + code += "varying vec3 uv1_power_normal;\n"; + } + + if (flags[FLAG_UV2_USE_TRIPLANAR]) { + code += "uniform float uv2_blend_sharpness;\n"; + code += "varying vec3 uv2_power_normal;\n"; + } + + code += "uniform vec3 uv1_scale;\n"; + code += "uniform vec3 uv1_offset;\n"; + code += "uniform vec3 uv2_scale;\n"; + code += "uniform vec3 uv2_offset;\n"; code += "\n\n"; @@ -384,7 +443,10 @@ void SpatialMaterial::_update_shader() { code += "\tPOINT_SIZE=point_size;\n"; } - code += "\tUV=UV*uv1_scale+uv1_offset;\n"; + + if (!flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n"; + } switch (billboard_mode) { case BILLBOARD_DISABLED: { @@ -414,7 +476,6 @@ void SpatialMaterial::_update_shader() { //code += "\tUV+= UV * vec2(float(particle_frame % particles_anim_h_frames),float(particle_frame / particles_anim_v_frames));\n"; //handle rotation // code += "\tmat4 rotation = mat4(" - } break; } @@ -437,20 +498,65 @@ void SpatialMaterial::_update_shader() { code += "\t}\n"; } - if (detail_uv == DETAIL_UV_2) { + if (detail_uv == DETAIL_UV_2 && !flags[FLAG_UV2_USE_TRIPLANAR]) { code += "\tUV2=UV2*uv2_scale+uv2_offset;\n"; } + if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { + //generate tangent and binormal in world space + code += "\tTANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n"; + code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n"; + code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n"; + code += "\tTANGENT = normalize(TANGENT);\n"; + + code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n"; + code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n"; + code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n"; + code += "\tBINORMAL = normalize(BINORMAL);\n"; + } + + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + + code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; + code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n"; + code += "\tuv1_world_pos = VERTEX * uv1_scale + uv1_offset;\n"; + code += "\tuv1_world_pos *= vec3(1.0,-1.0, 1.0);\n"; + } + + if (flags[FLAG_UV2_USE_TRIPLANAR]) { + + code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; + code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n"; + code += "\tuv2_world_pos = VERTEX * uv2_scale + uv2_offset;\n"; + code += "\tuv2_world_pos *= vec3(1.0,-1.0, 1.0);\n"; + } + + if (grow_enabled) { + code += "\tVERTEX+=NORMAL*grow;\n"; + } code += "}\n"; code += "\n\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { + code += "vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_world_pos) {\n"; + code += "\tvec4 samp=vec4(0.0);\n"; + code += "\tsamp+= texture(p_sampler,p_world_pos.xy) * p_weights.z;\n"; + code += "\tsamp+= texture(p_sampler,p_world_pos.xz) * p_weights.y;\n"; + code += "\tsamp+= texture(p_sampler,p_world_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n"; + code += "\treturn samp;\n"; + code += "}\n"; + } + code += "\n\n"; code += "void fragment() {\n"; - code += "\tvec2 base_uv = UV;\n"; - if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) { + if (!flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec2 base_uv = UV;\n"; + } + + if ((features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) || (features[FEATURE_AMBIENT_OCCLUSION] && flags[FLAG_AO_ON_UV2])) { code += "\tvec2 base_uv2 = UV2;\n"; } - if (features[FEATURE_DEPTH_MAPPING]) { + if (features[FEATURE_DEPTH_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //depthmap not supported with triplanar code += "\t{\n"; code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT,-BINORMAL,NORMAL));\n"; //binormal is negative due to mikktpsace @@ -490,7 +596,11 @@ void SpatialMaterial::_update_shader() { 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_world_pos);\n"; + } else { + code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n"; + } } if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) { @@ -498,22 +608,39 @@ void SpatialMaterial::_update_shader() { } code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n"; - code += "\tfloat metallic_tex = texture(texture_metallic,base_uv).r;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tfloat metallic_tex = triplanar_texture(texture_metallic,uv1_power_normal,uv1_world_pos).r;\n"; + } else { + code += "\tfloat metallic_tex = texture(texture_metallic,base_uv).r;\n"; + } code += "\tMETALLIC = metallic_tex * metallic;\n"; - code += "\tfloat roughness_tex = texture(texture_roughness,base_uv).r;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tfloat roughness_tex = triplanar_texture(texture_roughness,uv1_power_normal,uv1_world_pos).r;\n"; + } else { + code += "\tfloat roughness_tex = texture(texture_roughness,base_uv).r;\n"; + } code += "\tROUGHNESS = roughness_tex * roughness;\n"; code += "\tSPECULAR = specular;\n"; if (features[FEATURE_NORMAL_MAPPING]) { - code += "\tNORMALMAP = texture(texture_normal,base_uv).rgb;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tNORMALMAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_world_pos).rgb;\n"; + } else { + code += "\tNORMALMAP = texture(texture_normal,base_uv).rgb;\n"; + } code += "\tNORMALMAP_DEPTH = normal_scale;\n"; } if (features[FEATURE_EMISSION]) { - code += "\tEMISSION = (emission.rgb+texture(texture_emission,base_uv).rgb)*emission_energy;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_world_pos).rgb;\n"; + } else { + code += "\tvec3 emission_tex = texture(texture_emission,base_uv).rgb;\n"; + } + code += "\tEMISSION = (emission.rgb+emission_tex)*emission_energy;\n"; } - if (features[FEATURE_REFRACTION]) { + if (features[FEATURE_REFRACTION] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //refraction not supported with triplanar if (features[FEATURE_NORMAL_MAPPING]) { code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) ) * SIDE;\n"; @@ -532,38 +659,82 @@ void SpatialMaterial::_update_shader() { } if (features[FEATURE_RIM]) { - code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xw;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_world_pos).xy;\n"; + } else { + code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xy;\n"; + } code += "\tRIM = rim*rim_tex.x;"; code += "\tRIM_TINT = rim_tint*rim_tex.y;\n"; } if (features[FEATURE_CLEARCOAT]) { - code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xw;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_world_pos).xy;\n"; + } else { + code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n"; + } code += "\tCLEARCOAT = clearcoat*clearcoat_tex.x;"; code += "\tCLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n"; } if (features[FEATURE_ANISOTROPY]) { - code += "\tvec4 anisotropy_tex = texture(texture_flowmap,base_uv);\n"; - code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.a;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_world_pos).rga;\n"; + } else { + code += "\tvec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n"; + } + code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n"; code += "\tANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n"; } if (features[FEATURE_AMBIENT_OCCLUSION]) { - code += "\tAO = texture(texture_ambient_occlusion,base_uv).r;\n"; + if (flags[FLAG_AO_ON_UV2]) { + if (flags[FLAG_UV2_USE_TRIPLANAR]) { + code += "\tAO = triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_world_pos).r;\n"; + } else { + code += "\tAO = texture(texture_ambient_occlusion,base_uv2).r;\n"; + } + } else { + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tAO = triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_world_pos).r;\n"; + } else { + code += "\tAO = texture(texture_ambient_occlusion,base_uv).r;\n"; + } + } } if (features[FEATURE_SUBSURACE_SCATTERING]) { - code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n"; + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_world_pos).r;\n"; + } else { + code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n"; + } code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n"; } if (features[FEATURE_DETAIL]) { - String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2"; - code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n"; - code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n"; - code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; + + bool triplanar = (flags[FLAG_UV1_USE_TRIPLANAR] && detail_uv == DETAIL_UV_1) || (flags[FLAG_UV2_USE_TRIPLANAR] && detail_uv == DETAIL_UV_2); + + if (triplanar) { + String tp_uv = detail_uv == DETAIL_UV_1 ? "uv1" : "uv2"; + code += "\tvec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_world_pos);\n"; + code += "\tvec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_world_pos);\n"; + + } else { + String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2"; + code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n"; + code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n"; + } + + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + + code += "\tvec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal);\n"; + } else { + code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; + } switch (detail_blend_mode) { case BLEND_MODE_MIX: { @@ -581,7 +752,6 @@ void SpatialMaterial::_update_shader() { } code += "\tvec3 detail_norm = mix(NORMALMAP,detail_norm_tex.rgb,detail_tex.a);\n"; - code += "\tNORMALMAP = mix(NORMALMAP,detail_norm,detail_mask_tex.r);\n"; code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n"; } @@ -875,6 +1045,19 @@ SpatialMaterial::DiffuseMode SpatialMaterial::get_diffuse_mode() const { return diffuse_mode; } +void SpatialMaterial::set_specular_mode(SpecularMode p_mode) { + + if (specular_mode == p_mode) + return; + + specular_mode = p_mode; + _queue_shader_change(); +} +SpatialMaterial::SpecularMode SpatialMaterial::get_specular_mode() const { + + return specular_mode; +} + void SpatialMaterial::set_flag(Flags p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); @@ -947,6 +1130,10 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) { property.usage = 0; } + + if (property.name == "params_grow_amount" && !grow_enabled) { + property.usage = 0; + } } void SpatialMaterial::set_line_width(float p_line_width) { @@ -971,49 +1158,71 @@ float SpatialMaterial::get_point_size() const { return point_size; } -void SpatialMaterial::set_uv1_scale(const Vector2 &p_scale) { +void SpatialMaterial::set_uv1_scale(const Vector3 &p_scale) { uv1_scale = p_scale; VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_scale, p_scale); } -Vector2 SpatialMaterial::get_uv1_scale() const { +Vector3 SpatialMaterial::get_uv1_scale() const { return uv1_scale; } -void SpatialMaterial::set_uv1_offset(const Vector2 &p_offset) { +void SpatialMaterial::set_uv1_offset(const Vector3 &p_offset) { uv1_offset = p_offset; VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_offset, p_offset); } -Vector2 SpatialMaterial::get_uv1_offset() const { +Vector3 SpatialMaterial::get_uv1_offset() const { return uv1_offset; } -void SpatialMaterial::set_uv2_scale(const Vector2 &p_scale) { +void SpatialMaterial::set_uv1_triplanar_blend_sharpness(float p_sharpness) { + + uv1_triplanar_sharpness = p_sharpness; + VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness); +} + +float SpatialMaterial::get_uv1_triplanar_blend_sharpness() const { + + return uv1_triplanar_sharpness; +} + +void SpatialMaterial::set_uv2_scale(const Vector3 &p_scale) { uv2_scale = p_scale; VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_scale, p_scale); } -Vector2 SpatialMaterial::get_uv2_scale() const { +Vector3 SpatialMaterial::get_uv2_scale() const { return uv2_scale; } -void SpatialMaterial::set_uv2_offset(const Vector2 &p_offset) { +void SpatialMaterial::set_uv2_offset(const Vector3 &p_offset) { uv2_offset = p_offset; VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_offset, p_offset); } -Vector2 SpatialMaterial::get_uv2_offset() const { +Vector3 SpatialMaterial::get_uv2_offset() const { return uv2_offset; } +void SpatialMaterial::set_uv2_triplanar_blend_sharpness(float p_sharpness) { + + uv2_triplanar_sharpness = p_sharpness; + VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness); +} + +float SpatialMaterial::get_uv2_triplanar_blend_sharpness() const { + + return uv2_triplanar_sharpness; +} + void SpatialMaterial::set_billboard_mode(BillboardMode p_mode) { billboard_mode = p_mode; @@ -1063,7 +1272,6 @@ void SpatialMaterial::set_depth_deep_parallax(bool p_enable) { deep_parallax = p_enable; _queue_shader_change(); _change_notify(); - ; } bool SpatialMaterial::is_depth_deep_parallax_enabled() const { @@ -1091,6 +1299,26 @@ int SpatialMaterial::get_depth_deep_parallax_max_layers() const { return deep_parallax_max_layers; } +void SpatialMaterial::set_grow_enabled(bool p_enable) { + grow_enabled = p_enable; + _queue_shader_change(); + _change_notify(); +} + +bool SpatialMaterial::is_grow_enabled() const { + return grow_enabled; +} + +void SpatialMaterial::set_grow(float p_grow) { + grow = p_grow; + VS::get_singleton()->material_set_param(_get_material(), shader_names->grow, p_grow); +} + +float SpatialMaterial::get_grow() const { + + return grow; +} + void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo); @@ -1159,6 +1387,9 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_diffuse_mode", "diffuse_mode"), &SpatialMaterial::set_diffuse_mode); ClassDB::bind_method(D_METHOD("get_diffuse_mode"), &SpatialMaterial::get_diffuse_mode); + ClassDB::bind_method(D_METHOD("set_specular_mode", "specular_mode"), &SpatialMaterial::set_specular_mode); + ClassDB::bind_method(D_METHOD("get_specular_mode"), &SpatialMaterial::get_specular_mode); + ClassDB::bind_method(D_METHOD("set_flag", "flag", "enable"), &SpatialMaterial::set_flag); ClassDB::bind_method(D_METHOD("get_flag"), &SpatialMaterial::get_flag); @@ -1177,12 +1408,18 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_uv1_offset", "offset"), &SpatialMaterial::set_uv1_offset); ClassDB::bind_method(D_METHOD("get_uv1_offset"), &SpatialMaterial::get_uv1_offset); + ClassDB::bind_method(D_METHOD("set_uv1_triplanar_blend_sharpness", "sharpness"), &SpatialMaterial::set_uv1_triplanar_blend_sharpness); + ClassDB::bind_method(D_METHOD("get_uv1_triplanar_blend_sharpness"), &SpatialMaterial::get_uv1_triplanar_blend_sharpness); + ClassDB::bind_method(D_METHOD("set_uv2_scale", "scale"), &SpatialMaterial::set_uv2_scale); ClassDB::bind_method(D_METHOD("get_uv2_scale"), &SpatialMaterial::get_uv2_scale); ClassDB::bind_method(D_METHOD("set_uv2_offset", "offset"), &SpatialMaterial::set_uv2_offset); ClassDB::bind_method(D_METHOD("get_uv2_offset"), &SpatialMaterial::get_uv2_offset); + ClassDB::bind_method(D_METHOD("set_uv2_triplanar_blend_sharpness", "sharpness"), &SpatialMaterial::set_uv2_triplanar_blend_sharpness); + ClassDB::bind_method(D_METHOD("get_uv2_triplanar_blend_sharpness"), &SpatialMaterial::get_uv2_triplanar_blend_sharpness); + ClassDB::bind_method(D_METHOD("set_billboard_mode", "mode"), &SpatialMaterial::set_billboard_mode); ClassDB::bind_method(D_METHOD("get_billboard_mode"), &SpatialMaterial::get_billboard_mode); @@ -1204,6 +1441,12 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_max_layers", "layer"), &SpatialMaterial::set_depth_deep_parallax_max_layers); ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_max_layers"), &SpatialMaterial::get_depth_deep_parallax_max_layers); + ClassDB::bind_method(D_METHOD("set_grow", "amount"), &SpatialMaterial::set_grow); + ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow); + + ClassDB::bind_method(D_METHOD("set_grow_enabled", "enable"), &SpatialMaterial::set_grow_enabled); + ClassDB::bind_method(D_METHOD("is_grow_enabled"), &SpatialMaterial::is_grow_enabled); + ADD_GROUP("Flags", "flags_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_transparent"), "set_feature", "get_feature", FEATURE_TRANSPARENT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_unshaded"), "set_flag", "get_flag", FLAG_UNSHADED); @@ -1215,13 +1458,16 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_is_srgb"), "set_flag", "get_flag", FLAG_SRGB_VERTEX_COLOR); ADD_GROUP("Parameters", "params_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "params_diffuse_mode", PROPERTY_HINT_ENUM, "Lambert,Lambert Wrap,Oren Nayar,Burley"), "set_diffuse_mode", "get_diffuse_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "params_diffuse_mode", PROPERTY_HINT_ENUM, "Lambert,Lambert Wrap,Oren Nayar,Burley,Toon"), "set_diffuse_mode", "get_diffuse_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "params_specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Blinn,Phong,Toon,Disabled"), "set_specular_mode", "get_specular_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul"), "set_blend_mode", "get_blend_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_cull_mode", PROPERTY_HINT_ENUM, "Back,Front,Disabled"), "set_cull_mode", "get_cull_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_depth_draw_mode", PROPERTY_HINT_ENUM, "Opaque Only,Always,Never,Opaque Pre-Pass"), "set_depth_draw_mode", "get_depth_draw_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_line_width", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_line_width", "get_line_width"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_point_size", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_point_size", "get_point_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_billboard_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Y-Billboard,Particle Billboard"), "set_billboard_mode", "get_billboard_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "params_grow"), "set_grow_enabled", "is_grow_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_grow_amount", PROPERTY_HINT_RANGE, "-16,10,0.01"), "set_grow", "get_grow"); ADD_GROUP("Particles Anim", "particles_anim_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_h_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_h_frames", "get_particles_anim_h_frames"); ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_v_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_v_frames", "get_particles_anim_v_frames"); @@ -1271,6 +1517,7 @@ void SpatialMaterial::_bind_methods() { ADD_GROUP("Ambient Occlusion", "ao_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_on_uv2"), "set_flag", "get_flag", FLAG_AO_ON_UV2); ADD_GROUP("Depth", "depth_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "depth_enabled"), "set_feature", "get_feature", FEATURE_DEPTH_MAPPING); @@ -1299,12 +1546,16 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "detail_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_DETAIL_NORMAL); ADD_GROUP("UV1", "uv1_"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv1_scale"), "set_uv1_scale", "get_uv1_scale"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv1_offset"), "set_uv1_offset", "get_uv1_offset"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_scale"), "set_uv1_scale", "get_uv1_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_offset"), "set_uv1_offset", "get_uv1_offset"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv1_triplanar"), "set_flag", "get_flag", FLAG_UV1_USE_TRIPLANAR); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv1_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv1_triplanar_blend_sharpness", "get_uv1_triplanar_blend_sharpness"); ADD_GROUP("UV2", "uv2_"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_scale"), "set_uv2_scale", "get_uv2_scale"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_offset"), "set_uv2_offset", "get_uv2_offset"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_scale"), "set_uv2_scale", "get_uv2_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_offset"), "set_uv2_offset", "get_uv2_offset"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv2_triplanar"), "set_flag", "get_flag", FLAG_UV2_USE_TRIPLANAR); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv2_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv2_triplanar_blend_sharpness", "get_uv2_triplanar_blend_sharpness"); BIND_CONSTANT(TEXTURE_ALBEDO); BIND_CONSTANT(TEXTURE_METALLIC); @@ -1365,6 +1616,13 @@ void SpatialMaterial::_bind_methods() { BIND_CONSTANT(DIFFUSE_HALF_LAMBERT); BIND_CONSTANT(DIFFUSE_OREN_NAYAR); BIND_CONSTANT(DIFFUSE_BURLEY); + BIND_CONSTANT(DIFFUSE_TOON); + + BIND_CONSTANT(SPECULAR_SCHLICK_GGX); + BIND_CONSTANT(SPECULAR_BLINN); + BIND_CONSTANT(SPECULAR_PHONG); + BIND_CONSTANT(SPECULAR_TOON); + BIND_CONSTANT(SPECULAR_DISABLED); BIND_CONSTANT(BILLBOARD_DISABLED); BIND_CONSTANT(BILLBOARD_ENABLED); @@ -1393,15 +1651,20 @@ SpatialMaterial::SpatialMaterial() set_refraction(0.05); set_line_width(1); set_point_size(1); - set_uv1_offset(Vector2(0, 0)); - set_uv1_scale(Vector2(1, 1)); - set_uv2_offset(Vector2(0, 0)); - set_uv2_scale(Vector2(1, 1)); + set_uv1_offset(Vector3(0, 0, 0)); + set_uv1_scale(Vector3(1, 1, 1)); + set_uv1_triplanar_blend_sharpness(1); + set_uv2_offset(Vector3(0, 0, 0)); + set_uv2_scale(Vector3(1, 1, 1)); + set_uv2_triplanar_blend_sharpness(1); set_billboard_mode(BILLBOARD_DISABLED); set_particles_anim_h_frames(1); set_particles_anim_v_frames(1); set_particles_anim_loop(false); + grow_enabled = false; + set_grow(0.0); + deep_parallax = false; set_depth_deep_parallax_min_layers(8); set_depth_deep_parallax_max_layers(32); @@ -1415,6 +1678,7 @@ SpatialMaterial::SpatialMaterial() flags[i] = 0; } diffuse_mode = DIFFUSE_LAMBERT; + specular_mode = SPECULAR_SCHLICK_GGX; for (int i = 0; i < FEATURE_MAX; i++) { features[i] = false; diff --git a/scene/resources/material.h b/scene/resources/material.h index fb6c5b81d9..276064bce4 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -47,11 +47,16 @@ class Material : public Resource { OBJ_SAVE_TYPE(Material) RID material; + Ref<Material> next_pass; protected: _FORCE_INLINE_ RID _get_material() const { return material; } + static void _bind_methods(); public: + void set_next_pass(const Ref<Material> &p_pass); + Ref<Material> get_next_pass() const; + virtual RID get_rid() const; Material(); virtual ~Material(); @@ -155,6 +160,9 @@ public: FLAG_SRGB_VERTEX_COLOR, FLAG_USE_POINT_SIZE, FLAG_FIXED_SIZE, + FLAG_UV1_USE_TRIPLANAR, + FLAG_UV2_USE_TRIPLANAR, + FLAG_AO_ON_UV2, FLAG_MAX }; @@ -163,6 +171,15 @@ public: DIFFUSE_HALF_LAMBERT, DIFFUSE_OREN_NAYAR, DIFFUSE_BURLEY, + DIFFUSE_TOON, + }; + + enum SpecularMode { + SPECULAR_SCHLICK_GGX, + SPECULAR_BLINN, + SPECULAR_PHONG, + SPECULAR_TOON, + SPECULAR_DISABLED, }; enum BillboardMode { @@ -176,20 +193,22 @@ private: union MaterialKey { struct { - uint32_t feature_mask : 11; - uint32_t detail_uv : 1; - uint32_t blend_mode : 2; - uint32_t depth_draw_mode : 2; - uint32_t cull_mode : 2; - uint32_t flags : 6; - uint32_t detail_blend_mode : 2; - uint32_t diffuse_mode : 2; - uint32_t invalid_key : 1; - uint32_t deep_parallax : 1; - uint32_t billboard_mode : 2; + uint64_t feature_mask : 11; + uint64_t detail_uv : 1; + uint64_t blend_mode : 2; + uint64_t depth_draw_mode : 2; + uint64_t cull_mode : 2; + uint64_t flags : 9; + uint64_t detail_blend_mode : 2; + uint64_t diffuse_mode : 3; + uint64_t specular_mode : 2; + uint64_t invalid_key : 1; + uint64_t deep_parallax : 1; + uint64_t billboard_mode : 2; + uint64_t grow : 1; }; - uint32_t key; + uint64_t key; bool operator<(const MaterialKey &p_key) const { return key < p_key.key; @@ -225,9 +244,10 @@ private: } mk.detail_blend_mode = detail_blend_mode; mk.diffuse_mode = diffuse_mode; + mk.specular_mode = specular_mode; mk.billboard_mode = billboard_mode; mk.deep_parallax = deep_parallax ? 1 : 0; - ; + mk.grow = grow_enabled; return mk; } @@ -258,6 +278,9 @@ private: StringName particles_anim_loop; StringName depth_min_layers; StringName depth_max_layers; + StringName uv1_blend_sharpness; + StringName uv2_blend_sharpness; + StringName grow; StringName texture_names[TEXTURE_MAX]; }; @@ -289,15 +312,19 @@ private: float refraction; float line_width; float point_size; + bool grow_enabled; + float grow; int particles_anim_h_frames; int particles_anim_v_frames; bool particles_anim_loop; - Vector2 uv1_scale; - Vector2 uv1_offset; + Vector3 uv1_scale; + Vector3 uv1_offset; + float uv1_triplanar_sharpness; - Vector2 uv2_scale; - Vector2 uv2_offset; + Vector3 uv2_scale; + Vector3 uv2_offset; + float uv2_triplanar_sharpness; DetailUV detail_uv; @@ -310,6 +337,7 @@ private: DepthDrawMode depth_draw_mode; CullMode cull_mode; bool flags[FLAG_MAX]; + SpecularMode specular_mode; DiffuseMode diffuse_mode; BillboardMode billboard_mode; @@ -402,6 +430,9 @@ public: void set_diffuse_mode(DiffuseMode p_mode); DiffuseMode get_diffuse_mode() const; + void set_specular_mode(SpecularMode p_mode); + SpecularMode get_specular_mode() const; + void set_flag(Flags p_flag, bool p_enabled); bool get_flag(Flags p_flag) const; @@ -411,17 +442,23 @@ public: void set_feature(Feature p_feature, bool p_enabled); bool get_feature(Feature p_feature) const; - void set_uv1_scale(const Vector2 &p_scale); - Vector2 get_uv1_scale() const; + void set_uv1_scale(const Vector3 &p_scale); + Vector3 get_uv1_scale() const; - void set_uv1_offset(const Vector2 &p_offset); - Vector2 get_uv1_offset() const; + void set_uv1_offset(const Vector3 &p_offset); + Vector3 get_uv1_offset() const; - void set_uv2_scale(const Vector2 &p_scale); - Vector2 get_uv2_scale() const; + void set_uv1_triplanar_blend_sharpness(float p_sharpness); + float get_uv1_triplanar_blend_sharpness() const; - void set_uv2_offset(const Vector2 &p_offset); - Vector2 get_uv2_offset() const; + void set_uv2_scale(const Vector3 &p_scale); + Vector3 get_uv2_scale() const; + + void set_uv2_offset(const Vector3 &p_offset); + Vector3 get_uv2_offset() const; + + void set_uv2_triplanar_blend_sharpness(float p_sharpness); + float get_uv2_triplanar_blend_sharpness() const; void set_billboard_mode(BillboardMode p_mode); BillboardMode get_billboard_mode() const; @@ -434,6 +471,12 @@ public: void set_particles_anim_loop(int p_frames); int get_particles_anim_loop() const; + void set_grow_enabled(bool p_enable); + bool is_grow_enabled() const; + + void set_grow(float p_grow); + float get_grow() const; + static void init_shaders(); static void finish_shaders(); static void flush_changes(); @@ -450,6 +493,7 @@ VARIANT_ENUM_CAST(SpatialMaterial::DepthDrawMode) VARIANT_ENUM_CAST(SpatialMaterial::CullMode) VARIANT_ENUM_CAST(SpatialMaterial::Flags) VARIANT_ENUM_CAST(SpatialMaterial::DiffuseMode) +VARIANT_ENUM_CAST(SpatialMaterial::SpecularMode) VARIANT_ENUM_CAST(SpatialMaterial::BillboardMode) ////////////////////// diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 36d2a38b3d..9ec89e4003 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -32,7 +32,6 @@ #include "servers/visual_server.h" //#include "servers/spatial_sound_2d_server.h" #include "global_config.h" -#include "global_config.h" #include "scene/2d/camera_2d.h" #include "scene/2d/visibility_notifier_2d.h" #include "scene/main/viewport.h" |