1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

webgpu: support hsv transforms

This commit is contained in:
Wez Furlong 2022-11-18 10:29:31 -07:00
parent 1f7a34f8b2
commit dad5fbd1f9
No known key found for this signature in database
2 changed files with 27 additions and 3 deletions

View File

@ -33,6 +33,30 @@ struct ShaderUniform {
@group(2) @binding(0) var atlas_nearest_tex: texture_2d<f32>;
@group(2) @binding(1) var atlas_nearest_sampler: sampler;
fn rgb2hsv(c: vec3<f32>) -> vec3<f32>
{
let K = vec4<f32>(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
let p = mix(vec4<f32>(c.bg, K.wz), vec4<f32>(c.gb, K.xy), step(c.b, c.g));
let q = mix(vec4<f32>(p.xyw, c.r), vec4<f32>(c.r, p.yzx), step(p.x, c.r));
let d = q.x - min(q.w, q.y);
let e = 1.0e-10;
return vec3<f32>(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
fn hsv2rgb(c: vec3<f32>) -> vec3<f32>
{
let K = vec4<f32>(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
let p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, vec3(0.0), vec3(1.0)), c.y);
}
fn apply_hsv(c: vec4<f32>, transform: vec3<f32>) -> vec4<f32>
{
let hsv = rgb2hsv(c.rgb) * transform;
return vec4<f32>(hsv2rgb(hsv).rgb, c.a);
}
@vertex
fn vs_main(
model: VertexInput,
@ -76,10 +100,10 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
// and we need to tint with the fg_color
color = fg_color;
color.a = nearest_tex.a;
// color = apply_hsv(color, foreground_text_hsb);
color = apply_hsv(color, uniforms.foreground_text_hsb);
}
// color = apply_hsv(color, in.hsv);
color = apply_hsv(color, in.hsv);
// We MUST output SRGB and tell glium that we do that (outputs_srgb),
// otherwise something in glium over-gamma-corrects depending on the gl setup.

View File

@ -288,7 +288,7 @@ impl WebGpuState {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::VERTEX,
visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,