Skip to content

Commit bd8ef69

Browse files
author
L Sikkes
committed
Simple shadows now a project setting & alpha hint to make custom shaders compatible with simple shadow mode
1 parent 4b90abe commit bd8ef69

23 files changed

Lines changed: 105 additions & 78 deletions

doc/classes/Environment.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@
220220
Number of ray samples cast per pixel per frame. Higher values reduce noise but increase GPU cost proportionally. When using a temporal denoiser such as DLSS Ray Reconstruction, a low sample count (1-2) is typically sufficient since the denoiser accumulates information across frames.
221221
[b]Note:[/b] Only has an effect when [member pathtracing_enabled] is [code]true[/code].
222222
</member>
223-
<member name="pathtracing_use_simple_shadows" type="bool" setter="set_pathtracing_use_simple_shadows" getter="is_pathtracing_using_simple_shadows" default="true">
224-
Whether Ray Queries or fully traced rays should be used for shadow rays. Ray Queries are significantly cheaper, but rely on a quick alpha estimation.
225-
If you have materials with changing alpha textures Ray Queries will result in wrong shadows.
226-
</member>
227223
<member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0">
228224
The reflected (specular) light source.
229225
</member>

doc/classes/ProjectSettings.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,30 +3245,34 @@
32453245
[b]Note:[/b] Enabling occlusion culling has a cost on the CPU. Only enable occlusion culling if you actually plan to use it. Large open scenes with few or no objects blocking the view will generally not benefit much from occlusion culling. Large open scenes generally benefit more from mesh LOD and visibility ranges ([member GeometryInstance3D.visibility_range_begin] and [member GeometryInstance3D.visibility_range_end]) compared to occlusion culling.
32463246
[b]Note:[/b] Due to memory constraints, occlusion culling is not supported by default in Web export templates. It can be enabled by compiling custom Web export templates with [code]module_raycast_enabled=yes[/code].
32473247
</member>
3248-
<member name="rendering/pathtracer/async_shader_compilation" type="bool" setter="" getter="" default="true">
3248+
<member name="rendering/pathtracing/async_shader_compilation" type="bool" setter="" getter="" default="true">
32493249
If [code]true[/code], path tracing ray hit shaders are compiled asynchronously in the background. This avoids frame stalls when new shader variants are first encountered during rendering. While a shader is compiling, a fallback shader may be used, which can cause temporary visual artifacts. Disable this if you require fully deterministic rendering from the first frame at the cost of potential stalls on shader warm-up.
32503250
</member>
3251-
<member name="rendering/pathtracer/deformed_mesh_cache_ttl_frames" type="int" setter="" getter="" default="60">
3251+
<member name="rendering/pathtracing/deformed_mesh_cache_ttl_frames" type="int" setter="" getter="" default="60">
32523252
Number of frames a skinned or vertex-displaced deformed-mesh BLAS is kept alive in the path tracer cache after its last visible frame. Once this threshold is exceeded the BLAS and its associated buffers are freed. Increase this value if deformed meshes flicker back into view after brief occlusion; decrease it to reclaim GPU memory sooner.
32533253
[b]Note:[/b] Requires a restart to take effect.
32543254
</member>
3255-
<member name="rendering/pathtracer/multimesh_blas_cache_ttl_frames" type="int" setter="" getter="" default="3600">
3255+
<member name="rendering/pathtracing/multimesh_blas_cache_ttl_frames" type="int" setter="" getter="" default="3600">
32563256
Number of frames a merged MultiMesh BLAS is kept alive in the path tracer cache after its last visible frame. At 60 fps, the default of 3600 corresponds to approximately one minute. Once this threshold is exceeded the BLAS and all merged vertex, attribute, and index buffers are freed. Decrease this value to reclaim GPU memory when MultiMeshes disappear from the scene.
32573257
[b]Note:[/b] Requires a restart to take effect.
32583258
</member>
3259-
<member name="rendering/pathtracer/multimesh_cache_cpu_transforms" type="bool" setter="" getter="" default="false">
3259+
<member name="rendering/pathtracing/multimesh_cache_cpu_transforms" type="bool" setter="" getter="" default="false">
32603260
When enabled, setting [member MultiMesh.buffer] keeps a CPU-side mirror of the instance transform data in sync with the GPU buffer. This allows the path tracer to read per-instance transforms without performing a GPU-to-CPU readback on first access, eliminating the one-time stall that occurs otherwise.
32613261
[b]Warning:[/b] Enabling this setting increases CPU memory usage. Every [MultiMesh] that assigns [member MultiMesh.buffer] will maintain a full duplicate of its transform data in RAM.
32623262
Enable this only when [MultiMesh] nodes with frequently updated transforms are present in path-traced scenes and the GPU readback stall is measurable.
32633263
[b]Note:[/b] Requires a restart to take effect.
32643264
</member>
3265-
<member name="rendering/pathtracer/multimesh_merged_blas_max_triangles" type="int" setter="" getter="" default="65536">
3265+
<member name="rendering/pathtracing/multimesh_merged_blas_max_triangles" type="int" setter="" getter="" default="65536">
32663266
Maximum total triangle count ([code]instance_count * triangles_per_surface[/code]) for a [MultiMesh] surface to use a single merged BLAS in the path tracer. When the combined triangle count exceeds this value, the path tracer falls back to one TLAS entry per instance sharing a common BLAS instead. Lower this value to reduce peak GPU memory for large MultiMeshes; raise it to prefer the merged path (which avoids per-instance TLAS overhead).
32673267
[b]Note:[/b] Requires a restart to take effect.
32683268
</member>
3269-
<member name="rendering/pathtracer/use_shader_execution_reordering" type="bool" setter="" getter="" default="true">
3269+
<member name="rendering/pathtracing/use_shader_execution_reordering" type="bool" setter="" getter="" default="true">
32703270
If [code]true[/code], enables NVIDIA Shader Execution Reordering in the path tracer. SET reorders ray tracing shader invocations at runtime to improve GPU occupancy and reduce divergence between threads executing different materials. This can significantly improve path tracing performance on NVIDIA Ada Lovelace and later GPUs. Has no effect on hardware that does not support SET.
32713271
</member>
3272+
<member name="rendering/pathtracing/use_simple_shadows" type="bool" setter="" getter="" default="false">
3273+
If [code]true[/code], shadow rays use Ray Queries instead of fully traced rays. Ray Queries are significantly cheaper but rely on a quick alpha texture fetch, which can produce incorrect shadows on materials with generated/animated alpha textures. Fully traced shadow rays are more accurate but incur a higher GPU cost.
3274+
[b]Note:[/b] Only has an effect when path tracing is enabled on the active [Environment].
3275+
</member>
32723276
<member name="rendering/reflections/reflection_atlas/reflection_count" type="int" setter="" getter="" default="64">
32733277
Number of cubemaps to store in the reflection atlas. The number of [ReflectionProbe]s in a scene will be limited by this amount. A higher number requires more VRAM.
32743278
</member>

