Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the white border in entity #149

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

kokosha
Copy link
Contributor

@kokosha kokosha commented Nov 19, 2024

The goal is to remove the white border in entity.
The alpha blending is bleeding in the border of the texture, because is sampling the transparent part of picture in weighted average, resulting in a white pixel. To correct the problem, the transparent border that is used in weighted average is recolored with color close to the opaque border.
with_border_recoloring
without_border_recoloring

The depth buffer depends on the order of drawing, if you draw a transparent pixel, you can't draw a opaque pixel before the transparent pixel, to fix the problem, we sort by the value of the distance between the camera and the entity and render from farthest to nearest distance to camera.
depth_buffer
depth_buffer_transparent

A small fix is made in the picker, after sorting the entities, the initial entries is not the current player anymore.

// in the picker buffer.
// TODO: Remove the player entity correctly.
for instruction in instructions.entities.iter().skip(player_size) {
for instruction in instructions.entities.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use iter().filter() here

// in the picker buffer.
// TODO: Remove the player entity correctly.
for instruction in instructions.entities.iter().skip(player_size) {
for instruction in instructions.entities.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use iter().filter() here too.

fn get_distance(camera: &dyn Camera, entity: &Entity) -> f32 {
camera.distance_to(entity.get_position())
}
let mut entity_order: Vec<usize> = (0..entities.len()).collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to not allocate every frame inside the hot loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the entity design doesn't allow it.

});

entity_order.iter().for_each(|&index| {
let is_self = index == 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"self" has a pretty well defined meaning in Rust. We should better use "is_player_entity" or somthing similar.

@kokosha
Copy link
Contributor Author

kokosha commented Nov 21, 2024

The new way is changing the alpha from (0.0;1.0] into 1.0, when the entity is opaque. When the entity is transparent, we need to sort to treat the ordering, but even sorting won't solve it all, as the first transparent pixel will overwrite the depth buffer, you will need new techniques such as depth peeling or other order-independent transparency method and is process intensive to fix transparency. Another problem is the way that the entities is structured in the moment doesn't allow easy sorting without affecting hot loop.

@kokosha kokosha marked this pull request as draft November 21, 2024 18:31
@kokosha kokosha marked this pull request as ready for review November 22, 2024 13:08
@kokosha kokosha marked this pull request as draft November 26, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants