Skip to content

Commit

Permalink
Render SDF sharp for the in-game UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenbanck committed Dec 17, 2024
1 parent 92d3c57 commit 080a5b6
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 6 deletions.
Binary file modified korangar/archive/data/texture/marker_entity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified korangar/archive/data/texture/marker_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified korangar/archive/data/texture/marker_object.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified korangar/archive/data/texture/marker_particle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified korangar/archive/data/texture/marker_shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified korangar/archive/data/texture/marker_sound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion korangar/src/graphics/passes/interface/shader/rectangle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
case 1u: {
// SDF
let pixel = textureSample(texture, linear_sampler, input.texture_coordinates);
color *= vec4(pixel.rgb, saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a)));
let alpha = saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a));
color *= vec4(pixel.rgb * alpha, alpha);
}
case 2u: {
// Sprite (linear filtering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
case 1u: {
// SDF
let pixel = textureSample(textures[instance.texture_index], linear_sampler, input.texture_coordinates);
color *= vec4(pixel.rgb, saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a)));
let alpha = saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a));
color *= vec4(pixel.rgb * alpha, alpha);
}
case 2u: {
// Sprite (linear filtering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
case 1u: {
// SDF
let pixel = textureSample(texture, linear_sampler, input.texture_coordinates);
return vec4(pixel.rgb, saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a))) * instance.color;
let alpha = step(0.5, pixel.a);
return vec4(pixel.rgb * alpha, alpha) * instance.color;
}
case 2u: {
// Sprite (linear filtering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
case 1u: {
// SDF
let pixel = textureSample(textures[instance.texture_index], linear_sampler, input.texture_coordinates);
return vec4(pixel.rgb, saturate((pixel.a - 0.5) * 2.0 / fwidth(pixel.a))) * instance.color;
let alpha = step(0.5, pixel.a);
return vec4(pixel.rgb * alpha, alpha) * instance.color;
}
case 2u: {
// Sprite (linear filtering)
Expand Down
3 changes: 1 addition & 2 deletions korangar/src/renderer/game_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,12 @@ impl MarkerRenderer for GameInterfaceRenderer {
MarkerIdentifier::Shadow(..) => (&self.shadow_marker_texture, Color::rgb_u8(170, 170, 170)),
};

self.instructions.borrow_mut().push(RectangleInstruction::Sprite {
self.instructions.borrow_mut().push(RectangleInstruction::Sdf {
screen_position,
screen_size,
color,
texture_position: Vector2::new(0.0, 0.0),
texture_size: Vector2::new(1.0, 1.0),
linear_filtering: true,
texture: texture.clone(),
});
}
Expand Down

0 comments on commit 080a5b6

Please sign in to comment.