doc/classes/RenderingServer.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,6 @@
14071407
<param index="3" name="samples_per_pixel" type="int" />
14081408
<param index="4" name="max_bounces" type="int" />
14091409
<param index="5" name="denoiser" type="int" enum="RenderingServer.PathtracingDenoiser" />
1410-
<param index="6" name="use_simple_shadows" type="bool" />
14111410
<description>
14121411
</description>
14131412
</method>

modules/visual_shader/doc_classes/VisualShaderNodeTextureParameter.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeTextureParameter.TextureType" default="0">
2525
Defines the type of data provided by the source texture.
2626
</member>
27+
<member name="alpha_hint" type="bool" setter="set_alpha_hint" getter="get_alpha_hint" default="false">
28+
If [code]true[/code], adds [code]hint_alpha[/code] to the uniform declaration. This marks the texture's alpha channel as the source of opacity for path tracing ray query alpha tests (simple shadows and Opacity Micromap baking). Can be combined with any [member texture_type], for example [constant TYPE_COLOR] for a color-plus-alpha albedo texture or [constant TYPE_DATA] for a dedicated grayscale alpha mask.
29+
</member>
2730
</members>
2831
<constants>
2932
<constant name="TYPE_DATA" value="0" enum="TextureType">

modules/visual_shader/vs_nodes/visual_shader_nodes.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6390,7 +6390,7 @@ VisualShaderNodeTransformParameter::VisualShaderNodeTransformParameter() {
63906390

63916391
//////////////
63926392

6393-
String get_sampler_hint(VisualShaderNodeTextureParameter::TextureType p_texture_type, VisualShaderNodeTextureParameter::ColorDefault p_color_default, VisualShaderNodeTextureParameter::TextureFilter p_texture_filter, VisualShaderNodeTextureParameter::TextureRepeat p_texture_repeat, VisualShaderNodeTextureParameter::TextureSource p_texture_source) {
6393+
String get_sampler_hint(VisualShaderNodeTextureParameter::TextureType p_texture_type, bool p_alpha_hint, VisualShaderNodeTextureParameter::ColorDefault p_color_default, VisualShaderNodeTextureParameter::TextureFilter p_texture_filter, VisualShaderNodeTextureParameter::TextureRepeat p_texture_repeat, VisualShaderNodeTextureParameter::TextureSource p_texture_source) {
63946394
String code;
63956395
bool has_colon = false;
63966396

@@ -6428,6 +6428,11 @@ String get_sampler_hint(VisualShaderNodeTextureParameter::TextureType p_texture_
64286428
code += " : " + type_code;
64296429
has_colon = true;
64306430
}
6431+
6432+
if (p_alpha_hint) {
6433+
code += has_colon ? ", hint_alpha" : " : hint_alpha";
6434+
has_colon = true;
6435+
}
64316436
}
64326437

64336438
// filter
@@ -6569,6 +6574,18 @@ VisualShaderNodeTextureParameter::TextureType VisualShaderNodeTextureParameter::
65696574
return texture_type;
65706575
}
65716576

6577+
void VisualShaderNodeTextureParameter::set_alpha_hint(bool p_alpha_hint) {
6578+
if (alpha_hint == p_alpha_hint) {
6579+
return;
6580+
}
6581+
alpha_hint = p_alpha_hint;
6582+
emit_changed();
6583+
}
6584+
6585+
bool VisualShaderNodeTextureParameter::get_alpha_hint() const {
6586+
return alpha_hint;
6587+
}
6588+
65726589
void VisualShaderNodeTextureParameter::set_color_default(ColorDefault p_color_default) {
65736590
ERR_FAIL_INDEX(int(p_color_default), int(COLOR_DEFAULT_MAX));
65746591
if (color_default == p_color_default) {
@@ -6626,6 +6643,7 @@ Vector<StringName> VisualShaderNodeTextureParameter::get_editable_properties() c
66266643
props.push_back("texture_type");
66276644
if (texture_type == TYPE_DATA || texture_type == TYPE_COLOR) {
66286645
props.push_back("color_default");
6646+
props.push_back("alpha_hint");
66296647
}
66306648
props.push_back("texture_filter");
66316649
props.push_back("texture_repeat");
@@ -6711,6 +6729,9 @@ void VisualShaderNodeTextureParameter::_bind_methods() {
67116729
ClassDB::bind_method(D_METHOD("set_texture_type", "type"), &VisualShaderNodeTextureParameter::set_texture_type);
67126730
ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeTextureParameter::get_texture_type);
67136731

6732+
ClassDB::bind_method(D_METHOD("set_alpha_hint", "alpha_hint"), &VisualShaderNodeTextureParameter::set_alpha_hint);
6733+
ClassDB::bind_method(D_METHOD("get_alpha_hint"), &VisualShaderNodeTextureParameter::get_alpha_hint);
6734+
67146735
ClassDB::bind_method(D_METHOD("set_color_default", "color"), &VisualShaderNodeTextureParameter::set_color_default);
67156736
ClassDB::bind_method(D_METHOD("get_color_default"), &VisualShaderNodeTextureParameter::get_color_default);
67166737

@@ -6724,6 +6745,7 @@ void VisualShaderNodeTextureParameter::_bind_methods() {
67246745
ClassDB::bind_method(D_METHOD("get_texture_source"), &VisualShaderNodeTextureParameter::get_texture_source);
67256746

67266747
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normal Map,Anisotropic"), "set_texture_type", "get_texture_type");
6748+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alpha_hint"), "set_alpha_hint", "get_alpha_hint");
67276749
ADD_PROPERTY(PropertyInfo(Variant::INT, "color_default", PROPERTY_HINT_ENUM, "White,Black,Transparent"), "set_color_default", "get_color_default");
67286750
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Default,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
67296751
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Default,Enabled,Disabled"), "set_texture_repeat", "get_texture_repeat");
@@ -6801,7 +6823,7 @@ String VisualShaderNodeTexture2DParameter::get_output_port_name(int p_port) cons
68016823

68026824
String VisualShaderNodeTexture2DParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
68036825
String code = _get_qual_str() + "uniform sampler2D " + get_parameter_name();
6804-
code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
6826+
code += get_sampler_hint(texture_type, alpha_hint, color_default, texture_filter, texture_repeat, texture_source);
68056827
code += ";\n";
68066828
return code;
68076829
}
@@ -6901,7 +6923,7 @@ String VisualShaderNodeTextureParameterTriplanar::generate_global_per_func(Shade
69016923

69026924
String VisualShaderNodeTextureParameterTriplanar::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
69036925
String code = _get_qual_str() + "uniform sampler2D " + get_parameter_name();
6904-
code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
6926+
code += get_sampler_hint(texture_type, alpha_hint, color_default, texture_filter, texture_repeat, texture_source);
69056927
code += ";\n";
69066928
return code;
69076929
}
@@ -6947,7 +6969,7 @@ String VisualShaderNodeTexture2DArrayParameter::get_output_port_name(int p_port)
69476969

69486970
String VisualShaderNodeTexture2DArrayParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
69496971
String code = _get_qual_str() + "uniform sampler2DArray " + get_parameter_name();
6950-
code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
6972+
code += get_sampler_hint(texture_type, alpha_hint, color_default, texture_filter, texture_repeat, texture_source);
69516973
code += ";\n";
69526974
return code;
69536975
}
@@ -6967,7 +6989,7 @@ String VisualShaderNodeTexture3DParameter::get_output_port_name(int p_port) cons
69676989

69686990
String VisualShaderNodeTexture3DParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
69696991
String code = _get_qual_str() + "uniform sampler3D " + get_parameter_name();
6970-
code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
6992+
code += get_sampler_hint(texture_type, alpha_hint, color_default, texture_filter, texture_repeat, texture_source);
69716993
code += ";\n";
69726994
return code;
69736995
}
@@ -6987,7 +7009,7 @@ String VisualShaderNodeCubemapParameter::get_output_port_name(int p_port) const
69877009

69887010
String VisualShaderNodeCubemapParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
69897011
String code = _get_qual_str() + "uniform samplerCube " + get_parameter_name();
6990-
code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
7012+
code += get_sampler_hint(texture_type, alpha_hint, color_default, texture_filter, texture_repeat, texture_source);
69917013
code += ";\n";
69927014
return code;
69937015
}

