diff options
author | Spartan322 <Megacake1234@gmail.com> | 2024-11-26 12:56:19 -0500 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-11-26 12:56:19 -0500 |
commit | e58e18261ea7ed3978146ef8d77a900be2601be3 (patch) | |
tree | 79c2a4c34f2d888ff962d76edf474c518d1abdea /drivers | |
parent | c5b1645e60a59c0292c04bece3fdb0715a61afea (diff) | |
parent | d09d82d433b03bb3773fd2a8cc8d6ccc2f8739ce (diff) | |
download | redot-engine-e58e18261ea7ed3978146ef8d77a900be2601be3.tar.gz |
Merge commit godotengine/godot@d09d82d433b03bb3773fd2a8cc8d6ccc2f8739ce
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 54 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.h | 36 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 46 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas_uniforms_inc.glsl | 37 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 22 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/file_access_unix_pipe.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 2 |
8 files changed, 108 insertions, 93 deletions
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 8e1b744113..292534c43e 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -722,11 +722,14 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou } } - bool success = GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_bind_shader(shader_version, variant, specialization); + bool success = material_storage->shaders.canvas_shader.version_bind_shader(shader_version, variant, specialization); if (!success) { continue; } + // Bind per-batch uniforms. + material_storage->shaders.canvas_shader.version_set_uniform(CanvasShaderGLES3::BATCH_FLAGS, state.canvas_instance_batches[i].flags, shader_version, variant, specialization); + GLES3::CanvasShaderData::BlendMode blend_mode = state.canvas_instance_batches[i].blend_mode; Color blend_color = state.canvas_instance_batches[i].blend_color; @@ -849,6 +852,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend uint32_t lights[4] = { 0, 0, 0, 0 }; uint16_t light_count = 0; + uint16_t shadow_mask = 0; { Light *light = p_lights; @@ -858,6 +862,10 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend uint32_t light_index = light->render_index_cache; lights[light_count >> 2] |= light_index << ((light_count & 3) * 8); + if (p_item->light_mask & light->item_shadow_mask) { + shadow_mask |= 1 << light_count; + } + light_count++; if (light_count == data.max_lights_per_item - 1) { @@ -867,7 +875,8 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend light = light->next_ptr; } - base_flags |= light_count << FLAGS_LIGHT_COUNT_SHIFT; + base_flags |= light_count << INSTANCE_FLAGS_LIGHT_COUNT_SHIFT; + base_flags |= shadow_mask << INSTANCE_FLAGS_SHADOW_MASKED_SHIFT; } bool lights_disabled = light_count == 0 && !state.using_directional_lights; @@ -908,7 +917,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.instance_data_array[r_index].lights[2] = lights[2]; state.instance_data_array[r_index].lights[3] = lights[3]; - state.instance_data_array[r_index].flags = base_flags | (state.instance_data_array[r_index == 0 ? 0 : r_index - 1].flags & (FLAGS_DEFAULT_NORMAL_MAP_USED | FLAGS_DEFAULT_SPECULAR_MAP_USED)); // Reset on each command for safety, keep canvastexture binding config. + state.instance_data_array[r_index].flags = base_flags; Color blend_color = base_color; GLES3::CanvasShaderData::BlendMode blend_mode = p_blend_mode; @@ -941,6 +950,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.canvas_instance_batches[state.current_batch_index].command_type = Item::Command::TYPE_RECT; state.canvas_instance_batches[state.current_batch_index].command = c; state.canvas_instance_batches[state.current_batch_index].specialization &= specialization_command_mask; + state.canvas_instance_batches[state.current_batch_index].flags = 0; } _prepare_canvas_texture(rect->texture, state.canvas_instance_batches[state.current_batch_index].filter, state.canvas_instance_batches[state.current_batch_index].repeat, r_index, texpixel_size); @@ -963,20 +973,18 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend if (rect->flags & CANVAS_RECT_FLIP_H) { src_rect.size.x *= -1; - state.instance_data_array[r_index].flags |= FLAGS_FLIP_H; } if (rect->flags & CANVAS_RECT_FLIP_V) { src_rect.size.y *= -1; - state.instance_data_array[r_index].flags |= FLAGS_FLIP_V; } if (rect->flags & CANVAS_RECT_TRANSPOSE) { - state.instance_data_array[r_index].flags |= FLAGS_TRANSPOSE_RECT; + state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_TRANSPOSE_RECT; } if (rect->flags & CANVAS_RECT_CLIP_UV) { - state.instance_data_array[r_index].flags |= FLAGS_CLIP_RECT_UV; + state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_CLIP_RECT_UV; } } else { @@ -995,13 +1003,13 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend } if (rect->flags & CANVAS_RECT_MSDF) { - state.instance_data_array[r_index].flags |= FLAGS_USE_MSDF; + state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_USE_MSDF; state.instance_data_array[r_index].msdf[0] = rect->px_range; // Pixel range. state.instance_data_array[r_index].msdf[1] = rect->outline; // Outline size. state.instance_data_array[r_index].msdf[2] = 0.f; // Reserved. state.instance_data_array[r_index].msdf[3] = 0.f; // Reserved. } else if (rect->flags & CANVAS_RECT_LCD) { - state.instance_data_array[r_index].flags |= FLAGS_USE_LCD; + state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_USE_LCD; } state.instance_data_array[r_index].modulation[0] = rect->modulate.r * base_color.r; @@ -1032,6 +1040,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.canvas_instance_batches[state.current_batch_index].command = c; state.canvas_instance_batches[state.current_batch_index].specialization &= specialization_command_mask; state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_NINEPATCH; + state.canvas_instance_batches[state.current_batch_index].flags = 0; } _prepare_canvas_texture(np->texture, state.canvas_instance_batches[state.current_batch_index].filter, state.canvas_instance_batches[state.current_batch_index].repeat, r_index, texpixel_size); @@ -1069,11 +1078,11 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.instance_data_array[r_index].dst_rect[2] = dst_rect.size.width; state.instance_data_array[r_index].dst_rect[3] = dst_rect.size.height; - state.instance_data_array[r_index].flags |= int(np->axis_x) << FLAGS_NINEPATCH_H_MODE_SHIFT; - state.instance_data_array[r_index].flags |= int(np->axis_y) << FLAGS_NINEPATCH_V_MODE_SHIFT; + state.instance_data_array[r_index].flags |= int(np->axis_x) << INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT; + state.instance_data_array[r_index].flags |= int(np->axis_y) << INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT; if (np->draw_center) { - state.instance_data_array[r_index].flags |= FLAGS_NINEPACH_DRAW_CENTER; + state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_NINEPACH_DRAW_CENTER; } state.instance_data_array[r_index].ninepatch_margins[0] = np->margin[SIDE_LEFT]; @@ -1099,6 +1108,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.canvas_instance_batches[state.current_batch_index].command = c; state.canvas_instance_batches[state.current_batch_index].specialization &= specialization_command_mask; state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_ATTRIBUTES; + state.canvas_instance_batches[state.current_batch_index].flags = 0; _prepare_canvas_texture(polygon->texture, state.canvas_instance_batches[state.current_batch_index].filter, state.canvas_instance_batches[state.current_batch_index].repeat, r_index, texpixel_size); @@ -1127,6 +1137,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.canvas_instance_batches[state.current_batch_index].command = c; state.canvas_instance_batches[state.current_batch_index].specialization &= specialization_command_mask; state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_PRIMITIVE; + state.canvas_instance_batches[state.current_batch_index].flags = 0; } _prepare_canvas_texture(state.canvas_instance_batches[state.current_batch_index].tex, state.canvas_instance_batches[state.current_batch_index].filter, state.canvas_instance_batches[state.current_batch_index].repeat, r_index, texpixel_size); @@ -1167,12 +1178,13 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend case Item::Command::TYPE_MESH: case Item::Command::TYPE_MULTIMESH: case Item::Command::TYPE_PARTICLES: { - // Mesh's can't be batched, so always create a new batch + // Meshes can't be batched, so always create a new batch. _new_batch(r_batch_broken); Color modulate(1, 1, 1, 1); state.canvas_instance_batches[state.current_batch_index].specialization &= specialization_command_mask; state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_ATTRIBUTES; + state.canvas_instance_batches[state.current_batch_index].flags = 0; if (c->type == Item::Command::TYPE_MESH) { const Item::CommandMesh *m = static_cast<const Item::CommandMesh *>(c); state.canvas_instance_batches[state.current_batch_index].tex = m->texture; @@ -1185,10 +1197,10 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_INSTANCING; if (GLES3::MeshStorage::get_singleton()->multimesh_uses_colors(mm->multimesh)) { - state.instance_data_array[r_index].flags |= FLAGS_INSTANCING_HAS_COLORS; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_INSTANCING_HAS_COLORS; } if (GLES3::MeshStorage::get_singleton()->multimesh_uses_custom_data(mm->multimesh)) { - state.instance_data_array[r_index].flags |= FLAGS_INSTANCING_HAS_CUSTOM_DATA; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA; } } else if (c->type == Item::Command::TYPE_PARTICLES) { GLES3::ParticlesStorage *particles_storage = GLES3::ParticlesStorage::get_singleton(); @@ -1198,8 +1210,8 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend RID particles = pt->particles; state.canvas_instance_batches[state.current_batch_index].tex = pt->texture; state.canvas_instance_batches[state.current_batch_index].specialization |= CanvasShaderGLES3::USE_INSTANCING; - state.instance_data_array[r_index].flags |= FLAGS_INSTANCING_HAS_COLORS; - state.instance_data_array[r_index].flags |= FLAGS_INSTANCING_HAS_CUSTOM_DATA; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_INSTANCING_HAS_COLORS; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA; if (particles_storage->particles_has_collision(particles) && texture_storage->render_target_is_sdf_enabled(p_render_target)) { // Pass collision information. @@ -2366,15 +2378,15 @@ void RasterizerCanvasGLES3::_prepare_canvas_texture(RID p_texture, RS::CanvasIte GLES3::Texture *normal_map = texture_storage->get_texture(ct->normal_map); if (ct->specular_color.a < 0.999) { - state.instance_data_array[r_index].flags |= FLAGS_DEFAULT_SPECULAR_MAP_USED; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED; } else { - state.instance_data_array[r_index].flags &= ~FLAGS_DEFAULT_SPECULAR_MAP_USED; + state.canvas_instance_batches[state.current_batch_index].flags &= ~BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED; } if (normal_map) { - state.instance_data_array[r_index].flags |= FLAGS_DEFAULT_NORMAL_MAP_USED; + state.canvas_instance_batches[state.current_batch_index].flags |= BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED; } else { - state.instance_data_array[r_index].flags &= ~FLAGS_DEFAULT_NORMAL_MAP_USED; + state.canvas_instance_batches[state.current_batch_index].flags &= ~BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED; } state.instance_data_array[r_index].specular_shininess = uint32_t(CLAMP(ct->specular_color.a * 255.0, 0, 255)) << 24; diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 0fd82f841e..5385981a6e 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -56,29 +56,27 @@ class RasterizerCanvasGLES3 : public RendererCanvasRender { _FORCE_INLINE_ void _update_transform_to_mat4(const Transform3D &p_transform, float *p_mat4); enum { + INSTANCE_FLAGS_LIGHT_COUNT_SHIFT = 0, // 4 bits for light count. - FLAGS_INSTANCING_MASK = 0x7F, - FLAGS_INSTANCING_HAS_COLORS = (1 << 7), - FLAGS_INSTANCING_HAS_CUSTOM_DATA = (1 << 8), + INSTANCE_FLAGS_CLIP_RECT_UV = (1 << 4), + INSTANCE_FLAGS_TRANSPOSE_RECT = (1 << 5), + INSTANCE_FLAGS_USE_MSDF = (1 << 6), + INSTANCE_FLAGS_USE_LCD = (1 << 7), - FLAGS_CLIP_RECT_UV = (1 << 9), - FLAGS_TRANSPOSE_RECT = (1 << 10), + INSTANCE_FLAGS_NINEPACH_DRAW_CENTER = (1 << 8), + INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT = 9, + INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT = 11, - FLAGS_NINEPACH_DRAW_CENTER = (1 << 12), - - FLAGS_USE_SKELETON = (1 << 15), - FLAGS_NINEPATCH_H_MODE_SHIFT = 16, - FLAGS_NINEPATCH_V_MODE_SHIFT = 18, - FLAGS_LIGHT_COUNT_SHIFT = 20, - - FLAGS_DEFAULT_NORMAL_MAP_USED = (1 << 26), - FLAGS_DEFAULT_SPECULAR_MAP_USED = (1 << 27), + INSTANCE_FLAGS_SHADOW_MASKED_SHIFT = 13, // 16 bits. + }; - FLAGS_USE_MSDF = (1 << 28), - FLAGS_USE_LCD = (1 << 29), + enum { + BATCH_FLAGS_INSTANCING_MASK = 0x7F, + BATCH_FLAGS_INSTANCING_HAS_COLORS = (1 << 7), + BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA = (1 << 8), - FLAGS_FLIP_H = (1 << 30), - FLAGS_FLIP_V = (1 << 31), + BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED = (1 << 9), + BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED = (1 << 10), }; enum { @@ -281,6 +279,8 @@ public: const Item::Command *command = nullptr; Item::Command::Type command_type = Item::Command::TYPE_ANIMATION_SLICE; // Can default to any type that doesn't form a batch. uint32_t primitive_points = 0; + + uint32_t flags = 0; }; // DataBuffer contains our per-frame data. I.e. the resources that are updated each frame. diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 1ac289d5a2..3857aa8841 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -110,6 +110,9 @@ layout(std140) uniform MaterialUniforms{ //ubo:4 }; #endif + +uniform mediump uint batch_flags; + /* clang-format on */ #include "canvas_uniforms_inc.glsl" @@ -179,13 +182,13 @@ void main() { vec2 uv = uv_attrib; #ifdef USE_INSTANCING - if (bool(read_draw_data_flags & FLAGS_INSTANCING_HAS_COLORS)) { + if (bool(batch_flags & BATCH_FLAGS_INSTANCING_HAS_COLORS)) { vec4 instance_color; instance_color.xy = unpackHalf2x16(uint(instance_color_custom_data.x)); instance_color.zw = unpackHalf2x16(uint(instance_color_custom_data.y)); color *= instance_color; } - if (bool(read_draw_data_flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) { + if (bool(batch_flags & BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA)) { instance_custom.xy = unpackHalf2x16(instance_color_custom_data.z); instance_custom.zw = unpackHalf2x16(instance_color_custom_data.w); } @@ -218,7 +221,7 @@ void main() { else if (vertex_id == 5) vertex_base = vec2(1.0, 1.0); - vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy); + vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & INSTANCE_FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy); vec4 color = read_draw_data_modulation; vec2 vertex = read_draw_data_dst_rect.xy + abs(read_draw_data_dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(read_draw_data_src_rect.zw, vec2(0.0, 0.0))); @@ -336,6 +339,8 @@ uniform sampler2D specular_texture; //texunit:-7 uniform sampler2D color_texture; //texunit:0 +uniform mediump uint batch_flags; + layout(location = 0) out vec4 frag_color; /* clang-format off */ @@ -519,7 +524,7 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo } else if (pixel >= draw_size - margin_end) { return (tex_size - (draw_size - pixel)) * tex_pixel_size; } else { - if (!bool(read_draw_data_flags & FLAGS_NINEPACH_DRAW_CENTER)) { + if (!bool(read_draw_data_flags & INSTANCE_FLAGS_NINEPATCH_DRAW_CENTER)) { draw_center--; } @@ -567,8 +572,8 @@ void main() { int draw_center = 2; uv = vec2( - map_ninepatch_axis(pixel_size_interp.x, abs(read_draw_data_dst_rect_z), read_draw_data_color_texture_pixel_size.x, read_draw_data_ninepatch_margins.x, read_draw_data_ninepatch_margins.z, int(read_draw_data_flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center), - map_ninepatch_axis(pixel_size_interp.y, abs(read_draw_data_dst_rect_w), read_draw_data_color_texture_pixel_size.y, read_draw_data_ninepatch_margins.y, read_draw_data_ninepatch_margins.w, int(read_draw_data_flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center)); + map_ninepatch_axis(pixel_size_interp.x, abs(read_draw_data_dst_rect_z), read_draw_data_color_texture_pixel_size.x, read_draw_data_ninepatch_margins.x, read_draw_data_ninepatch_margins.z, int(read_draw_data_flags >> INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center), + map_ninepatch_axis(pixel_size_interp.y, abs(read_draw_data_dst_rect_w), read_draw_data_color_texture_pixel_size.y, read_draw_data_ninepatch_margins.y, read_draw_data_ninepatch_margins.w, int(read_draw_data_flags >> INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center)); if (draw_center == 0) { color.a = 0.0; @@ -577,7 +582,7 @@ void main() { uv = uv * read_draw_data_src_rect.zw + read_draw_data_src_rect.xy; //apply region if needed #endif - if (bool(read_draw_data_flags & FLAGS_CLIP_RECT_UV)) { + if (bool(read_draw_data_flags & INSTANCE_FLAGS_CLIP_RECT_UV)) { vec2 half_texpixel = read_draw_data_color_texture_pixel_size * 0.5; uv = clamp(uv, read_draw_data_src_rect.xy + half_texpixel, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) - half_texpixel); } @@ -585,7 +590,7 @@ void main() { #endif #ifndef USE_PRIMITIVE - if (bool(read_draw_data_flags & FLAGS_USE_MSDF)) { + if (bool(read_draw_data_flags & INSTANCE_FLAGS_USE_MSDF)) { float px_range = read_draw_data_ninepatch_margins.x; float outline_thickness = read_draw_data_ninepatch_margins.y; @@ -603,7 +608,7 @@ void main() { float a = clamp(d * px_size + 0.5, 0.0, 1.0); color.a = a * color.a; } - } else if (bool(read_draw_data_flags & FLAGS_USE_LCD)) { + } else if (bool(read_draw_data_flags & INSTANCE_FLAGS_USE_LCD)) { vec4 lcd_sample = texture(color_texture, uv); if (lcd_sample.a == 1.0) { color.rgb = lcd_sample.rgb * color.a; @@ -617,7 +622,7 @@ void main() { color *= texture(color_texture, uv); } - uint light_count = (read_draw_data_flags >> uint(FLAGS_LIGHT_COUNT_SHIFT)) & uint(0xF); //max 16 lights + uint light_count = read_draw_data_flags & uint(0xF); // Max 16 lights. bool using_light = light_count > 0u || directional_light_count > 0u; vec3 normal; @@ -628,17 +633,16 @@ void main() { bool normal_used = false; #endif - if (normal_used || (using_light && bool(read_draw_data_flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) { + if (normal_used || (using_light && bool(batch_flags & BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED))) { normal.xy = texture(normal_texture, uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); - if (bool(read_draw_data_flags & FLAGS_TRANSPOSE_RECT)) { + +#if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE) + if (bool(read_draw_data_flags & INSTANCE_FLAGS_TRANSPOSE_RECT)) { normal.xy = normal.yx; } - if (bool(read_draw_data_flags & FLAGS_FLIP_H)) { - normal.x = -normal.x; - } - if (bool(read_draw_data_flags & FLAGS_FLIP_V)) { - normal.y = -normal.y; - } + normal.xy *= sign(read_draw_data_src_rect.zw); +#endif + normal.z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy))); normal_used = true; } else { @@ -654,7 +658,7 @@ void main() { bool specular_shininess_used = false; #endif - if (specular_shininess_used || (using_light && normal_used && bool(read_draw_data_flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) { + if (specular_shininess_used || (using_light && normal_used && bool(batch_flags & BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED))) { specular_shininess = texture(specular_texture, uv); specular_shininess *= godot_unpackUnorm4x8(read_draw_data_specular_shininess); specular_shininess_used = true; @@ -727,7 +731,7 @@ void main() { } #endif - if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) { + if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW) && bool(read_draw_data_flags & uint(INSTANCE_FLAGS_SHADOW_MASKED << i))) { vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array[light_base].shadow_matrix[0], light_array[light_base].shadow_matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. vec4 shadow_uv = vec4(shadow_pos.x, light_array[light_base].shadow_y_ofs, shadow_pos.y * light_array[light_base].shadow_zfar_inv, 1.0); @@ -802,7 +806,7 @@ void main() { } #endif - if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) { + if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW) && bool(read_draw_data_flags & uint(INSTANCE_FLAGS_SHADOW_MASKED << i))) { vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array[light_base].shadow_matrix[0], light_array[light_base].shadow_matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. vec2 pos_norm = normalize(shadow_pos); diff --git a/drivers/gles3/shaders/canvas_uniforms_inc.glsl b/drivers/gles3/shaders/canvas_uniforms_inc.glsl index f6ad2b730a..94cbbdd8a7 100644 --- a/drivers/gles3/shaders/canvas_uniforms_inc.glsl +++ b/drivers/gles3/shaders/canvas_uniforms_inc.glsl @@ -1,33 +1,32 @@ - #define MAX_LIGHTS_PER_ITEM uint(16) #define M_PI 3.14159265359 #define SDF_MAX_LENGTH 16384.0 -//1 means enabled, 2+ means trails in use -#define FLAGS_INSTANCING_MASK uint(0x7F) -#define FLAGS_INSTANCING_HAS_COLORS uint(1 << 7) -#define FLAGS_INSTANCING_HAS_CUSTOM_DATA uint(1 << 8) - -#define FLAGS_CLIP_RECT_UV uint(1 << 9) -#define FLAGS_TRANSPOSE_RECT uint(1 << 10) -// (1 << 11) is for FLAGS_CONVERT_ATTRIBUTES_TO_LINEAR in RD backends, unused here. -#define FLAGS_NINEPACH_DRAW_CENTER uint(1 << 12) +#define INSTANCE_FLAGS_LIGHT_COUNT_SHIFT 0 // 4 bits. -#define FLAGS_NINEPATCH_H_MODE_SHIFT 16 -#define FLAGS_NINEPATCH_V_MODE_SHIFT 18 +#define INSTANCE_FLAGS_CLIP_RECT_UV uint(1 << 4) +#define INSTANCE_FLAGS_TRANSPOSE_RECT uint(1 << 5) +#define INSTANCE_FLAGS_USE_MSDF uint(1 << 6) +#define INSTANCE_FLAGS_USE_LCD uint(1 << 7) -#define FLAGS_LIGHT_COUNT_SHIFT 20 +#define INSTANCE_FLAGS_NINEPATCH_DRAW_CENTER uint(1 << 8) +#define INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT 9 +#define INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT 11 -#define FLAGS_DEFAULT_NORMAL_MAP_USED uint(1 << 26) -#define FLAGS_DEFAULT_SPECULAR_MAP_USED uint(1 << 27) +#define INSTANCE_FLAGS_SHADOW_MASKED_SHIFT 13u // 16 bits. +#define INSTANCE_FLAGS_SHADOW_MASKED uint(1 << INSTANCE_FLAGS_SHADOW_MASKED_SHIFT) -#define FLAGS_USE_MSDF uint(1 << 28) -#define FLAGS_USE_LCD uint(1 << 29) +// 1 means enabled, 2+ means trails in use +#define BATCH_FLAGS_INSTANCING_MASK uint(0x7F) +#define BATCH_FLAGS_INSTANCING_HAS_COLORS_SHIFT 7 +#define BATCH_FLAGS_INSTANCING_HAS_COLORS uint(1 << BATCH_FLAGS_INSTANCING_HAS_COLORS_SHIFT) +#define BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA_SHIFT 8 +#define BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA uint(1 << BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA_SHIFT) -#define FLAGS_FLIP_H uint(1 << 30) -#define FLAGS_FLIP_V uint(1 << 31) +#define BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED uint(1 << 9) +#define BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED uint(1 << 10) layout(std140) uniform GlobalShaderUniformData { //ubo:1 vec4 global_shader_uniforms[MAX_GLOBAL_SHADER_UNIFORMS]; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index fcfbeddb9e..2022c8ee43 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1259,7 +1259,7 @@ float SchlickFresnel(float u) { return m2 * m2 * m; // pow(m,5) } -void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, bool is_directional, float attenuation, vec3 f0, float roughness, float metallic, float specular_amount, vec3 albedo, inout float alpha, +void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, bool is_directional, float attenuation, vec3 f0, float roughness, float metallic, float specular_amount, vec3 albedo, inout float alpha, vec2 screen_uv, #ifdef LIGHT_BACKLIGHT_USED vec3 backlight, #endif @@ -1423,7 +1423,7 @@ float get_omni_spot_attenuation(float distance, float inv_range, float decay) { } #if !defined(DISABLE_LIGHT_OMNI) || defined(ADDITIVE_OMNI) -void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f0, float roughness, float metallic, float shadow, vec3 albedo, inout float alpha, +void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f0, float roughness, float metallic, float shadow, vec3 albedo, inout float alpha, vec2 screen_uv, #ifdef LIGHT_BACKLIGHT_USED vec3 backlight, #endif @@ -1450,7 +1450,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f omni_attenuation *= shadow; - light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, false, omni_attenuation, f0, roughness, metallic, omni_lights[idx].specular_amount, albedo, alpha, + light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, false, omni_attenuation, f0, roughness, metallic, omni_lights[idx].specular_amount, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -1469,7 +1469,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f #endif // !DISABLE_LIGHT_OMNI #if !defined(DISABLE_LIGHT_SPOT) || defined(ADDITIVE_SPOT) -void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f0, float roughness, float metallic, float shadow, vec3 albedo, inout float alpha, +void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f0, float roughness, float metallic, float shadow, vec3 albedo, inout float alpha, vec2 screen_uv, #ifdef LIGHT_BACKLIGHT_USED vec3 backlight, #endif @@ -1506,7 +1506,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f spot_attenuation *= shadow; - light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, false, spot_attenuation, f0, roughness, metallic, spot_lights[idx].specular_amount, albedo, alpha, + light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, false, spot_attenuation, f0, roughness, metallic, spot_lights[idx].specular_amount, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2114,7 +2114,7 @@ void main() { continue; } #endif - light_compute(normal, normalize(directional_lights[i].direction), normalize(view), directional_lights[i].size, directional_lights[i].color * directional_lights[i].energy, true, 1.0, f0, roughness, metallic, 1.0, albedo, alpha, + light_compute(normal, normalize(directional_lights[i].direction), normalize(view), directional_lights[i].size, directional_lights[i].color * directional_lights[i].energy, true, 1.0, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2143,7 +2143,7 @@ void main() { continue; } #endif - light_process_omni(omni_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, + light_process_omni(omni_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2171,7 +2171,7 @@ void main() { continue; } #endif - light_process_spot(spot_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, + light_process_spot(spot_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2389,7 +2389,7 @@ void main() { #endif // SHADOWS_DISABLED #ifndef USE_VERTEX_LIGHTING - light_compute(normal, normalize(directional_lights[directional_shadow_index].direction), normalize(view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, 1.0, albedo, alpha, + light_compute(normal, normalize(directional_lights[directional_shadow_index].direction), normalize(view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2421,7 +2421,7 @@ void main() { #endif // SHADOWS_DISABLED #ifndef USE_VERTEX_LIGHTING - light_process_omni(omni_light_index, vertex, view, normal, f0, roughness, metallic, omni_shadow, albedo, alpha, + light_process_omni(omni_light_index, vertex, view, normal, f0, roughness, metallic, omni_shadow, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif @@ -2451,7 +2451,7 @@ void main() { #endif // SHADOWS_DISABLED #ifndef USE_VERTEX_LIGHTING - light_process_spot(spot_light_index, vertex, view, normal, f0, roughness, metallic, spot_shadow, albedo, alpha, + light_process_spot(spot_light_index, vertex, view, normal, f0, roughness, metallic, spot_shadow, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, #endif diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 3b3f96b136..79428900b6 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -120,7 +120,7 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { last_error = ERR_FILE_CANT_OPEN; return last_error; } - fchmod(fd, 0666); + fchmod(fd, 0644); path = String::utf8(cs.ptr()); f = fdopen(fd, mode_string); diff --git a/drivers/unix/file_access_unix_pipe.cpp b/drivers/unix/file_access_unix_pipe.cpp index 592085ea7c..e12a53cb77 100644 --- a/drivers/unix/file_access_unix_pipe.cpp +++ b/drivers/unix/file_access_unix_pipe.cpp @@ -72,7 +72,7 @@ Error FileAccessUnixPipe::open_internal(const String &p_path, int p_mode_flags) struct stat st = {}; int err = stat(path.utf8().get_data(), &st); if (err) { - if (mkfifo(path.utf8().get_data(), 0666) != 0) { + if (mkfifo(path.utf8().get_data(), 0600) != 0) { last_error = ERR_FILE_CANT_OPEN; return last_error; } diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 440b78e0b7..75bccf048c 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -193,7 +193,7 @@ String OS_Unix::get_stdin_string(int64_t p_buffer_size) { Vector<uint8_t> data; data.resize(p_buffer_size); if (fgets((char *)data.ptrw(), data.size(), stdin)) { - return String::utf8((char *)data.ptr()); + return String::utf8((char *)data.ptr()).replace("\r\n", "\n").rstrip("\n"); } return String(); } |