mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 20:51:29 +11:00
6976f877e0
A fairly simple approach, but it adds the translation (not tested yet in scene encoding) and does bounding box culling.
55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
// A simple kernel to create an image.
|
|
|
|
// Right now, this kernel stores the image in a buffer, but a better
|
|
// plan is to use a texture. This is because of limited support.
|
|
|
|
#version 450
|
|
#extension GL_GOOGLE_include_directive : enable
|
|
|
|
layout(local_size_x = 16, local_size_y = 16) in;
|
|
|
|
layout(set = 0, binding = 0) readonly buffer SceneBuf {
|
|
uint[] scene;
|
|
};
|
|
|
|
layout(set = 0, binding = 1) buffer ImageBuf {
|
|
uint[] image;
|
|
};
|
|
|
|
#include "scene.h"
|
|
|
|
// TODO: make the image size dynamic.
|
|
#define IMAGE_WIDTH 2048
|
|
#define IMAGE_HEIGHT 1535
|
|
|
|
void main() {
|
|
uvec2 xy_uint = gl_GlobalInvocationID.xy;
|
|
vec2 xy = vec2(xy_uint);
|
|
vec2 uv = xy * vec2(1.0 / IMAGE_WIDTH, 1.0 / IMAGE_HEIGHT);
|
|
vec3 rgb = uv.xyy;
|
|
|
|
// Render the scene. Right now, every pixel traverses the scene graph,
|
|
// which is horribly wasteful, but the goal is to get *some* output and
|
|
// then optimize.
|
|
|
|
SimpleGroup group = PietItem_Group_read(PietItemRef(0));
|
|
for (uint i = 0; i < group.n_items; i++) {
|
|
PietItemRef item_ref = PietItem_index(group.items, i);
|
|
uint tag = PietItem_tag(item_ref);
|
|
tag = PietItem_Circle;
|
|
if (tag == PietItem_Circle) {
|
|
PietCircle circle = PietItem_Circle_read(item_ref);
|
|
float r = length(xy + vec2(0.5, 0.5) - circle.center.xy);
|
|
float alpha = clamp(0.5 + circle.radius - r, 0.0, 1.0);
|
|
vec4 fg_rgba = unpackUnorm4x8(circle.rgba_color);
|
|
// TODO: sRGB
|
|
rgb = mix(rgb, fg_rgba.rgb, alpha * fg_rgba.a);
|
|
}
|
|
}
|
|
|
|
// TODO: sRGB
|
|
uvec4 s = uvec4(round(vec4(rgb, 1.0) * 255.0));
|
|
uint rgba_packed = s.r | (s.g << 8) | (s.b << 16) | (s.a << 24);
|
|
image[xy_uint.y * IMAGE_WIDTH + xy_uint.x] = rgba_packed;
|
|
}
|