Skip to content
Open
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
19 changes: 19 additions & 0 deletions ink/rendering/webgpu/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package(
default_applicable_licenses = ["//ink:license"],
default_visibility = ["//ink:__subpackages__"],
)

genrule(
name = "stroke_shader_metal",
srcs = ["StrokeShader.wgsl"],
outs = [
"StrokeShader_vs.metal",
"StrokeShader_fs.metal",
],
cmd = (
"$(location //third_party/dawn:tint) $< --format msl --ep vertexMain -o $(location StrokeShader_vs.metal) && " +
"$(location //third_party/dawn:tint) $< --format msl --ep fragmentMain -o $(location StrokeShader_fs.metal)"
),
tools = ["//third_party/dawn:tint"],
visibility = ["//ink/ios/rendering/metal:__pkg__"],
)
31 changes: 31 additions & 0 deletions ink/rendering/webgpu/StrokeShader.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) color: vec4<f32>,
}

struct Uniforms {
modelTransform: mat4x4<f32>,
viewTransform: mat4x4<f32>,
projectionTransform: mat4x4<f32>,
color: vec4<f32>,
vertexStride: u32,
}

@group(0) @binding(0) var<uniform> uniforms: Uniforms;
@group(0) @binding(1) var<storage, read> vertices: array<f32>;

@vertex
fn vertexMain(@builtin(vertex_index) vertexID: u32) -> VertexOut {
var out: VertexOut;
let floatOffset = (vertexID * uniforms.vertexStride) / 4u;
let pos = vec2<f32>(vertices[floatOffset], vertices[floatOffset + 1u]);

out.position = uniforms.projectionTransform * uniforms.viewTransform * uniforms.modelTransform * vec4<f32>(pos, 0.0, 1.0);
out.color = uniforms.color;
return out;
}

@fragment
fn fragmentMain(in: VertexOut) -> @location(0) vec4<f32> {
return in.color;
}
Loading