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

Dev ivy #10

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
targets: wasm32-unknown-unknown
- run: wasm-pack build --release --target web --out-dir public/pkg
- name: Upload Artefact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: demo
path: ./violet-demo/public
Expand All @@ -36,7 +36,7 @@ jobs:
if: github.event_name == 'push' && ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Download demo
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: demo
path: dist/demo
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/shaders/border_shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct VertexOutput {
struct Object {
world_matrix: mat4x4<f32>,
color: vec4<f32>,
corner_radius: f32,
}

struct Globals {
Expand Down
5 changes: 3 additions & 2 deletions assets/shaders/debug_indicator.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct VertexOutput {
struct Object {
world_matrix: mat4x4<f32>,
color: vec4<f32>,
corner_radius: f32,
}

struct Globals {
Expand All @@ -38,7 +39,7 @@ var fill_image: texture_2d<f32>;
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;
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;
Expand All @@ -65,7 +66,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
// to_nearest.x > in.scale.x - border_size || to_nearest.y > in.scale.y - border_size) {
// border = 1.0;
// }
if (dot(to_nearest, vec2(1.0)) < border_size) {
if dot(to_nearest, vec2(1.0)) < border_size {
border = 1.0;
}

Expand Down
31 changes: 30 additions & 1 deletion assets/shaders/solid.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) color: vec4<f32>,
@location(1) tex_coord: vec2<f32>,
@location(2) frag_pos: vec3<f32>,
@location(3) frag_scale: vec3<f32>,
@location(4) corner_radius: f32,
}

struct Object {
world_matrix: mat4x4<f32>,
color: vec4<f32>,
corner_radius: f32,
}

struct Globals {
Expand All @@ -36,14 +40,39 @@ var fill_image: texture_2d<f32>;
fn vs_main(in: VertexInput) -> VertexOutput {
var out: VertexOutput;
let object = objects[in.instance];


let scale = vec3(object.world_matrix[0][0], object.world_matrix[1][1], object.world_matrix[2][2]);

out.pos = globals.viewproj * object.world_matrix * vec4<f32>(in.pos, 1.0);
out.color = object.color;
out.tex_coord = in.tex_coord;
out.frag_pos = in.pos;
out.frag_scale = abs(scale);
out.corner_radius = object.corner_radius;

return out;
}

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color * textureSample(fill_image, default_sampler, in.tex_coord);
let width = in.frag_scale.x / 2;
let height = in.frag_scale.y / 2;

var alpha = 1f;
let corner_radius = min(in.corner_radius, min(width, height));
if corner_radius != 0.0 {
let midsegment = vec2(width - corner_radius, height - corner_radius);

let local_pos = ((in.frag_pos.xy - 0.5) * in.frag_scale.xy);

let corner_pos = midsegment * sign(local_pos);

let inside_corner = max((vec2(width, height) - corner_radius) - abs(local_pos), vec2(0f));

let corner_cutout = smoothstep(-1f, 1f, corner_radius - length(local_pos - corner_pos)) + inside_corner.x + inside_corner.y;
alpha = min(corner_cutout, 1.0);
}

return in.color * textureSample(fill_image, default_sampler, in.tex_coord) * vec4(1f, 1f, 1f, alpha);
}
1 change: 1 addition & 0 deletions assets/shaders/text.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct VertexOutput {
struct Object {
world_matrix: mat4x4<f32>,
color: vec4<f32>,
corner_radius: f32,
}

struct Globals {
Expand Down
Loading
Loading