-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: main
Are you sure you want to change the base?
Conversation
// 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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
korangar/src/world/map/mod.rs
Outdated
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
korangar/src/world/map/mod.rs
Outdated
}); | ||
|
||
entity_order.iter().for_each(|&index| { | ||
let is_self = index == 0; |
There was a problem hiding this comment.
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.
e434049
to
8506d84
Compare
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. |
9131055
to
66ff7c1
Compare
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.
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.
A small fix is made in the picker, after sorting the entities, the initial entries is not the current player anymore.