modules/visual_shader/vs_nodes/visual_shader_nodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,7 @@ class VisualShaderNodeTextureParameter : public VisualShaderNodeParameter {
25462546

25472547
protected:
25482548
TextureType texture_type = TYPE_DATA;
2549+
bool alpha_hint = false;
25492550
ColorDefault color_default = COLOR_DEFAULT_WHITE;
25502551
TextureFilter texture_filter = FILTER_DEFAULT;
25512552
TextureRepeat texture_repeat = REPEAT_DEFAULT;
@@ -2573,6 +2574,9 @@ class VisualShaderNodeTextureParameter : public VisualShaderNodeParameter {
25732574
void set_texture_type(TextureType p_type);
25742575
TextureType get_texture_type() const;
25752576

2577+
void set_alpha_hint(bool p_alpha_hint);
2578+
bool get_alpha_hint() const;
2579+
25762580
void set_color_default(ColorDefault p_default);
25772581
ColorDefault get_color_default() const;
25782582

scene/resources/environment.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -650,24 +650,14 @@ RSE::PathtracingDenoiser Environment::get_pathtracing_denoiser() const {
650650
return pathtracing_denoiser;
651651
}
652652

653-
void Environment::set_pathtracing_use_simple_shadows(bool p_enabled) {
654-
pathtracing_use_simple_shadows = p_enabled;
655-
_update_pathtracing();
656-
}
657-
658-
bool Environment::is_pathtracing_using_simple_shadows() const {
659-
return pathtracing_use_simple_shadows;
660-
}
661-
662653
void Environment::_update_pathtracing() {
663654
RS::get_singleton()->environment_set_pathtracing(
664655
environment,
665656
pathtracing_enabled,
666657
(int)pathtracing_debug_mode,
667658
pathtracing_samples_per_pixel,
668659
pathtracing_max_bounces,
669-
pathtracing_denoiser,
670-
pathtracing_use_simple_shadows);
660+
pathtracing_denoiser);
671661
}
672662

673663
// Glow
@@ -1509,16 +1499,14 @@ void Environment::_bind_methods() {
15091499
ClassDB::bind_method(D_METHOD("get_pathtracing_max_bounces"), &Environment::get_pathtracing_max_bounces);
15101500
ClassDB::bind_method(D_METHOD("set_pathtracing_denoiser", "denoiser"), &Environment::set_pathtracing_denoiser);
15111501
ClassDB::bind_method(D_METHOD("get_pathtracing_denoiser"), &Environment::get_pathtracing_denoiser);
1512-
ClassDB::bind_method(D_METHOD("set_pathtracing_use_simple_shadows", "enabled"), &Environment::set_pathtracing_use_simple_shadows);
1513-
ClassDB::bind_method(D_METHOD("is_pathtracing_using_simple_shadows"), &Environment::is_pathtracing_using_simple_shadows);
1502+
GLOBAL_DEF("rendering/pathtracing/use_simple_shadows", false);
15141503

15151504
ADD_GROUP("Pathtracing", "pathtracing_");
15161505
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pathtracing_enabled", PROPERTY_HINT_GROUP_ENABLE), "set_pathtracing_enabled", "is_pathtracing_enabled");
15171506
ADD_PROPERTY(PropertyInfo(Variant::INT, "pathtracing_debug_mode", PROPERTY_HINT_ENUM, "Disabled,Mirror Reflection,Geometry Normals,Final Normals,Normal Map,Tangent,Bitangent,UV,Albedo,ORM,Diffuse Albedo,Specular Albedo,Normal+Roughness,Specular Hit Dist,Metalness,Roughness,View Normals,Diffuse+Specular,Fresnel F0,Front/Back Face,Depth,Emissive,BRDF Rejection"), "set_pathtracing_debug_mode", "get_pathtracing_debug_mode");
15181507
ADD_PROPERTY(PropertyInfo(Variant::INT, "pathtracing_samples_per_pixel", PROPERTY_HINT_RANGE, "1,16,1"), "set_pathtracing_samples_per_pixel", "get_pathtracing_samples_per_pixel");
15191508
ADD_PROPERTY(PropertyInfo(Variant::INT, "pathtracing_max_bounces", PROPERTY_HINT_RANGE, "1,8,1"), "set_pathtracing_max_bounces", "get_pathtracing_max_bounces");
15201509
ADD_PROPERTY(PropertyInfo(Variant::INT, "pathtracing_denoiser", PROPERTY_HINT_ENUM, "None,DLSS Ray Reconstruction"), "set_pathtracing_denoiser", "get_pathtracing_denoiser");
1521-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pathtracing_use_simple_shadows"), "set_pathtracing_use_simple_shadows", "is_pathtracing_using_simple_shadows");
15221510

15231511
// Glow
15241512

scene/resources/environment.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ class Environment : public Resource {
196196
int pathtracing_samples_per_pixel = 1;
197197
int pathtracing_max_bounces = 3;
198198
RSE::PathtracingDenoiser pathtracing_denoiser = RSE::PT_DENOISER_DLSS_RAY_RECONSTRUCTION;
199-
bool pathtracing_use_simple_shadows = true;
200199
void _update_pathtracing();
201200

202201
// Glow
@@ -397,8 +396,6 @@ class Environment : public Resource {
397396
int get_pathtracing_max_bounces() const;
398397
void set_pathtracing_denoiser(RSE::PathtracingDenoiser p_denoiser);
399398
RSE::PathtracingDenoiser get_pathtracing_denoiser() const;
400-
void set_pathtracing_use_simple_shadows(bool p_enabled);
401-
bool is_pathtracing_using_simple_shadows() const;
402399

403400
// Glow
404401
void set_glow_enabled(bool p_enabled);

0 commit comments

Comments
 (0)