Skip to content

Commit 8085fd3

Browse files
committed
Merge pull request #93142 from clayjohn/z_clip_scale
Add new shader built ins: `Z_CLIP_SCALE` and `PERSPECTIVE_SCALE`
2 parents f129e54 + 9a1def8 commit 8085fd3

File tree

15 files changed

+254
-90
lines changed

15 files changed

+254
-90
lines changed

doc/classes/BaseMaterial3D.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@
229229
<member name="fixed_size" type="bool" setter="set_flag" getter="get_flag" default="false">
230230
If [code]true[/code], the object is rendered at the same size regardless of distance. The object's size on screen is the same as if the camera was [code]1.0[/code] units away from the object's origin, regardless of the actual distance from the camera. The [Camera3D]'s field of view (or [member Camera3D.size] when in orthogonal/frustum mode) still affects the size the object is drawn at.
231231
</member>
232+
<member name="fov_override" type="float" setter="set_fov_override" getter="get_fov_override" default="75.0">
233+
Overrides the [Camera3D]'s field of view angle (in degrees).
234+
[b]Note:[/b] This behaves as if the field of view is set on a [Camera3D] with [member Camera3D.keep_aspect] set to [constant Camera3D.KEEP_HEIGHT]. Additionally, it may not look correct on a non-perspective camera where the field of view setting is ignored.
235+
</member>
232236
<member name="grow" type="bool" setter="set_grow_enabled" getter="is_grow_enabled" default="false">
233237
If [code]true[/code], enables the vertex grow setting. This can be used to create mesh-based outlines using a second material pass and its [member cull_mode] set to [constant CULL_FRONT]. See also [member grow_amount].
234238
[b]Note:[/b] Vertex growth cannot create new vertices, which means that visible gaps may occur in sharp corners. This can be alleviated by designing the mesh to use smooth normals exclusively using [url=http://wiki.polycount.com/wiki/Face_weighted_normals]face weighted normals[/url] in the 3D authoring software. In this case, grow will be able to join every outline together, just like in the original mesh.
@@ -407,13 +411,19 @@
407411
<member name="transparency" type="int" setter="set_transparency" getter="get_transparency" enum="BaseMaterial3D.Transparency" default="0">
408412
The material's transparency mode. Some transparency modes will disable shadow casting. Any transparency mode other than [constant TRANSPARENCY_DISABLED] has a greater performance impact compared to opaque rendering. See also [member blend_mode].
409413
</member>
414+
<member name="use_fov_override" type="bool" setter="set_flag" getter="get_flag" default="false">
415+
If [code]true[/code] use [member fov_override] to override the [Camera3D]'s field of view angle.
416+
</member>
410417
<member name="use_particle_trails" type="bool" setter="set_flag" getter="get_flag" default="false">
411418
If [code]true[/code], enables parts of the shader required for [GPUParticles3D] trails to function. This also requires using a mesh with appropriate skinning, such as [RibbonTrailMesh] or [TubeTrailMesh]. Enabling this feature outside of materials used in [GPUParticles3D] meshes will break material rendering.
412419
</member>
413420
<member name="use_point_size" type="bool" setter="set_flag" getter="get_flag" default="false">
414421
If [code]true[/code], render point size can be changed.
415422
[b]Note:[/b] This is only effective for objects whose geometry is point-based rather than triangle-based. See also [member point_size].
416423
</member>
424+
<member name="use_z_clip_scale" type="bool" setter="set_flag" getter="get_flag" default="false">
425+
If [code]true[/code] use [member z_clip_scale] to scale the object being rendered towards the camera to avoid clipping into things like walls.
426+
</member>
417427
<member name="uv1_offset" type="Vector3" setter="set_uv1_offset" getter="get_uv1_offset" default="Vector3(0, 0, 0)">
418428
How much to offset the [code]UV[/code] coordinates. This amount will be added to [code]UV[/code] in the vertex function. This can be used to offset a texture. The Z component is used when [member uv1_triplanar] is enabled, but it is not used anywhere else.
419429
</member>
@@ -453,6 +463,9 @@
453463
<member name="vertex_color_use_as_albedo" type="bool" setter="set_flag" getter="get_flag" default="false">
454464
If [code]true[/code], the vertex color is used as albedo color.
455465
</member>
466+
<member name="z_clip_scale" type="float" setter="set_z_clip_scale" getter="get_z_clip_scale" default="1.0">
467+
Scales the object being rendered towards the camera to avoid clipping into things like walls. This is intended to be used for objects that are fixed with respect to the camera like player arms, tools, etc. Lighting and shadows will continue to work correctly when this setting is adjusted, but screen-space effects like SSAO and SSR may break with lower scales. Therefore, try to keep this setting as close to [code]1.0[/code] as possible.
468+
</member>
456469
</members>
457470
<constants>
458471
<constant name="TEXTURE_ALBEDO" value="0" enum="TextureParam">
@@ -727,7 +740,13 @@
727740
<constant name="FLAG_DISABLE_SPECULAR_OCCLUSION" value="22" enum="Flags">
728741
Disables specular occlusion.
729742
</constant>
730-
<constant name="FLAG_MAX" value="23" enum="Flags">
743+
<constant name="FLAG_USE_Z_CLIP_SCALE" value="23" enum="Flags">
744+
Enables using [member z_clip_scale].
745+
</constant>
746+
<constant name="FLAG_USE_FOV_OVERRIDE" value="24" enum="Flags">
747+
Enables using [member fov_override].
748+
</constant>
749+
<constant name="FLAG_MAX" value="25" enum="Flags">
731750
Represents the size of the [enum Flags] enum.
732751
</constant>
733752
<constant name="DIFFUSE_BURLEY" value="0" enum="DiffuseMode">

drivers/gles3/shaders/scene.glsl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ LIGHTMAP_BICUBIC_FILTER = false
4646
#define SHADER_IS_SRGB true
4747
#define SHADER_SPACE_FAR -1.0
4848

49+
#if defined(RENDER_SHADOWS) || defined(RENDER_SHADOWS_LINEAR)
50+
#define IN_SHADOW_PASS true
51+
#else
52+
#define IN_SHADOW_PASS false
53+
#endif
54+
4955
#include "stdlib_inc.glsl"
5056

5157
#if !defined(MODE_RENDER_DEPTH) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED) ||defined(LIGHT_CLEARCOAT_USED)
@@ -607,6 +613,10 @@ void main() {
607613
#endif
608614
#endif
609615

616+
#ifdef Z_CLIP_SCALE_USED
617+
float z_clip_scale = 1.0;
618+
#endif
619+
610620
float roughness = 1.0;
611621

612622
highp mat4 modelview = scene_data.view_matrix * model_matrix;
@@ -712,6 +722,12 @@ void main() {
712722
gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
713723
#endif
714724

725+
#if !defined(RENDER_SHADOWS) && !defined(RENDER_SHADOWS_LINEAR)
726+
#ifdef Z_CLIP_SCALE_USED
727+
gl_Position.z = mix(gl_Position.w, gl_Position.z, z_clip_scale);
728+
#endif
729+
#endif
730+
715731
#ifdef RENDER_MATERIAL
716732
vec2 uv_dest_attrib;
717733
if (uv_scale != vec4(0.0)) {
@@ -833,6 +849,12 @@ void main() {
833849
#define SHADER_IS_SRGB true
834850
#define SHADER_SPACE_FAR -1.0
835851

852+
#if defined(RENDER_SHADOWS) || defined(RENDER_SHADOWS_LINEAR)
853+
#define IN_SHADOW_PASS true
854+
#else
855+
#define IN_SHADOW_PASS false
856+
#endif
857+
836858
#define FLAGS_NON_UNIFORM_SCALE (1 << 4)
837859

838860
/* Varyings */

drivers/gles3/storage/material_storage.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ MaterialStorage::MaterialStorage() {
12321232
actions.renames["POINT_SIZE"] = "point_size";
12331233
actions.renames["INSTANCE_ID"] = "gl_InstanceID";
12341234
actions.renames["VERTEX_ID"] = "gl_VertexID";
1235+
actions.renames["Z_CLIP_SCALE"] = "z_clip_scale";
12351236

12361237
actions.renames["ALPHA_SCISSOR_THRESHOLD"] = "alpha_scissor_threshold";
12371238
actions.renames["ALPHA_HASH_SCALE"] = "alpha_hash_scale";
@@ -1247,6 +1248,7 @@ MaterialStorage::MaterialStorage() {
12471248
actions.renames["E"] = String::num(Math::E);
12481249
actions.renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
12491250
actions.renames["CLIP_SPACE_FAR"] = "SHADER_SPACE_FAR";
1251+
actions.renames["IN_SHADOW_PASS"] = "IN_SHADOW_PASS";
12501252
actions.renames["VIEWPORT_SIZE"] = "scene_data.viewport_size";
12511253

12521254
actions.renames["FRAGCOORD"] = "gl_FragCoord";
@@ -1336,6 +1338,7 @@ MaterialStorage::MaterialStorage() {
13361338
actions.usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n";
13371339
actions.usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n";
13381340
actions.usage_defines["LIGHT_VERTEX"] = "#define LIGHT_VERTEX_USED\n";
1341+
actions.usage_defines["Z_CLIP_SCALE"] = "#define Z_CLIP_SCALE_USED\n";
13391342

13401343
actions.usage_defines["ALPHA_SCISSOR_THRESHOLD"] = "#define ALPHA_SCISSOR_USED\n";
13411344
actions.usage_defines["ALPHA_HASH_SCALE"] = "#define ALPHA_HASH_USED\n";

scene/resources/material.cpp

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ void BaseMaterial3D::init_shaders() {
666666

667667
shader_names->alpha_antialiasing_edge = "alpha_antialiasing_edge";
668668
shader_names->albedo_texture_size = "albedo_texture_size";
669+
shader_names->z_clip_scale = "z_clip_scale";
670+
shader_names->fov_override = "fov_override";
669671
}
670672

671673
HashMap<uint64_t, Ref<StandardMaterial3D>> BaseMaterial3D::materials_for_2d;
@@ -1135,6 +1137,14 @@ uniform vec3 uv2_scale;
11351137
uniform vec3 uv2_offset;
11361138
)";
11371139

1140+
if (flags[FLAG_USE_Z_CLIP_SCALE]) {
1141+
code += "uniform float z_clip_scale : hint_range(0.01, 1.0, 0.01);\n";
1142+
}
1143+
1144+
if (flags[FLAG_USE_FOV_OVERRIDE]) {
1145+
code += "uniform float fov_override : hint_range(1.0, 179.0, 0.1);\n";
1146+
}
1147+
11381148
// Generate vertex shader.
11391149
code += R"(
11401150
void vertex() {)";
@@ -1378,6 +1388,25 @@ void vertex() {)";
13781388
)";
13791389
}
13801390

1391+
if (flags[FLAG_USE_Z_CLIP_SCALE]) {
1392+
code += R"(
1393+
Z_CLIP_SCALE = z_clip_scale;
1394+
)";
1395+
}
1396+
1397+
if (flags[FLAG_USE_FOV_OVERRIDE]) {
1398+
code += R"(
1399+
if (!IN_SHADOW_PASS) {
1400+
float flip_y = sign(PROJECTION_MATRIX[1][1]);
1401+
float aspect = PROJECTION_MATRIX[1][1] / PROJECTION_MATRIX[0][0];
1402+
float f = flip_y / tan(fov_override * PI / 360.0);
1403+
PROJECTION_MATRIX[0][0] = f / aspect;
1404+
PROJECTION_MATRIX[1][1] = f;
1405+
}
1406+
)";
1407+
}
1408+
1409+
// End of the vertex shader function.
13811410
code += "}\n";
13821411

13831412
if (flags[FLAG_ALBEDO_TEXTURE_MSDF] && !flags[FLAG_UV1_USE_TRIPLANAR]) {
@@ -2375,7 +2404,9 @@ void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) {
23752404
p_flag == FLAG_SUBSURFACE_MODE_SKIN ||
23762405
p_flag == FLAG_USE_POINT_SIZE ||
23772406
p_flag == FLAG_UV1_USE_TRIPLANAR ||
2378-
p_flag == FLAG_UV2_USE_TRIPLANAR) {
2407+
p_flag == FLAG_UV2_USE_TRIPLANAR ||
2408+
p_flag == FLAG_USE_Z_CLIP_SCALE ||
2409+
p_flag == FLAG_USE_FOV_OVERRIDE) {
23792410
notify_property_list_changed();
23802411
}
23812412

@@ -2510,6 +2541,14 @@ void BaseMaterial3D::_validate_property(PropertyInfo &p_property) const {
25102541
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
25112542
}
25122543

2544+
if (p_property.name == "z_clip_scale" && !flags[FLAG_USE_Z_CLIP_SCALE]) {
2545+
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
2546+
}
2547+
2548+
if (p_property.name == "fov_override" && !flags[FLAG_USE_FOV_OVERRIDE]) {
2549+
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
2550+
}
2551+
25132552
// you can only enable anti-aliasing (in materials) on alpha scissor and alpha hash
25142553
const bool can_select_aa = (transparency == TRANSPARENCY_ALPHA_SCISSOR || transparency == TRANSPARENCY_ALPHA_HASH);
25152554
// alpha anti aliasiasing is only enabled when you can select aa
@@ -2860,6 +2899,24 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel()
28602899
return refraction_texture_channel;
28612900
}
28622901

2902+
void BaseMaterial3D::set_z_clip_scale(float p_z_clip_scale) {
2903+
z_clip_scale = p_z_clip_scale;
2904+
_material_set_param(shader_names->z_clip_scale, p_z_clip_scale);
2905+
}
2906+
2907+
float BaseMaterial3D::get_z_clip_scale() const {
2908+
return z_clip_scale;
2909+
}
2910+
2911+
void BaseMaterial3D::set_fov_override(float p_fov_override) {
2912+
fov_override = p_fov_override;
2913+
_material_set_param(shader_names->fov_override, p_fov_override);
2914+
}
2915+
2916+
float BaseMaterial3D::get_fov_override() const {
2917+
return fov_override;
2918+
}
2919+
28632920
Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard, bool p_billboard_y, bool p_msdf, bool p_no_depth, bool p_fixed_size, TextureFilter p_filter, AlphaAntiAliasing p_alpha_antialiasing_mode, RID *r_shader_rid) {
28642921
uint64_t key = 0;
28652922
key |= ((int8_t)p_shaded & 0x01) << 0;
@@ -3212,6 +3269,12 @@ void BaseMaterial3D::_bind_methods() {
32123269
ClassDB::bind_method(D_METHOD("set_distance_fade_min_distance", "distance"), &BaseMaterial3D::set_distance_fade_min_distance);
32133270
ClassDB::bind_method(D_METHOD("get_distance_fade_min_distance"), &BaseMaterial3D::get_distance_fade_min_distance);
32143271

3272+
ClassDB::bind_method(D_METHOD("set_z_clip_scale", "scale"), &BaseMaterial3D::set_z_clip_scale);
3273+
ClassDB::bind_method(D_METHOD("get_z_clip_scale"), &BaseMaterial3D::get_z_clip_scale);
3274+
3275+
ClassDB::bind_method(D_METHOD("set_fov_override", "scale"), &BaseMaterial3D::set_fov_override);
3276+
ClassDB::bind_method(D_METHOD("get_fov_override"), &BaseMaterial3D::get_fov_override);
3277+
32153278
ADD_GROUP("Transparency", "");
32163279
ADD_PROPERTY(PropertyInfo(Variant::INT, "transparency", PROPERTY_HINT_ENUM, "Disabled,Alpha,Alpha Scissor,Alpha Hash,Depth Pre-Pass"), "set_transparency", "get_transparency");
32173280
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "alpha_scissor_threshold", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_alpha_scissor_threshold", "get_alpha_scissor_threshold");
@@ -3381,7 +3444,10 @@ void BaseMaterial3D::_bind_methods() {
33813444
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_point_size"), "set_flag", "get_flag", FLAG_USE_POINT_SIZE);
33823445
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "point_size", PROPERTY_HINT_RANGE, "0.1,128,0.1,suffix:px"), "set_point_size", "get_point_size");
33833446
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_particle_trails"), "set_flag", "get_flag", FLAG_PARTICLE_TRAILS_MODE);
3384-
3447+
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_z_clip_scale"), "set_flag", "get_flag", FLAG_USE_Z_CLIP_SCALE);
3448+
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "z_clip_scale", PROPERTY_HINT_RANGE, "0.01,1.0,0.01"), "set_z_clip_scale", "get_z_clip_scale");
3449+
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_fov_override"), "set_flag", "get_flag", FLAG_USE_FOV_OVERRIDE);
3450+
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov_override", PROPERTY_HINT_RANGE, "1,179,0.1,degrees"), "set_fov_override", "get_fov_override");
33853451
ADD_GROUP("Proximity Fade", "proximity_fade_");
33863452
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "proximity_fade_enabled"), "set_proximity_fade_enabled", "is_proximity_fade_enabled");
33873453
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "proximity_fade_distance", PROPERTY_HINT_RANGE, "0.01,4096,0.01,suffix:m"), "set_proximity_fade_distance", "get_proximity_fade_distance");
@@ -3495,6 +3561,8 @@ void BaseMaterial3D::_bind_methods() {
34953561
BIND_ENUM_CONSTANT(FLAG_ALBEDO_TEXTURE_MSDF);
34963562
BIND_ENUM_CONSTANT(FLAG_DISABLE_FOG);
34973563
BIND_ENUM_CONSTANT(FLAG_DISABLE_SPECULAR_OCCLUSION);
3564+
BIND_ENUM_CONSTANT(FLAG_USE_Z_CLIP_SCALE);
3565+
BIND_ENUM_CONSTANT(FLAG_USE_FOV_OVERRIDE);
34983566
BIND_ENUM_CONSTANT(FLAG_MAX);
34993567

35003568
BIND_ENUM_CONSTANT(DIFFUSE_BURLEY);
@@ -3589,6 +3657,9 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
35893657
set_heightmap_deep_parallax_max_layers(32);
35903658
set_heightmap_deep_parallax_flip_tangent(false); //also sets binormal
35913659

3660+
set_z_clip_scale(1.0);
3661+
set_fov_override(75.0);
3662+
35923663
flags[FLAG_ALBEDO_TEXTURE_MSDF] = false;
35933664
flags[FLAG_USE_TEXTURE_REPEAT] = true;
35943665

scene/resources/material.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ class BaseMaterial3D : public Material {
269269
FLAG_ALBEDO_TEXTURE_MSDF,
270270
FLAG_DISABLE_FOG,
271271
FLAG_DISABLE_SPECULAR_OCCLUSION,
272+
FLAG_USE_Z_CLIP_SCALE,
273+
FLAG_USE_FOV_OVERRIDE,
272274
FLAG_MAX
273275
};
274276

@@ -466,6 +468,8 @@ class BaseMaterial3D : public Material {
466468

467469
StringName alpha_antialiasing_edge;
468470
StringName albedo_texture_size;
471+
StringName z_clip_scale;
472+
StringName fov_override;
469473
};
470474

471475
static Mutex material_mutex;
@@ -563,6 +567,9 @@ class BaseMaterial3D : public Material {
563567

564568
AlphaAntiAliasing alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF;
565569

570+
float z_clip_scale = 1.0;
571+
float fov_override = 75.0;
572+
566573
bool features[FEATURE_MAX] = {};
567574

568575
Ref<Texture2D> textures[TEXTURE_MAX];
@@ -782,6 +789,11 @@ class BaseMaterial3D : public Material {
782789
void set_refraction_texture_channel(TextureChannel p_channel);
783790
TextureChannel get_refraction_texture_channel() const;
784791

792+
void set_z_clip_scale(float p_z_clip_scale);
793+
float get_z_clip_scale() const;
794+
void set_fov_override(float p_fov_override);
795+
float get_fov_override() const;
796+
785797
static void init_shaders();
786798
static void finish_shaders();
787799
static void flush_changes();

servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,7 @@ void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const Page
27442744
scene_data.time = time;
27452745
scene_data.time_step = time_step;
27462746
scene_data.main_cam_transform = p_main_cam_transform;
2747+
scene_data.shadow_pass = true;
27472748

27482749
RenderDataRD render_data;
27492750
render_data.scene_data = &scene_data;
@@ -2836,6 +2837,7 @@ void RenderForwardClustered::_render_particle_collider_heightfield(RID p_fb, con
28362837
scene_data.time = time;
28372838
scene_data.time_step = time_step;
28382839
scene_data.main_cam_transform = p_cam_transform;
2840+
scene_data.shadow_pass = true; // Not a shadow pass, but should be treated like one.
28392841

28402842
RenderDataRD render_data;
28412843
render_data.scene_data = &scene_data;

servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
7979
writes_modelview_or_projection = false;
8080
uses_world_coordinates = false;
8181
uses_particle_trails = false;
82+
uses_z_clip_scale = false;
8283

8384
int depth_drawi = DEPTH_DRAW_OPAQUE;
8485

@@ -140,6 +141,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
140141
actions.write_flag_pointers["PROJECTION_MATRIX"] = &writes_modelview_or_projection;
141142
actions.write_flag_pointers["VERTEX"] = &uses_vertex;
142143
actions.write_flag_pointers["POSITION"] = &uses_position;
144+
actions.write_flag_pointers["Z_CLIP_SCALE"] = &uses_z_clip_scale;
143145

144146
actions.uniforms = &uniforms;
145147

@@ -613,6 +615,7 @@ void SceneShaderForwardClustered::init(const String p_defines) {
613615
actions.renames["POINT_SIZE"] = "gl_PointSize";
614616
actions.renames["INSTANCE_ID"] = "gl_InstanceIndex";
615617
actions.renames["VERTEX_ID"] = "gl_VertexIndex";
618+
actions.renames["Z_CLIP_SCALE"] = "z_clip_scale";
616619

617620
actions.renames["ALPHA_SCISSOR_THRESHOLD"] = "alpha_scissor_threshold";
618621
actions.renames["ALPHA_HASH_SCALE"] = "alpha_hash_scale";
@@ -628,6 +631,7 @@ void SceneShaderForwardClustered::init(const String p_defines) {
628631
actions.renames["E"] = String::num(Math::E);
629632
actions.renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
630633
actions.renames["CLIP_SPACE_FAR"] = "SHADER_SPACE_FAR";
634+
actions.renames["IN_SHADOW_PASS"] = "bool(scene_data_block.data.flags & SCENE_DATA_FLAGS_IN_SHADOW_PASS)";
631635
actions.renames["VIEWPORT_SIZE"] = "read_viewport_size";
632636

633637
actions.renames["FRAGCOORD"] = "gl_FragCoord";
@@ -717,12 +721,13 @@ void SceneShaderForwardClustered::init(const String p_defines) {
717721
actions.usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n";
718722
actions.usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n";
719723
actions.usage_defines["LIGHT_VERTEX"] = "#define LIGHT_VERTEX_USED\n";
720-
actions.usage_defines["PREMUL_ALPHA_FACTOR"] = "#define PREMUL_ALPHA_USED\n";
724+
actions.usage_defines["Z_CLIP_SCALE"] = "#define Z_CLIP_SCALE_USED\n";
721725

722726
actions.usage_defines["ALPHA_SCISSOR_THRESHOLD"] = "#define ALPHA_SCISSOR_USED\n";
723727
actions.usage_defines["ALPHA_HASH_SCALE"] = "#define ALPHA_HASH_USED\n";
724728
actions.usage_defines["ALPHA_ANTIALIASING_EDGE"] = "#define ALPHA_ANTIALIASING_EDGE_USED\n";
725729
actions.usage_defines["ALPHA_TEXTURE_COORDINATE"] = "@ALPHA_ANTIALIASING_EDGE";
730+
actions.usage_defines["PREMUL_ALPHA_FACTOR"] = "#define PREMUL_ALPHA_USED\n";
726731

727732
actions.usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n";
728733
actions.usage_defines["SSS_TRANSMITTANCE_DEPTH"] = "#define ENABLE_TRANSMITTANCE\n";

servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class SceneShaderForwardClustered {
245245
bool writes_modelview_or_projection = false;
246246
bool uses_world_coordinates = false;
247247
bool uses_screen_texture_mipmaps = false;
248+
bool uses_z_clip_scale = false;
248249
RS::CullMode cull_mode = RS::CULL_MODE_DISABLED;
249250

250251
uint64_t last_pass = 0;
@@ -268,7 +269,7 @@ class SceneShaderForwardClustered {
268269

269270
_FORCE_INLINE_ bool uses_shared_shadow_material() const {
270271
bool backface_culling = cull_mode == RS::CULL_MODE_BACK;
271-
return !uses_particle_trails && !writes_modelview_or_projection && !uses_vertex && !uses_position && !uses_discard && !uses_depth_prepass_alpha && !uses_alpha_clip && !uses_alpha_antialiasing && backface_culling && !uses_point_size && !uses_world_coordinates && !wireframe;
272+
return !uses_particle_trails && !writes_modelview_or_projection && !uses_vertex && !uses_position && !uses_discard && !uses_depth_prepass_alpha && !uses_alpha_clip && !uses_alpha_antialiasing && backface_culling && !uses_point_size && !uses_world_coordinates && !wireframe && !uses_z_clip_scale;
272273
}
273274

274275
virtual void set_code(const String &p_Code);

0 commit comments

Comments
 (0)