diff options
author | George L. Albany <Megacake1234@gmail.com> | 2024-11-26 19:30:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 19:30:58 +0000 |
commit | b06d20bf39d15ec736d08d4e4fcb32e0c3c1ce1e (patch) | |
tree | 79c2a4c34f2d888ff962d76edf474c518d1abdea /servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp | |
parent | c5b1645e60a59c0292c04bece3fdb0715a61afea (diff) | |
parent | e58e18261ea7ed3978146ef8d77a900be2601be3 (diff) | |
download | redot-engine-b06d20bf39d15ec736d08d4e4fcb32e0c3c1ce1e.tar.gz |
Merge pull request #885 from Spartan322/merge/d09d82d
Merge commit godotengine/godot@d09d82d
Diffstat (limited to 'servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp')
-rw-r--r-- | servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 3244c763ef..8dcc6b1e1e 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -668,6 +668,8 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p RD::get_singleton()->buffer_update(state.lights_uniform_buffer, 0, sizeof(LightUniform) * light_count, &state.light_uniforms[0]); } + bool use_linear_colors = texture_storage->render_target_is_using_hdr(p_to_render_target); + { //update canvas state uniform buffer State::Buffer state_buffer; @@ -686,7 +688,6 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p normal_transform.columns[2] = Vector2(); _update_transform_2d_to_mat4(normal_transform, state_buffer.canvas_normal_transform); - bool use_linear_colors = texture_storage->render_target_is_using_hdr(p_to_render_target); Color modulate = p_modulate; if (use_linear_colors) { modulate = p_modulate.srgb_to_linear(); @@ -724,6 +725,8 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p //print_line("w: " + itos(ssize.width) + " s: " + rtos(canvas_scale)); state_buffer.tex_to_sdf = 1.0 / ((canvas_scale.x + canvas_scale.y) * 0.5); + state_buffer.flags = use_linear_colors ? CANVAS_FLAGS_CONVERT_ATTRIBUTES_TO_LINEAR : 0; + RD::get_singleton()->buffer_update(state.canvas_state_buffer, 0, sizeof(State::Buffer), &state_buffer); } @@ -754,8 +757,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p RenderTarget to_render_target; to_render_target.render_target = p_to_render_target; - bool use_linear_colors = texture_storage->render_target_is_using_hdr(p_to_render_target); - to_render_target.base_flags = use_linear_colors ? FLAGS_CONVERT_ATTRIBUTES_TO_LINEAR : 0; + to_render_target.use_linear_colors = use_linear_colors; while (ci) { if (ci->copy_back_buffer && canvas_group_owner == nullptr) { @@ -2246,7 +2248,7 @@ RendererCanvasRenderRD::InstanceData *RendererCanvasRenderRD::new_instance_data( instance_data->world[i] = p_world[i]; } - instance_data->flags = p_base_flags | p_info->flags; // Reset on each command for safety, keep canvas texture binding config. + instance_data->flags = p_base_flags; // Reset on each command for safety. instance_data->color_texture_pixel_size[0] = p_info->texpixel_size.width; instance_data->color_texture_pixel_size[1] = p_info->texpixel_size.height; @@ -2267,8 +2269,8 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar _update_transform_2d_to_mat2x3(base_transform, world); Color base_color = p_item->final_modulate; - bool use_linear_colors = bool(p_render_target.base_flags & FLAGS_CONVERT_ATTRIBUTES_TO_LINEAR); - uint32_t base_flags = p_render_target.base_flags; + bool use_linear_colors = p_render_target.use_linear_colors; + uint32_t base_flags = 0; bool reclip = false; @@ -2278,6 +2280,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar uint32_t lights[4] = { 0, 0, 0, 0 }; uint16_t light_count = 0; + uint16_t shadow_mask = 0; { Light *light = p_lights; @@ -2287,6 +2290,10 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar 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 == MAX_LIGHTS_PER_ITEM - 1) { @@ -2296,7 +2303,8 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar 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 use_lighting = (light_count > 0 || using_directional_lights); @@ -2325,6 +2333,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar // default variant r_current_batch->shader_variant = SHADER_VARIANT_QUAD; r_current_batch->render_primitive = RD::RENDER_PRIMITIVE_TRIANGLES; + r_current_batch->flags = 0; } RenderingServer::CanvasItemTextureRepeat rect_repeat = texture_repeat; @@ -2380,20 +2389,18 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar if (rect->flags & CANVAS_RECT_FLIP_H) { src_rect.size.x *= -1; - instance_data->flags |= FLAGS_FLIP_H; } if (rect->flags & CANVAS_RECT_FLIP_V) { src_rect.size.y *= -1; - instance_data->flags |= FLAGS_FLIP_V; } if (rect->flags & CANVAS_RECT_TRANSPOSE) { - instance_data->flags |= FLAGS_TRANSPOSE_RECT; + instance_data->flags |= INSTANCE_FLAGS_TRANSPOSE_RECT; } if (rect->flags & CANVAS_RECT_CLIP_UV) { - instance_data->flags |= FLAGS_CLIP_RECT_UV; + instance_data->flags |= INSTANCE_FLAGS_CLIP_RECT_UV; } } else { @@ -2412,13 +2419,13 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar } if (has_msdf) { - instance_data->flags |= FLAGS_USE_MSDF; + instance_data->flags |= INSTANCE_FLAGS_USE_MSDF; instance_data->msdf[0] = rect->px_range; // Pixel range. instance_data->msdf[1] = rect->outline; // Outline size. instance_data->msdf[2] = 0.f; // Reserved. instance_data->msdf[3] = 0.f; // Reserved. } else if (rect->flags & CANVAS_RECT_LCD) { - instance_data->flags |= FLAGS_USE_LCD; + instance_data->flags |= INSTANCE_FLAGS_USE_LCD; } instance_data->modulation[0] = modulated.r; @@ -2449,6 +2456,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch->has_blend = false; r_current_batch->shader_variant = SHADER_VARIANT_NINEPATCH; r_current_batch->render_primitive = RD::RENDER_PRIMITIVE_TRIANGLES; + r_current_batch->flags = 0; } TextureState tex_state(np->texture, texture_filter, texture_repeat, false, use_linear_colors); @@ -2500,11 +2508,11 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar instance_data->dst_rect[2] = dst_rect.size.width; instance_data->dst_rect[3] = dst_rect.size.height; - instance_data->flags |= int(np->axis_x) << FLAGS_NINEPATCH_H_MODE_SHIFT; - instance_data->flags |= int(np->axis_y) << FLAGS_NINEPATCH_V_MODE_SHIFT; + instance_data->flags |= int(np->axis_x) << INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT; + instance_data->flags |= int(np->axis_y) << INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT; if (np->draw_center) { - instance_data->flags |= FLAGS_NINEPACH_DRAW_CENTER; + instance_data->flags |= INSTANCE_FLAGS_NINEPACH_DRAW_CENTER; } instance_data->ninepatch_margins[0] = np->margin[SIDE_LEFT]; @@ -2524,6 +2532,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch->command_type = Item::Command::TYPE_POLYGON; r_current_batch->has_blend = false; r_current_batch->command = c; + r_current_batch->flags = 0; TextureState tex_state(polygon->texture, texture_filter, texture_repeat, false, use_linear_colors); TextureInfo *tex_info = texture_info_map.getptr(tex_state); @@ -2568,6 +2577,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch->has_blend = false; r_current_batch->command = c; r_current_batch->primitive_points = primitive->point_count; + r_current_batch->flags = 0; ERR_CONTINUE(primitive->point_count == 0 || primitive->point_count > 4); @@ -2650,6 +2660,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch->command = c; r_current_batch->command_type = c->type; r_current_batch->has_blend = false; + r_current_batch->flags = 0; InstanceData *instance_data = nullptr; @@ -2692,13 +2703,13 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch->tex_info = tex_info; instance_data = new_instance_data(world, lights, base_flags, r_index, tex_info); - instance_data->flags |= 1; // multimesh, trails disabled + r_current_batch->flags |= 1; // multimesh, trails disabled if (mesh_storage->multimesh_uses_colors(mm->multimesh)) { - instance_data->flags |= FLAGS_INSTANCING_HAS_COLORS; + r_current_batch->flags |= BATCH_FLAGS_INSTANCING_HAS_COLORS; } if (mesh_storage->multimesh_uses_custom_data(mm->multimesh)) { - instance_data->flags |= FLAGS_INSTANCING_HAS_CUSTOM_DATA; + r_current_batch->flags |= BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA; } } else if (c->type == Item::Command::TYPE_PARTICLES) { RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); @@ -2716,13 +2727,13 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar uint32_t divisor = 1; r_current_batch->mesh_instance_count = particles_storage->particles_get_amount(pt->particles, divisor); - instance_data->flags |= (divisor & FLAGS_INSTANCING_MASK); + r_current_batch->flags |= (divisor & BATCH_FLAGS_INSTANCING_MASK); r_current_batch->mesh_instance_count /= divisor; RID particles = pt->particles; - instance_data->flags |= FLAGS_INSTANCING_HAS_COLORS; - instance_data->flags |= FLAGS_INSTANCING_HAS_CUSTOM_DATA; + r_current_batch->flags |= BATCH_FLAGS_INSTANCING_HAS_COLORS; + r_current_batch->flags |= BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA; if (particles_storage->particles_has_collision(particles) && texture_storage->render_target_is_sdf_enabled(p_render_target.render_target)) { // Pass collision information. @@ -2808,6 +2819,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar // default variant r_current_batch->shader_variant = SHADER_VARIANT_QUAD; r_current_batch->render_primitive = RD::RENDER_PRIMITIVE_TRIANGLES; + r_current_batch->flags = 0; } // 2: If the current batch has lighting, start a new batch. @@ -2922,6 +2934,7 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, CanvasSha PushConstant push_constant; push_constant.base_instance_index = p_batch->start; push_constant.specular_shininess = p_batch->tex_info->specular_shininess; + push_constant.batch_flags = p_batch->tex_info->flags | p_batch->flags; RID pipeline; PipelineKey pipeline_key; @@ -3170,11 +3183,11 @@ void RendererCanvasRenderRD::_prepare_batch_texture_info(RID p_texture, TextureS // cache values to be copied to instance data if (info.specular_color.a < 0.999) { - p_info->flags |= FLAGS_DEFAULT_SPECULAR_MAP_USED; + p_info->flags |= BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED; } if (info.use_normal) { - p_info->flags |= FLAGS_DEFAULT_NORMAL_MAP_USED; + p_info->flags |= BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED; } uint8_t a = uint8_t(CLAMP(info.specular_color.a * 255.0, 0.0, 255.0)); |