Files
OneCAD-Draft/src/shaders/image.wgsl
T
Hakan SevenandClaude Sonnet 4.6 4312b6c3a5 feat: raster image render pipeline (IMAGE command + GPU textured quad)
- Add IMAGE / IMAGEATTACH / IM command with async file-picker (rfd)
- src/scene/image_model.rs: ImageModel with RGBA pixel data + quad corners
- src/scene/pipeline/image_gpu.rs: ImageGpu with wgpu texture, sampler, opacity uniform
- src/scene/pipeline/mod.rs: image render pipeline (pass 2, between hatches and meshes)
- src/scene/render.rs: include images in Primitive, call upload_images in prepare
- src/scene/mod.rs: images HashMap, populate_images_from_document, cache on add_entity
- src/modules/home/draw/raster_image.rs: ImageCommand (two-click: origin + width, aspect-correct preview)
- src/io/mod.rs: pick_image_file() async helper (file dialog + dimension decode)
- app: ImagePick / ImagePickResult messages, populate on file open and undo/redo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 23:19:08 +03:00

54 lines
1.8 KiB
WebGPU Shading Language

// Textured-quad shader for raster images (RasterImage entity).
// Renders a four-vertex quad (two triangles) with a sampled texture.
// ── Bind group 0: shared projection uniforms ─────────────────────────────────
struct Uniforms {
mvp: mat4x4<f32>,
view: mat4x4<f32>,
width: f32,
height: f32,
cam_z: f32,
_pad: f32,
};
@group(0) @binding(0) var<uniform> u: Uniforms;
// ── Bind group 1: per-image texture + sampler ────────────────────────────────
@group(1) @binding(0) var img_texture: texture_2d<f32>;
@group(1) @binding(1) var img_sampler: sampler;
// Per-image params (fade, clip flag, etc.)
struct ImageParams {
opacity: f32,
_pad0: f32,
_pad1: f32,
_pad2: f32,
};
@group(1) @binding(2) var<uniform> img_params: ImageParams;
// ── Vertex stage ──────────────────────────────────────────────────────────────
struct VertIn {
@location(0) pos: vec3<f32>,
@location(1) uv: vec2<f32>,
};
struct VertOut {
@builtin(position) clip_pos: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(in: VertIn) -> VertOut {
var out: VertOut;
out.clip_pos = u.mvp * vec4<f32>(in.pos, 1.0);
out.uv = in.uv;
return out;
}
// ── Fragment stage ────────────────────────────────────────────────────────────
@fragment
fn fs_main(in: VertOut) -> @location(0) vec4<f32> {
let col = textureSample(img_texture, img_sampler, in.uv);
return vec4<f32>(col.rgb, col.a * img_params.opacity);
}