-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve performance for non-coupled size widgets
- Loading branch information
1 parent
8865ddb
commit 40626c8
Showing
19 changed files
with
430 additions
and
165 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
struct VertexInput { | ||
@location(0) pos: vec3<f32>, | ||
@location(1) color: vec4<f32>, | ||
@location(2) tex_coord: vec2<f32>, | ||
@builtin(instance_index) instance: u32, | ||
} | ||
|
||
struct VertexOutput { | ||
@builtin(position) pos: vec4<f32>, | ||
@location(0) color: vec4<f32>, | ||
@location(1) tex_coord: vec2<f32>, | ||
@location(2) vertex_pos: vec3<f32>, | ||
@location(3) scale: vec2<f32>, | ||
} | ||
|
||
struct Object { | ||
world_matrix: mat4x4<f32>, | ||
color: vec4<f32>, | ||
} | ||
|
||
struct Globals { | ||
viewproj: mat4x4<f32>, | ||
} | ||
|
||
@group(0) @binding(0) | ||
var<uniform> globals: Globals; | ||
|
||
@group(1) @binding(0) | ||
var<uniform> objects: array<Object, 32>; | ||
|
||
@group(2) @binding(0) | ||
var default_sampler: sampler; | ||
|
||
@group(2) @binding(1) | ||
var fill_image: texture_2d<f32>; | ||
|
||
@vertex | ||
fn vs_main(in: VertexInput) -> VertexOutput { | ||
var out: VertexOutput; | ||
let object = objects[in.instance]; | ||
let scale = (object.world_matrix * vec4(1.0, 1.0, 0.0, 0.0)).xy; | ||
out.pos = globals.viewproj * object.world_matrix * vec4<f32>(in.pos, 1.0); | ||
out.color = object.color; | ||
out.tex_coord = in.tex_coord; | ||
out.vertex_pos = in.pos; | ||
out.scale = scale; | ||
|
||
return out; | ||
} | ||
|
||
@fragment | ||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { | ||
|
||
let nearest_corner = vec2<f32>(select(0.0, in.scale.x, in.vertex_pos.x > 0.5), select(0.0, in.scale.y, in.vertex_pos.y > 0.5)); | ||
let to_nearest = abs(in.vertex_pos.xy * in.scale - nearest_corner); | ||
|
||
// return vec4(length(nearest_corner - in.pos.xy) / 100.0); | ||
let dist = max(1.0 - length(to_nearest) * 0.1, 0.0); | ||
// return vec4(0.0, 0.0, dist, 1.0); | ||
let border_size = 2.0; | ||
|
||
var border = 0.0; | ||
|
||
if to_nearest.x < border_size || to_nearest.y < border_size || to_nearest.x > in.scale.x - border_size || to_nearest.y > in.scale.y - border_size { | ||
border = 1.0; | ||
} | ||
|
||
return in.color * textureSample(fill_image, default_sampler, in.tex_coord) * border; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.