diff options
Diffstat (limited to 'servers/rendering/renderer_rd')
11 files changed, 45 insertions, 26 deletions
diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index 768bd1de9d..71753f9694 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -44,7 +44,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { uniforms.clear(); uses_screen_texture = false; - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp index e6d9a60f94..8807ebf134 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp @@ -47,7 +47,7 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) { uniforms.clear(); uses_screen_texture = false; - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index d013099cce..2ff7f27d33 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -1953,7 +1953,7 @@ void RendererCanvasRenderRD::ShaderData::set_code(const String &p_code) { uses_sdf = false; uses_time = false; - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index 522a8e8112..d310becd1e 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -240,7 +240,7 @@ RendererCompositorRD *RendererCompositorRD::singleton = nullptr; RendererCompositorRD::RendererCompositorRD() { { String shader_cache_dir = Engine::get_singleton()->get_shader_cache_path(); - if (shader_cache_dir == String()) { + if (shader_cache_dir.is_empty()) { shader_cache_dir = "user://"; } DirAccessRef da = DirAccess::open(shader_cache_dir); @@ -261,7 +261,7 @@ RendererCompositorRD::RendererCompositorRD() { shader_cache_dir = String(); //disable only if not editor } - if (shader_cache_dir != String()) { + if (!shader_cache_dir.is_empty()) { bool compress = GLOBAL_GET("rendering/shader_compiler/shader_cache/compress"); bool use_zstd = GLOBAL_GET("rendering/shader_compiler/shader_cache/use_zstd_compression"); bool strip_debug = GLOBAL_GET("rendering/shader_compiler/shader_cache/strip_debug"); diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 5acb1cb99c..d1085245c0 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -1858,7 +1858,7 @@ void RendererSceneGIRD::SDFGI::render_region(RID p_render_buffers, int p_region, Ref<Image> img; img.instantiate(); for (uint32_t i = 0; i < cascade_size; i++) { - Vector<uint8_t> subarr = data.subarray(128 * 128 * i, 128 * 128 * (i + 1) - 1); + Vector<uint8_t> subarr = data.slice(128 * 128 * i, 128 * 128 * (i + 1)); img->create(cascade_size, cascade_size, false, Image::FORMAT_L8, subarr); img->save_png("res://cascade_sdf_" + itos(cascade) + "_" + itos(i) + ".png"); } @@ -1871,7 +1871,7 @@ void RendererSceneGIRD::SDFGI::render_region(RID p_render_buffers, int p_region, Ref<Image> img; img.instantiate(); for (uint32_t i = 0; i < cascade_size; i++) { - Vector<uint8_t> subarr = data.subarray(128 * 128 * i * 2, 128 * 128 * (i + 1) * 2 - 1); + Vector<uint8_t> subarr = data.slice(128 * 128 * i * 2, 128 * 128 * (i + 1) * 2); img->createcascade_size, cascade_size, false, Image::FORMAT_RGB565, subarr); img->convert(Image::FORMAT_RGBA8); img->save_png("res://cascade_" + itos(cascade) + "_" + itos(i) + ".png"); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index ae8d91a73b..7c35b01b50 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3581,7 +3581,7 @@ void RendererSceneRenderRD::FogShaderData::set_code(const String &p_code) { ubo_size = 0; uniforms.clear(); - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } @@ -4417,9 +4417,9 @@ void RendererSceneRenderRD::_update_volumetric_fog(RID p_render_buffers, RID p_e uint32_t cluster_screen_width = (rb->width - 1) / cluster_size + 1; uint32_t cluster_screen_height = (rb->height - 1) / cluster_size + 1; - params.cluster_type_size = cluster_screen_width * cluster_screen_height * (32 + 32); - params.cluster_width = cluster_screen_width; params.max_cluster_element_count_div_32 = max_cluster_elements / 32; + params.cluster_type_size = cluster_screen_width * cluster_screen_height * (params.max_cluster_element_count_div_32 + 32); + params.cluster_width = cluster_screen_width; params.screen_size[0] = rb->width; params.screen_size[1] = rb->height; diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index a9c39fb937..f595edb225 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -46,7 +46,7 @@ void RendererSceneSkyRD::SkyShaderData::set_code(const String &p_code) { ubo_size = 0; uniforms.clear(); - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index cd5d70e12f..321d86ffda 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -1089,7 +1089,7 @@ Vector<Ref<Image>> RendererStorageRD::texture_3d_get(RID p_texture) const { const Texture::BufferSlice3D &bs = tex->buffer_slices_3d[i]; ERR_FAIL_COND_V(bs.offset >= (uint32_t)all_data.size(), Vector<Ref<Image>>()); ERR_FAIL_COND_V(bs.offset + bs.buffer_size > (uint32_t)all_data.size(), Vector<Ref<Image>>()); - Vector<uint8_t> sub_region = all_data.subarray(bs.offset, bs.offset + bs.buffer_size - 1); + Vector<uint8_t> sub_region = all_data.slice(bs.offset, bs.offset + bs.buffer_size); Ref<Image> img; img.instantiate(); @@ -2821,7 +2821,7 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari case ShaderLanguage::ShaderNode::Uniform::HINT_NONE: { rd_texture = singleton->texture_rd_get_default(DEFAULT_RD_TEXTURE_NORMAL); } break; - case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { + case ShaderLanguage::ShaderNode::Uniform::HINT_ANISOTROPY: { rd_texture = singleton->texture_rd_get_default(DEFAULT_RD_TEXTURE_ANISO); } break; default: { @@ -2861,7 +2861,7 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari } } #ifdef TOOLS_ENABLED - if (roughness_detect_texture && normal_detect_texture && normal_detect_texture->path != String()) { + if (roughness_detect_texture && normal_detect_texture && !normal_detect_texture->path.is_empty()) { roughness_detect_texture->detect_roughness_callback(roughness_detect_texture->detect_roughness_callback_ud, normal_detect_texture->path, roughness_channel); } #endif @@ -2901,7 +2901,7 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari rd_texture = singleton->texture_rd_get_default(DEFAULT_RD_TEXTURE_WHITE); } #ifdef TOOLS_ENABLED - if (roughness_detect_texture && normal_detect_texture && normal_detect_texture->path != String()) { + if (roughness_detect_texture && normal_detect_texture && !normal_detect_texture->path.is_empty()) { roughness_detect_texture->detect_roughness_callback(roughness_detect_texture->detect_roughness_callback_ud, normal_detect_texture->path, roughness_channel); } #endif @@ -5820,7 +5820,7 @@ void RendererStorageRD::ParticlesShaderData::set_code(const String &p_code) { uniforms.clear(); uses_collision = false; - if (code == String()) { + if (code.is_empty()) { return; //just invalid, but no error } diff --git a/servers/rendering/renderer_rd/shader_compiler_rd.cpp b/servers/rendering/renderer_rd/shader_compiler_rd.cpp index b02b3d2723..794c999d1d 100644 --- a/servers/rendering/renderer_rd/shader_compiler_rd.cpp +++ b/servers/rendering/renderer_rd/shader_compiler_rd.cpp @@ -1413,7 +1413,13 @@ ShaderLanguage::DataType ShaderCompilerRD::_get_variable_type(const StringName & } Error ShaderCompilerRD::compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { - Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), ShaderLanguage::VaryingFunctionNames(), ShaderTypes::get_singleton()->get_types(), _get_variable_type); + SL::ShaderCompileInfo info; + info.functions = ShaderTypes::get_singleton()->get_functions(p_mode); + info.render_modes = ShaderTypes::get_singleton()->get_modes(p_mode); + info.shader_types = ShaderTypes::get_singleton()->get_types(); + info.global_variable_type_func = _get_variable_type; + + Error err = parser.compile(p_code, info); if (err != OK) { Vector<String> shader = p_code.split("\n"); diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp index 2568090918..438e78ba8c 100644 --- a/servers/rendering/renderer_rd/shader_rd.cpp +++ b/servers/rendering/renderer_rd/shader_rd.cpp @@ -79,7 +79,7 @@ void ShaderRD::_add_stage(const char *p_code, StageType p_stage_type) { } if (push_chunk) { - if (text != String()) { + if (!text.is_empty()) { StageTemplate::Chunk text_chunk; text_chunk.type = StageTemplate::Chunk::TYPE_TEXT; text_chunk.text = text.utf8(); @@ -90,7 +90,7 @@ void ShaderRD::_add_stage(const char *p_code, StageType p_stage_type) { } } - if (text != String()) { + if (!text.is_empty()) { StageTemplate::Chunk text_chunk; text_chunk.type = StageTemplate::Chunk::TYPE_TEXT; text_chunk.text = text.utf8(); @@ -638,7 +638,7 @@ void ShaderRD::initialize(const Vector<String> &p_variant_defines, const String variants_enabled.push_back(true); } - if (shader_cache_dir != String()) { + if (!shader_cache_dir.is_empty()) { StringBuilder hash_build; hash_build.append("[base_hash]"); diff --git a/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl b/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl index 747f88960c..999e8d0844 100644 --- a/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl +++ b/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl @@ -581,16 +581,29 @@ void main() { if (spot_lights.data[light_index].shadow_enabled) { //has shadow - vec4 v = vec4(view_pos, 1.0); + vec4 uv_rect = spot_lights.data[light_index].atlas_rect; + vec2 flip_offset = spot_lights.data[light_index].direction.xy; - vec4 splane = (spot_lights.data[light_index].shadow_matrix * v); - splane /= splane.w; + vec3 local_vert = (spot_lights.data[light_index].shadow_matrix * vec4(view_pos, 1.0)).xyz; - float depth = texture(sampler2D(shadow_atlas, linear_sampler), splane.xy).r; + float shadow_len = length(local_vert); //need to remember shadow len from here + vec3 shadow_sample = normalize(local_vert); - shadow_attenuation = exp(min(0.0, (depth - splane.z)) / spot_lights.data[light_index].inv_radius * spot_lights.data[light_index].shadow_volumetric_fog_fade); - } + if (shadow_sample.z >= 0.0) { + uv_rect.xy += flip_offset; + } + + shadow_sample.z = 1.0 + abs(shadow_sample.z); + vec3 pos = vec3(shadow_sample.xy / shadow_sample.z, shadow_len - spot_lights.data[light_index].shadow_bias); + pos.z *= spot_lights.data[light_index].inv_radius; + + pos.xy = pos.xy * 0.5 + 0.5; + pos.xy = uv_rect.xy + pos.xy * uv_rect.zw; + float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r; + + shadow_attenuation = exp(min(0.0, (depth - pos.z)) / spot_lights.data[light_index].inv_radius * spot_lights.data[light_index].shadow_volumetric_fog_fade); + } total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(normalize(light_rel_vec), normalize(view_pos)), params.phase_g); } } |