1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Does just enough to get the correct (aspect ratio aside) output of scan outlines.

So, up next, can I start streaming these things?
This commit is contained in:
Thomas Harte 2020-08-07 22:20:01 -04:00
parent c575aa0640
commit fbda7aab23
2 changed files with 26 additions and 7 deletions

View File

@ -42,10 +42,10 @@ constexpr size_t NumBufferedScans = 2048;
// Install the standard quad.
constexpr float vertices[] = {
-0.9f, -0.9f,
-0.9f, 0.9f,
0.9f, -0.9f,
0.9f, 0.9f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
};
_quadBuffer = [view.device newBufferWithBytes:vertices length:sizeof(vertices) options:MTLResourceCPUCacheModeDefaultCache];
@ -53,7 +53,7 @@ constexpr size_t NumBufferedScans = 2048;
_uniformsBuffer = [view.device newBufferWithLength:16 options:MTLResourceCPUCacheModeWriteCombined];
const Uniforms testUniforms = {
.scale = {1024, 1024},
.lineWidth = 0.1f
.lineWidth = 1.0f / 312.0f
};
[self setUniforms:testUniforms];
@ -99,7 +99,7 @@ constexpr size_t NumBufferedScans = 2048;
scans[1].scan.end_points[0].x = 0;
scans[1].scan.end_points[0].y = 768;
scans[1].scan.end_points[1].x = 512;
scans[1].scan.end_points[1].y = 128;
scans[1].scan.end_points[1].y = 512;
memcpy(_scansBuffer.contents, scans, sizeof(scans));
}

View File

@ -53,8 +53,27 @@ vertex ColouredVertex scanVertexMain( QuadInputVertex vert [[stage_in]],
constant Uniforms &uniforms [[buffer(1)]],
constant Scan *scans [[buffer(2)]],
ushort instance [[instance_id]]) {
// Unpack start and end vertices.
const float2 start = float2(
float(scans[instance].startPosition & 0xffff) / float(uniforms.scale.x),
float(scans[instance].startPosition >> 16) / float(uniforms.scale.y)
);
const float2 end = float2(
float(scans[instance].endPosition & 0xffff) / float(uniforms.scale.x),
float(scans[instance].endPosition >> 16) / float(uniforms.scale.y)
);
// Calculate the tangent and normal.
const float2 tangent = end - start;
const float2 normal = float2(-tangent.y, tangent.x) / length(tangent);
// Hence determine this quad's real shape.
ColouredVertex output;
output.position = float4(vert.position * uniforms.lineWidth, 0.0, 1.0);
output.position = float4(
(start + vert.position.x * tangent + vert.position.y * normal * uniforms.lineWidth) * float2(2.0, -2.0) + float2(-1.0, 1.0),
0.0,
1.0
);
return output;
}