Skip to content

Commit 439ba2d

Browse files
Ink Open Sourcecopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 897182164
1 parent f031a89 commit 439ba2d

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

ink/rendering/webgpu/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package(
2+
default_applicable_licenses = ["//ink:license"],
3+
default_visibility = ["//ink:__subpackages__"],
4+
)
5+
6+
genrule(
7+
name = "stroke_shader_metal",
8+
srcs = ["StrokeShader.wgsl"],
9+
outs = [
10+
"StrokeShader_vs.metal",
11+
"StrokeShader_fs.metal",
12+
],
13+
cmd = (
14+
"$(location //third_party/dawn:tint) $< --format msl --ep vertexMain -o $(location StrokeShader_vs.metal) && " +
15+
"$(location //third_party/dawn:tint) $< --format msl --ep fragmentMain -o $(location StrokeShader_fs.metal)"
16+
),
17+
tools = ["//third_party/dawn:tint"],
18+
visibility = ["//ink/ios/rendering/metal:__pkg__"],
19+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
struct VertexOut {
2+
@builtin(position) position: vec4<f32>,
3+
@location(0) color: vec4<f32>,
4+
}
5+
6+
struct Uniforms {
7+
modelTransform: mat4x4<f32>,
8+
viewTransform: mat4x4<f32>,
9+
projectionTransform: mat4x4<f32>,
10+
color: vec4<f32>,
11+
vertexStride: u32,
12+
}
13+
14+
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
15+
@group(0) @binding(1) var<storage, read> vertices: array<f32>;
16+
17+
@vertex
18+
fn vertexMain(@builtin(vertex_index) vertexID: u32) -> VertexOut {
19+
var out: VertexOut;
20+
let floatOffset = (vertexID * uniforms.vertexStride) / 4u;
21+
let pos = vec2<f32>(vertices[floatOffset], vertices[floatOffset + 1u]);
22+
23+
out.position = uniforms.projectionTransform * uniforms.viewTransform * uniforms.modelTransform * vec4<f32>(pos, 0.0, 1.0);
24+
out.color = uniforms.color;
25+
return out;
26+
}
27+
28+
@fragment
29+
fn fragmentMain(in: VertexOut) -> @location(0) vec4<f32> {
30+
return in.color;
31+
}

0 commit comments

Comments
 (0)