diff options
Diffstat (limited to 'servers/rendering')
17 files changed, 211 insertions, 203 deletions
diff --git a/servers/rendering/dummy/storage/texture_storage.h b/servers/rendering/dummy/storage/texture_storage.h index 534b9f07d8..11d827a6e3 100644 --- a/servers/rendering/dummy/storage/texture_storage.h +++ b/servers/rendering/dummy/storage/texture_storage.h @@ -152,7 +152,8 @@ public: virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override {} virtual RID render_target_get_texture(RID p_render_target) override { return RID(); } virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override {} - virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override {} + virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override {} + virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override {} virtual bool render_target_was_used(RID p_render_target) override { return false; } virtual void render_target_set_as_unused(RID p_render_target) override {} diff --git a/servers/rendering/renderer_canvas_render.cpp b/servers/rendering/renderer_canvas_render.cpp index 3b68cd74fd..163a24247e 100644 --- a/servers/rendering/renderer_canvas_render.cpp +++ b/servers/rendering/renderer_canvas_render.cpp @@ -29,3 +29,102 @@ /*************************************************************************/ #include "renderer_canvas_render.h" +#include "servers/rendering/rendering_server_globals.h" + +const Rect2 &RendererCanvasRender::Item::get_rect() const { + if (custom_rect || (!rect_dirty && !update_when_visible)) { + return rect; + } + + //must update rect + + if (commands == nullptr) { + rect = Rect2(); + rect_dirty = false; + return rect; + } + + Transform2D xf; + bool found_xform = false; + bool first = true; + + const Item::Command *c = commands; + + while (c) { + Rect2 r; + + switch (c->type) { + case Item::Command::TYPE_RECT: { + const Item::CommandRect *crect = static_cast<const Item::CommandRect *>(c); + r = crect->rect; + + } break; + case Item::Command::TYPE_NINEPATCH: { + const Item::CommandNinePatch *style = static_cast<const Item::CommandNinePatch *>(c); + r = style->rect; + } break; + + case Item::Command::TYPE_POLYGON: { + const Item::CommandPolygon *polygon = static_cast<const Item::CommandPolygon *>(c); + r = polygon->polygon.rect_cache; + } break; + case Item::Command::TYPE_PRIMITIVE: { + const Item::CommandPrimitive *primitive = static_cast<const Item::CommandPrimitive *>(c); + for (uint32_t j = 0; j < primitive->point_count; j++) { + if (j == 0) { + r.position = primitive->points[0]; + } else { + r.expand_to(primitive->points[j]); + } + } + } break; + case Item::Command::TYPE_MESH: { + const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c); + AABB aabb = RSG::mesh_storage->mesh_get_aabb(mesh->mesh, RID()); + + r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); + + } break; + case Item::Command::TYPE_MULTIMESH: { + const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c); + AABB aabb = RSG::mesh_storage->multimesh_get_aabb(multimesh->multimesh); + + r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); + + } break; + case Item::Command::TYPE_PARTICLES: { + const Item::CommandParticles *particles_cmd = static_cast<const Item::CommandParticles *>(c); + if (particles_cmd->particles.is_valid()) { + AABB aabb = RSG::particles_storage->particles_get_aabb(particles_cmd->particles); + r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); + } + + } break; + case Item::Command::TYPE_TRANSFORM: { + const Item::CommandTransform *transform = static_cast<const Item::CommandTransform *>(c); + xf = transform->xform; + found_xform = true; + [[fallthrough]]; + } + default: { + c = c->next; + continue; + } + } + + if (found_xform) { + r = xf.xform(r); + } + + if (first) { + rect = r; + first = false; + } else { + rect = rect.merge(r); + } + c = c->next; + } + + rect_dirty = false; + return rect; +} diff --git a/servers/rendering/renderer_canvas_render.h b/servers/rendering/renderer_canvas_render.h index 59cc3b7a92..1724a99b20 100644 --- a/servers/rendering/renderer_canvas_render.h +++ b/servers/rendering/renderer_canvas_render.h @@ -31,8 +31,6 @@ #ifndef RENDERINGSERVERCANVASRENDER_H #define RENDERINGSERVERCANVASRENDER_H -#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h" -#include "servers/rendering/renderer_rd/storage_rd/particles_storage.h" #include "servers/rendering/renderer_storage.h" class RendererCanvasRender { @@ -356,103 +354,7 @@ public: Rect2 global_rect_cache; - const Rect2 &get_rect() const { - if (custom_rect || (!rect_dirty && !update_when_visible)) { - return rect; - } - - //must update rect - - if (commands == nullptr) { - rect = Rect2(); - rect_dirty = false; - return rect; - } - - Transform2D xf; - bool found_xform = false; - bool first = true; - - const Item::Command *c = commands; - - while (c) { - Rect2 r; - - switch (c->type) { - case Item::Command::TYPE_RECT: { - const Item::CommandRect *crect = static_cast<const Item::CommandRect *>(c); - r = crect->rect; - - } break; - case Item::Command::TYPE_NINEPATCH: { - const Item::CommandNinePatch *style = static_cast<const Item::CommandNinePatch *>(c); - r = style->rect; - } break; - - case Item::Command::TYPE_POLYGON: { - const Item::CommandPolygon *polygon = static_cast<const Item::CommandPolygon *>(c); - r = polygon->polygon.rect_cache; - } break; - case Item::Command::TYPE_PRIMITIVE: { - const Item::CommandPrimitive *primitive = static_cast<const Item::CommandPrimitive *>(c); - for (uint32_t j = 0; j < primitive->point_count; j++) { - if (j == 0) { - r.position = primitive->points[0]; - } else { - r.expand_to(primitive->points[j]); - } - } - } break; - case Item::Command::TYPE_MESH: { - const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c); - AABB aabb = RendererRD::MeshStorage::get_singleton()->mesh_get_aabb(mesh->mesh, RID()); - - r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); - - } break; - case Item::Command::TYPE_MULTIMESH: { - const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c); - AABB aabb = RendererRD::MeshStorage::get_singleton()->multimesh_get_aabb(multimesh->multimesh); - - r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); - - } break; - case Item::Command::TYPE_PARTICLES: { - const Item::CommandParticles *particles_cmd = static_cast<const Item::CommandParticles *>(c); - if (particles_cmd->particles.is_valid()) { - AABB aabb = RendererRD::ParticlesStorage::get_singleton()->particles_get_aabb(particles_cmd->particles); - r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); - } - - } break; - case Item::Command::TYPE_TRANSFORM: { - const Item::CommandTransform *transform = static_cast<const Item::CommandTransform *>(c); - xf = transform->xform; - found_xform = true; - [[fallthrough]]; - } - default: { - c = c->next; - continue; - } - } - - if (found_xform) { - r = xf.xform(r); - } - - if (first) { - rect = r; - first = false; - } else { - rect = rect.merge(r); - } - c = c->next; - } - - rect_dirty = false; - return rect; - } + const Rect2 &get_rect() const; Command *commands = nullptr; Command *last_command = nullptr; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 9e798e8b6d..85a132e6df 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -4365,7 +4365,8 @@ void RendererSceneRenderRD::_update_volumetric_fog(RID p_render_buffers, RID p_e RS::FogVolumeShape volume_type = storage->fog_volume_get_shape(fog_volume); Vector3 extents = storage->fog_volume_get_extents(fog_volume); - if (volume_type == RS::FOG_VOLUME_SHAPE_BOX || volume_type == RS::FOG_VOLUME_SHAPE_ELLIPSOID) { + if (volume_type != RS::FOG_VOLUME_SHAPE_WORLD) { + // Local fog volume. Vector3i points[8]; points[0] = _point_get_position_in_froxel_volume(fog_volume_instance->transform.xform(Vector3(extents.x, extents.y, extents.z)), fog_end, fog_near_size, fog_far_size, env->volumetric_fog_detail_spread, Vector3(rb->volumetric_fog->width, rb->volumetric_fog->height, rb->volumetric_fog->depth), p_cam_transform); points[1] = _point_get_position_in_froxel_volume(fog_volume_instance->transform.xform(Vector3(-extents.x, extents.y, extents.z)), fog_end, fog_near_size, fog_far_size, env->volumetric_fog_detail_spread, Vector3(rb->volumetric_fog->width, rb->volumetric_fog->height, rb->volumetric_fog->depth), p_cam_transform); diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index 14a5f02eee..7adc5a23f2 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -846,6 +846,7 @@ void RendererSceneSkyRD::init(RendererStorageRD *p_storage) { actions.renames["POSITION"] = "params.position_multiplier.xyz"; actions.renames["SKY_COORDS"] = "panorama_coords"; actions.renames["SCREEN_UV"] = "uv"; + actions.renames["FRAGCOORD"] = "gl_FragCoord"; actions.renames["TIME"] = "params.time"; actions.renames["PI"] = _MKSTR(Math_PI); actions.renames["TAU"] = _MKSTR(Math_TAU); diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index cf642c38c9..1b9e0faa00 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -97,6 +97,8 @@ AABB RendererStorageRD::fog_volume_get_aabb(RID p_fog_volume) const { switch (fog_volume->shape) { case RS::FOG_VOLUME_SHAPE_ELLIPSOID: + case RS::FOG_VOLUME_SHAPE_CONE: + case RS::FOG_VOLUME_SHAPE_CYLINDER: case RS::FOG_VOLUME_SHAPE_BOX: { AABB aabb; aabb.position = -fog_volume->extents; diff --git a/servers/rendering/renderer_rd/shaders/volumetric_fog.glsl b/servers/rendering/renderer_rd/shaders/volumetric_fog.glsl index a2a4c91894..eee609fb48 100644 --- a/servers/rendering/renderer_rd/shaders/volumetric_fog.glsl +++ b/servers/rendering/renderer_rd/shaders/volumetric_fog.glsl @@ -186,12 +186,31 @@ void main() { float sdf = -1.0; if (params.shape == 0) { - //Ellipsoid + // Ellipsoid // https://www.shadertoy.com/view/tdS3DG float k0 = length(local_pos.xyz / params.extents); float k1 = length(local_pos.xyz / (params.extents * params.extents)); sdf = k0 * (k0 - 1.0) / k1; } else if (params.shape == 1) { + // Cone + // https://iquilezles.org/www/articles/distfunctions/distfunctions.htm + + // Compute the cone angle automatically to fit within the volume's extents. + float inv_height = 1.0 / max(0.001, params.extents.y); + float radius = 1.0 / max(0.001, (min(params.extents.x, params.extents.z) * 0.5)); + float hypotenuse = sqrt(radius * radius + inv_height * inv_height); + float rsin = radius / hypotenuse; + float rcos = inv_height / hypotenuse; + vec2 c = vec2(rsin, rcos); + + float q = length(local_pos.xz); + sdf = max(dot(c, vec2(q, local_pos.y - params.extents.y)), -params.extents.y - local_pos.y); + } else if (params.shape == 2) { + // Cylinder + // https://iquilezles.org/www/articles/distfunctions/distfunctions.htm + vec2 d = abs(vec2(length(local_pos.xz), local_pos.y)) - vec2(min(params.extents.x, params.extents.z), params.extents.y); + sdf = min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); + } else if (params.shape == 3) { // Box // https://iquilezles.org/www/articles/distfunctions/distfunctions.htm vec3 q = abs(local_pos.xyz) - params.extents; @@ -199,7 +218,7 @@ void main() { } float cull_mask = 1.0; //used to cull cells that do not contribute - if (params.shape <= 1) { + if (params.shape <= 3) { #ifndef SDF_USED cull_mask = 1.0 - smoothstep(-0.1, 0.0, sdf); #endif diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index de9913be3f..8e2e9b14cb 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -955,7 +955,7 @@ void MaterialData::update_uniform_buffer(const HashMap<StringName, ShaderLanguag //value=E.value.default_value; } else { //zero because it was not provided - if ((E.value.type == ShaderLanguage::TYPE_VEC3 || E.value.type == ShaderLanguage::TYPE_VEC4) && E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if ((E.value.type == ShaderLanguage::TYPE_VEC3 || E.value.type == ShaderLanguage::TYPE_VEC4) && E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { //colors must be set as black, with alpha as 1.0 _fill_std140_variant_ubo_value(E.value.type, E.value.array_size, Color(0, 0, 0, 1), data, p_use_linear_color); } else { @@ -1090,8 +1090,7 @@ void MaterialData::update_textures(const HashMap<StringName, Variant> &p_paramet case ShaderLanguage::TYPE_USAMPLER2D: case ShaderLanguage::TYPE_SAMPLER2D: { switch (p_texture_uniforms[i].hint) { - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO: { + case ShaderLanguage::ShaderNode::Uniform::HINT_DEFAULT_BLACK: { rd_texture = texture_storage->texture_rd_get_default(DEFAULT_RD_TEXTURE_BLACK); } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISOTROPY: { @@ -1111,8 +1110,7 @@ void MaterialData::update_textures(const HashMap<StringName, Variant> &p_paramet case ShaderLanguage::TYPE_SAMPLERCUBE: { switch (p_texture_uniforms[i].hint) { - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO: { + case ShaderLanguage::ShaderNode::Uniform::HINT_DEFAULT_BLACK: { rd_texture = texture_storage->texture_rd_get_default(DEFAULT_RD_TEXTURE_CUBEMAP_BLACK); } break; default: { @@ -1152,7 +1150,7 @@ void MaterialData::update_textures(const HashMap<StringName, Variant> &p_paramet p_textures[k++] = rd_texture; } } else { - bool srgb = p_use_linear_color && (p_texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_ALBEDO || p_texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO); + bool srgb = p_use_linear_color && p_texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR; for (int j = 0; j < textures.size(); j++) { Texture *tex = TextureStorage::get_singleton()->get_texture(textures[j]); diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index e15d3e13a9..58a96ed1f9 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -540,11 +540,8 @@ void ParticlesStorage::particles_emit(RID p_particles, const Transform3D &p_tran _particles_allocate_emission_buffer(particles); } - if (particles->inactive) { - //in case it was inactive, make active again - particles->inactive = false; - particles->inactive_time = 0; - } + particles->inactive = false; + particles->inactive_time = 0; int32_t idx = particles->emission_buffer->particle_count; if (idx < particles->emission_buffer->particle_max) { diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 7d4808f936..329c23bad0 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -2075,7 +2075,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) { //until we implement support for HDR monitors (and render target is attached to screen), this is enough. rt->color_format = RD::DATA_FORMAT_R8G8B8A8_UNORM; rt->color_format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; - rt->image_format = rt->flags[RENDER_TARGET_TRANSPARENT] ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8; + rt->image_format = rt->is_transparent ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8; RD::TextureFormat rd_format; RD::TextureView rd_view; @@ -2127,7 +2127,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) { //so transparent can be supported RD::TextureView view; view.format_override = rt->color_format; - if (!rt->flags[RENDER_TARGET_TRANSPARENT]) { + if (!rt->is_transparent) { view.swizzle_a = RD::TEXTURE_SWIZZLE_ONE; } tex->rd_texture = RD::get_singleton()->texture_create_shared(view, rt->color); @@ -2194,9 +2194,6 @@ RID TextureStorage::render_target_create() { render_target.was_used = false; render_target.clear_requested = false; - for (int i = 0; i < RENDER_TARGET_FLAG_MAX; i++) { - render_target.flags[i] = false; - } _update_render_target(&render_target); return render_target_owner.make_rid(render_target); } @@ -2240,13 +2237,16 @@ RID TextureStorage::render_target_get_texture(RID p_render_target) { void TextureStorage::render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) { } -void TextureStorage::render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) { +void TextureStorage::render_target_set_transparent(RID p_render_target, bool p_is_transparent) { RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); - rt->flags[p_flag] = p_value; + rt->is_transparent = p_is_transparent; _update_render_target(rt); } +void TextureStorage::render_target_set_direct_to_screen(RID p_render_target, bool p_value) { +} + bool TextureStorage::render_target_was_used(RID p_render_target) { RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, false); diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.h b/servers/rendering/renderer_rd/storage_rd/texture_storage.h index 418eb82808..901f764085 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.h @@ -207,7 +207,7 @@ struct RenderTarget { RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8; Image::Format image_format = Image::FORMAT_L8; - bool flags[RendererTextureStorage::RENDER_TARGET_FLAG_MAX]; + bool is_transparent = false; bool sdf_enabled = false; @@ -525,7 +525,8 @@ public: virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override; virtual RID render_target_get_texture(RID p_render_target) override; virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override; - virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override; + virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override; + virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override; virtual bool render_target_was_used(RID p_render_target) override; virtual void render_target_set_as_unused(RID p_render_target) override; diff --git a/servers/rendering/renderer_scene_occlusion_cull.h b/servers/rendering/renderer_scene_occlusion_cull.h index 48412dab68..7198379ade 100644 --- a/servers/rendering/renderer_scene_occlusion_cull.h +++ b/servers/rendering/renderer_scene_occlusion_cull.h @@ -161,31 +161,31 @@ public: static RendererSceneOcclusionCull *get_singleton() { return singleton; } - void _print_warining() { - WARN_PRINT_ONCE("Occlusion culling is disabled at build time."); + void _print_warning() { + WARN_PRINT_ONCE("Occlusion culling is disabled at build-time."); } virtual bool is_occluder(RID p_rid) { return false; } virtual RID occluder_allocate() { return RID(); } virtual void occluder_initialize(RID p_occluder) {} - virtual void free_occluder(RID p_occluder) { _print_warining(); } - virtual void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) { _print_warining(); } + virtual void free_occluder(RID p_occluder) { _print_warning(); } + virtual void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) { _print_warning(); } virtual void add_scenario(RID p_scenario) {} virtual void remove_scenario(RID p_scenario) {} - virtual void scenario_set_instance(RID p_scenario, RID p_instance, RID p_occluder, const Transform3D &p_xform, bool p_enabled) { _print_warining(); } - virtual void scenario_remove_instance(RID p_scenario, RID p_instance) { _print_warining(); } + virtual void scenario_set_instance(RID p_scenario, RID p_instance, RID p_occluder, const Transform3D &p_xform, bool p_enabled) { _print_warning(); } + virtual void scenario_remove_instance(RID p_scenario, RID p_instance) { _print_warning(); } - virtual void add_buffer(RID p_buffer) { _print_warining(); } - virtual void remove_buffer(RID p_buffer) { _print_warining(); } + virtual void add_buffer(RID p_buffer) { _print_warning(); } + virtual void remove_buffer(RID p_buffer) { _print_warning(); } virtual HZBuffer *buffer_get_ptr(RID p_buffer) { return nullptr; } - virtual void buffer_set_scenario(RID p_buffer, RID p_scenario) { _print_warining(); } - virtual void buffer_set_size(RID p_buffer, const Vector2i &p_size) { _print_warining(); } + virtual void buffer_set_scenario(RID p_buffer, RID p_scenario) { _print_warning(); } + virtual void buffer_set_size(RID p_buffer, const Vector2i &p_size) { _print_warning(); } virtual void buffer_update(RID p_buffer, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, ThreadWorkPool &p_thread_pool) {} virtual RID buffer_get_debug_texture(RID p_buffer) { - _print_warining(); + _print_warning(); return RID(); } diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 7c2d7a1e1d..74fafe8381 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -866,7 +866,7 @@ void RendererViewport::viewport_set_render_direct_to_screen(RID p_viewport, bool RSG::texture_storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y, viewport->get_view_count()); } - RSG::texture_storage->render_target_set_flag(viewport->render_target, RendererTextureStorage::RENDER_TARGET_DIRECT_TO_SCREEN, p_enable); + RSG::texture_storage->render_target_set_direct_to_screen(viewport->render_target, p_enable); viewport->viewport_render_direct_to_screen = p_enable; // if attached to screen already, setup screen size and position, this needs to happen after setting flag to avoid an unnecessary buffer allocation @@ -980,7 +980,7 @@ void RendererViewport::viewport_set_transparent_background(RID p_viewport, bool Viewport *viewport = viewport_owner.get_or_null(p_viewport); ERR_FAIL_COND(!viewport); - RSG::texture_storage->render_target_set_flag(viewport->render_target, RendererTextureStorage::RENDER_TARGET_TRANSPARENT, p_enabled); + RSG::texture_storage->render_target_set_transparent(viewport->render_target, p_enabled); viewport->transparent_bg = p_enabled; } diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index a3bd067963..b25296e3b0 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -190,13 +190,11 @@ const char *ShaderLanguage::token_names[TK_MAX] = { "OUT", "INOUT", "RENDER_MODE", - "HINT_WHITE_TEXTURE", - "HINT_BLACK_TEXTURE", + "SOURCE_COLOR", + "HINT_DEFAULT_WHITE_TEXTURE", + "HINT_DEFAULT_BLACK_TEXTURE", "HINT_NORMAL_TEXTURE", "HINT_ANISOTROPY_TEXTURE", - "HINT_ALBEDO_TEXTURE", - "HINT_BLACK_ALBEDO_TEXTURE", - "HINT_COLOR", "HINT_RANGE", "HINT_INSTANCE_INDEX", "FILTER_NEAREST", @@ -344,17 +342,15 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { // hints + { TK_HINT_SOURCE_COLOR, "source_color", CF_UNSPECIFIED, {}, {} }, { TK_HINT_RANGE, "hint_range", CF_UNSPECIFIED, {}, {} }, - { TK_HINT_COLOR, "hint_color", CF_UNSPECIFIED, {}, {} }, { TK_HINT_INSTANCE_INDEX, "instance_index", CF_UNSPECIFIED, {}, {} }, // sampler hints - { TK_HINT_ALBEDO_TEXTURE, "hint_albedo", CF_UNSPECIFIED, {}, {} }, - { TK_HINT_BLACK_ALBEDO_TEXTURE, "hint_black_albedo", CF_UNSPECIFIED, {}, {} }, { TK_HINT_NORMAL_TEXTURE, "hint_normal", CF_UNSPECIFIED, {}, {} }, - { TK_HINT_WHITE_TEXTURE, "hint_white", CF_UNSPECIFIED, {}, {} }, - { TK_HINT_BLACK_TEXTURE, "hint_black", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_DEFAULT_WHITE_TEXTURE, "hint_default_white", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_DEFAULT_BLACK_TEXTURE, "hint_default_black", CF_UNSPECIFIED, {}, {} }, { TK_HINT_ANISOTROPY_TEXTURE, "hint_anisotropy", CF_UNSPECIFIED, {}, {} }, { TK_HINT_ROUGHNESS_R, "hint_roughness_r", CF_UNSPECIFIED, {}, {} }, { TK_HINT_ROUGHNESS_G, "hint_roughness_g", CF_UNSPECIFIED, {}, {} }, @@ -3421,17 +3417,7 @@ bool ShaderLanguage::is_float_type(DataType p_type) { } } bool ShaderLanguage::is_sampler_type(DataType p_type) { - return p_type == TYPE_SAMPLER2D || - p_type == TYPE_ISAMPLER2D || - p_type == TYPE_USAMPLER2D || - p_type == TYPE_SAMPLER2DARRAY || - p_type == TYPE_ISAMPLER2DARRAY || - p_type == TYPE_USAMPLER2DARRAY || - p_type == TYPE_SAMPLER3D || - p_type == TYPE_ISAMPLER3D || - p_type == TYPE_USAMPLER3D || - p_type == TYPE_SAMPLERCUBE || - p_type == TYPE_SAMPLERCUBEARRAY; + return p_type > TYPE_MAT4 && p_type < TYPE_STRUCT; } Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::ConstantNode::Value> &p_value, DataType p_type, int p_array_size, ShaderLanguage::ShaderNode::Uniform::Hint p_hint) { @@ -3618,7 +3604,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C if (array_size > 0) { array_size *= 3; - if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { PackedColorArray array = PackedColorArray(); for (int i = 0; i < array_size; i += 3) { array.push_back(Color(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real)); @@ -3632,7 +3618,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C value = Variant(array); } } else { - if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { value = Variant(Color(p_value[0].real, p_value[1].real, p_value[2].real)); } else { value = Variant(Vector3(p_value[0].real, p_value[1].real, p_value[2].real)); @@ -3643,7 +3629,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C if (array_size > 0) { array_size *= 4; - if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { PackedColorArray array = PackedColorArray(); for (int i = 0; i < array_size; i += 4) { array.push_back(Color(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real, p_value[i + 3].real)); @@ -3660,7 +3646,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C value = Variant(array); } } else { - if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { value = Variant(Color(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); } else { value = Variant(Quaternion(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); @@ -3842,14 +3828,14 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform break; case ShaderLanguage::TYPE_VEC3: if (p_uniform.array_size > 0) { - if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { pi.hint = PROPERTY_HINT_COLOR_NO_ALPHA; pi.type = Variant::PACKED_COLOR_ARRAY; } else { pi.type = Variant::PACKED_VECTOR3_ARRAY; } } else { - if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { pi.hint = PROPERTY_HINT_COLOR_NO_ALPHA; pi.type = Variant::COLOR; } else { @@ -3859,13 +3845,13 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform break; case ShaderLanguage::TYPE_VEC4: { if (p_uniform.array_size > 0) { - if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { pi.type = Variant::PACKED_COLOR_ARRAY; } else { pi.type = Variant::PACKED_FLOAT32_ARRAY; } } else { - if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { pi.type = Variant::COLOR; } else { pi.type = Variant::QUATERNION; @@ -5379,6 +5365,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (tk.type == TK_CURSOR) { //do nothing } else if (tk.type == TK_PERIOD) { +#ifdef DEBUG_ENABLED + uint32_t prev_keyword_completion_context = keyword_completion_context; + keyword_completion_context = CF_UNSPECIFIED; +#endif + DataType dt = expr->get_datatype(); String st = expr->get_datatype_name(); @@ -5734,6 +5725,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } expr = mn; +#ifdef DEBUG_ENABLED + keyword_completion_context = prev_keyword_completion_context; +#endif + //todo //member (period) has priority over any operator //creates a subindexing expression in place @@ -8240,16 +8235,16 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f } if (uniform2.array_size > 0) { - if (tk.type != TK_HINT_COLOR) { + if (tk.type != TK_HINT_SOURCE_COLOR) { _set_error(RTR("This hint is not supported for uniform arrays.")); return ERR_PARSE_ERROR; } } - if (tk.type == TK_HINT_WHITE_TEXTURE) { - uniform2.hint = ShaderNode::Uniform::HINT_WHITE; - } else if (tk.type == TK_HINT_BLACK_TEXTURE) { - uniform2.hint = ShaderNode::Uniform::HINT_BLACK; + if (tk.type == TK_HINT_DEFAULT_WHITE_TEXTURE) { + uniform2.hint = ShaderNode::Uniform::HINT_DEFAULT_WHITE; + } else if (tk.type == TK_HINT_DEFAULT_BLACK_TEXTURE) { + uniform2.hint = ShaderNode::Uniform::HINT_DEFAULT_BLACK; } else if (tk.type == TK_HINT_NORMAL_TEXTURE) { uniform2.hint = ShaderNode::Uniform::HINT_NORMAL; } else if (tk.type == TK_HINT_ROUGHNESS_NORMAL_TEXTURE) { @@ -8266,16 +8261,12 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f uniform2.hint = ShaderNode::Uniform::HINT_ROUGHNESS_GRAY; } else if (tk.type == TK_HINT_ANISOTROPY_TEXTURE) { uniform2.hint = ShaderNode::Uniform::HINT_ANISOTROPY; - } else if (tk.type == TK_HINT_ALBEDO_TEXTURE) { - uniform2.hint = ShaderNode::Uniform::HINT_ALBEDO; - } else if (tk.type == TK_HINT_BLACK_ALBEDO_TEXTURE) { - uniform2.hint = ShaderNode::Uniform::HINT_BLACK_ALBEDO; - } else if (tk.type == TK_HINT_COLOR) { - if (type != TYPE_VEC3 && type != TYPE_VEC4) { - _set_error(vformat(RTR("Color hint is for '%s' or '%s' only."), "vec3", "vec4")); + } else if (tk.type == TK_HINT_SOURCE_COLOR) { + if (type != TYPE_VEC3 && type != TYPE_VEC4 && type <= TYPE_MAT4) { + _set_error(vformat(RTR("Source color hint is for '%s', '%s' or sampler types only."), "vec3", "vec4")); return ERR_PARSE_ERROR; } - uniform2.hint = ShaderNode::Uniform::HINT_COLOR; + uniform2.hint = ShaderNode::Uniform::HINT_SOURCE_COLOR; } else if (tk.type == TK_HINT_RANGE) { uniform2.hint = ShaderNode::Uniform::HINT_RANGE; if (type != TYPE_FLOAT && type != TYPE_INT) { @@ -8409,7 +8400,12 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f uniform2.repeat = REPEAT_ENABLE; } - if (uniform2.hint != ShaderNode::Uniform::HINT_RANGE && uniform2.hint != ShaderNode::Uniform::HINT_NONE && uniform2.hint != ShaderNode::Uniform::HINT_COLOR && type <= TYPE_MAT4) { + if (uniform2.hint == ShaderNode::Uniform::HINT_SOURCE_COLOR) { + if (type != TYPE_VEC3 && type != TYPE_VEC4 && !is_sampler_type(type)) { + _set_error(vformat(RTR("This hint is only for '%s', '%s' or sampler types."), "vec3", "vec4")); + return ERR_PARSE_ERROR; + } + } else if (uniform2.hint != ShaderNode::Uniform::HINT_RANGE && uniform2.hint != ShaderNode::Uniform::HINT_NONE && !is_sampler_type(type)) { _set_error(RTR("This hint is only for sampler types.")); return ERR_PARSE_ERROR; } @@ -9913,7 +9909,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } break; case COMPLETION_HINT: { if (completion_base == DataType::TYPE_VEC3 || completion_base == DataType::TYPE_VEC4) { - ScriptLanguage::CodeCompletionOption option("hint_color", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option("source_color", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } else if ((completion_base == DataType::TYPE_INT || completion_base == DataType::TYPE_FLOAT) && !completion_base_array) { ScriptLanguage::CodeCompletionOption option("hint_range", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); @@ -9935,10 +9931,9 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ options.push_back("filter_nearest"); options.push_back("filter_nearest_mipmap"); options.push_back("filter_nearest_mipmap_anisotropic"); - options.push_back("hint_albedo"); options.push_back("hint_anisotropy"); - options.push_back("hint_black"); - options.push_back("hint_black_albedo"); + options.push_back("hint_default_black"); + options.push_back("hint_default_white"); options.push_back("hint_normal"); options.push_back("hint_roughness_a"); options.push_back("hint_roughness_b"); @@ -9946,7 +9941,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ options.push_back("hint_roughness_gray"); options.push_back("hint_roughness_normal"); options.push_back("hint_roughness_r"); - options.push_back("hint_white"); + options.push_back("source_color"); options.push_back("repeat_enable"); options.push_back("repeat_disable"); } diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index cd3f07e27e..5d216bd66e 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -160,8 +160,8 @@ public: TK_ARG_OUT, TK_ARG_INOUT, TK_RENDER_MODE, - TK_HINT_WHITE_TEXTURE, - TK_HINT_BLACK_TEXTURE, + TK_HINT_DEFAULT_WHITE_TEXTURE, + TK_HINT_DEFAULT_BLACK_TEXTURE, TK_HINT_NORMAL_TEXTURE, TK_HINT_ROUGHNESS_NORMAL_TEXTURE, TK_HINT_ROUGHNESS_R, @@ -170,9 +170,7 @@ public: TK_HINT_ROUGHNESS_A, TK_HINT_ROUGHNESS_GRAY, TK_HINT_ANISOTROPY_TEXTURE, - TK_HINT_ALBEDO_TEXTURE, - TK_HINT_BLACK_ALBEDO_TEXTURE, - TK_HINT_COLOR, + TK_HINT_SOURCE_COLOR, TK_HINT_RANGE, TK_HINT_INSTANCE_INDEX, TK_FILTER_NEAREST, @@ -503,7 +501,7 @@ public: BlockNode *parent_block = nullptr; enum BlockType { - BLOCK_TYPE_STANDART, + BLOCK_TYPE_STANDARD, BLOCK_TYPE_FOR_INIT, BLOCK_TYPE_FOR_CONDITION, BLOCK_TYPE_FOR_EXPRESSION, @@ -512,7 +510,7 @@ public: BLOCK_TYPE_DEFAULT, }; - int block_type = BLOCK_TYPE_STANDART; + int block_type = BLOCK_TYPE_STANDARD; SubClassTag block_tag = SubClassTag::TAG_GLOBAL; struct Variable { @@ -653,10 +651,8 @@ public: struct Uniform { enum Hint { HINT_NONE, - HINT_COLOR, HINT_RANGE, - HINT_ALBEDO, - HINT_BLACK_ALBEDO, + HINT_SOURCE_COLOR, HINT_NORMAL, HINT_ROUGHNESS_NORMAL, HINT_ROUGHNESS_R, @@ -664,8 +660,8 @@ public: HINT_ROUGHNESS_B, HINT_ROUGHNESS_A, HINT_ROUGHNESS_GRAY, - HINT_BLACK, - HINT_WHITE, + HINT_DEFAULT_BLACK, + HINT_DEFAULT_WHITE, HINT_ANISOTROPY, HINT_MAX }; diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index e0dd417758..5772179d68 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -422,6 +422,7 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["ALPHA"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["EYEDIR"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["SCREEN_UV"] = constt(ShaderLanguage::TYPE_VEC2); + shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["FRAGCOORD"] = constt(ShaderLanguage::TYPE_VEC4); shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["SKY_COORDS"] = constt(ShaderLanguage::TYPE_VEC2); shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["HALF_RES_COLOR"] = constt(ShaderLanguage::TYPE_VEC4); shader_modes[RS::SHADER_SKY].functions["sky"].built_ins["QUARTER_RES_COLOR"] = constt(ShaderLanguage::TYPE_VEC4); diff --git a/servers/rendering/storage/texture_storage.h b/servers/rendering/storage/texture_storage.h index 4c4213d7c1..e3a969d032 100644 --- a/servers/rendering/storage/texture_storage.h +++ b/servers/rendering/storage/texture_storage.h @@ -111,12 +111,6 @@ public: /* RENDER TARGET */ - enum RenderTargetFlags { - RENDER_TARGET_TRANSPARENT, - RENDER_TARGET_DIRECT_TO_SCREEN, - RENDER_TARGET_FLAG_MAX - }; - virtual RID render_target_create() = 0; virtual void render_target_free(RID p_rid) = 0; @@ -124,7 +118,8 @@ public: virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) = 0; virtual RID render_target_get_texture(RID p_render_target) = 0; virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) = 0; - virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) = 0; + virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) = 0; + virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) = 0; virtual bool render_target_was_used(RID p_render_target) = 0; virtual void render_target_set_as_unused(RID p_render_target) = 0; |