summaryrefslogtreecommitdiff
path: root/scene/resources/material.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/material.cpp')
-rw-r--r--scene/resources/material.cpp96
1 files changed, 54 insertions, 42 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index cc8685b952..274c74a9a2 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -427,10 +427,8 @@ void SpatialMaterial::_update_shader() {
if (flags[FLAG_USE_VERTEX_LIGHTING]) {
code += ",vertex_lighting";
}
- bool using_world = false;
if (flags[FLAG_TRIPLANAR_USE_WORLD] && (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR])) {
code += ",world_vertex_coords";
- using_world = true;
}
if (flags[FLAG_DONT_RECEIVE_SHADOWS]) {
code += ",shadows_disabled";
@@ -612,11 +610,11 @@ void SpatialMaterial::_update_shader() {
code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n";
//handle animation
- code += "\tint particle_total_frames = particles_anim_h_frames * particles_anim_v_frames;\n";
- code += "\tint particle_frame = int(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
- code += "\tif (particles_anim_loop) particle_frame=clamp(particle_frame,0,particle_total_frames-1); else particle_frame=abs(particle_frame)%particle_total_frames;\n";
+ code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
+ code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
+ code += "\tif (particles_anim_loop) particle_frame=clamp(particle_frame,0.0,particle_total_frames-1.0); else particle_frame=mod(particle_frame,float(particle_total_frames));\n";
code += "\tUV /= vec2(float(particles_anim_h_frames),float(particles_anim_v_frames));\n";
- code += "\tUV += vec2(float(particle_frame % particles_anim_h_frames) / float(particles_anim_h_frames),float(particle_frame / particles_anim_h_frames) / float(particles_anim_v_frames));\n";
+ code += "\tUV += vec2(mod(particle_frame,float(particles_anim_h_frames)) / float(particles_anim_h_frames),particle_frame / float(particles_anim_h_frames) / float(particles_anim_v_frames));\n";
} break;
}
@@ -819,7 +817,7 @@ void SpatialMaterial::_update_shader() {
code += "\tALPHA = albedo.a * albedo_tex.a;\n";
}
- if (proximity_fade_enabled) {
+ if (!VisualServer::get_singleton()->is_low_end() && proximity_fade_enabled) {
code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n";
code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n";
code += "\tworld_pos.xyz/=world_pos.w;\n";
@@ -827,43 +825,45 @@ void SpatialMaterial::_update_shader() {
}
if (distance_fade != DISTANCE_FADE_DISABLED) {
- if (distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER) {
-
- code += "\t{\n";
- if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) {
- code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
-
- } else {
- code += "\t\tfloat fade_distance=-VERTEX.z;\n";
+ if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) {
+
+ if (!VisualServer::get_singleton()->is_low_end()) {
+ code += "\t{\n";
+ if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) {
+ code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n";
+
+ } else {
+ code += "\t\tfloat fade_distance=-VERTEX.z;\n";
+ }
+
+ code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
+ code += "\t\tint x = int(FRAGCOORD.x) % 4;\n";
+ code += "\t\tint y = int(FRAGCOORD.y) % 4;\n";
+ code += "\t\tint index = x + y * 4;\n";
+ code += "\t\tfloat limit = 0.0;\n\n";
+ code += "\t\tif (x < 8) {\n";
+ code += "\t\t\tif (index == 0) limit = 0.0625;\n";
+ code += "\t\t\tif (index == 1) limit = 0.5625;\n";
+ code += "\t\t\tif (index == 2) limit = 0.1875;\n";
+ code += "\t\t\tif (index == 3) limit = 0.6875;\n";
+ code += "\t\t\tif (index == 4) limit = 0.8125;\n";
+ code += "\t\t\tif (index == 5) limit = 0.3125;\n";
+ code += "\t\t\tif (index == 6) limit = 0.9375;\n";
+ code += "\t\t\tif (index == 7) limit = 0.4375;\n";
+ code += "\t\t\tif (index == 8) limit = 0.25;\n";
+ code += "\t\t\tif (index == 9) limit = 0.75;\n";
+ code += "\t\t\tif (index == 10) limit = 0.125;\n";
+ code += "\t\t\tif (index == 11) limit = 0.625;\n";
+ code += "\t\t\tif (index == 12) limit = 1.0;\n";
+ code += "\t\t\tif (index == 13) limit = 0.5;\n";
+ code += "\t\t\tif (index == 14) limit = 0.875;\n";
+ code += "\t\t\tif (index == 15) limit = 0.375;\n";
+ code += "\t\t}\n\n";
+ code += "\tif (fade < limit)\n";
+ code += "\t\tdiscard;\n";
+ code += "\t}\n\n";
}
- code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n";
- code += "\t\tint x = int(FRAGCOORD.x) % 4;\n";
- code += "\t\tint y = int(FRAGCOORD.y) % 4;\n";
- code += "\t\tint index = x + y * 4;\n";
- code += "\t\tfloat limit = 0.0;\n\n";
- code += "\t\tif (x < 8) {\n";
- code += "\t\t\tif (index == 0) limit = 0.0625;\n";
- code += "\t\t\tif (index == 1) limit = 0.5625;\n";
- code += "\t\t\tif (index == 2) limit = 0.1875;\n";
- code += "\t\t\tif (index == 3) limit = 0.6875;\n";
- code += "\t\t\tif (index == 4) limit = 0.8125;\n";
- code += "\t\t\tif (index == 5) limit = 0.3125;\n";
- code += "\t\t\tif (index == 6) limit = 0.9375;\n";
- code += "\t\t\tif (index == 7) limit = 0.4375;\n";
- code += "\t\t\tif (index == 8) limit = 0.25;\n";
- code += "\t\t\tif (index == 9) limit = 0.75;\n";
- code += "\t\t\tif (index == 10) limit = 0.125;\n";
- code += "\t\t\tif (index == 11) limit = 0.625;\n";
- code += "\t\t\tif (index == 12) limit = 1.0;\n";
- code += "\t\t\tif (index == 13) limit = 0.5;\n";
- code += "\t\t\tif (index == 14) limit = 0.875;\n";
- code += "\t\t\tif (index == 15) limit = 0.375;\n";
- code += "\t\t}\n\n";
- code += "\tif (fade < limit)\n";
- code += "\t\tdiscard;\n";
- code += "\t}\n\n";
-
} else {
code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n";
}
@@ -1371,6 +1371,12 @@ void SpatialMaterial::_validate_feature(const String &text, Feature feature, Pro
}
}
+void SpatialMaterial::_validate_high_end(const String &text, PropertyInfo &property) const {
+ if (property.name.begins_with(text)) {
+ property.usage |= PROPERTY_USAGE_HIGH_END_GFX;
+ }
+}
+
void SpatialMaterial::_validate_property(PropertyInfo &property) const {
_validate_feature("normal", FEATURE_NORMAL_MAPPING, property);
_validate_feature("emission", FEATURE_EMISSION, property);
@@ -1384,6 +1390,12 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const {
_validate_feature("refraction", FEATURE_REFRACTION, property);
_validate_feature("detail", FEATURE_DETAIL, property);
+ _validate_high_end("refraction", property);
+ _validate_high_end("subsurf_scatter", property);
+ _validate_high_end("anisotropy", property);
+ _validate_high_end("clearcoat", property);
+ _validate_high_end("depth", property);
+
if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) {
property.usage = 0;
}