From 05e238e9ed5f0c6cade87228f8f3044ee26df756 Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 8 Jun 2023 10:10:26 -0700 Subject: Adjusted offscreen pass to be a render pass vs compute for compat with web-colors flag. --- wgpu/src/shader/offscreen_blit.wgsl | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'wgpu/src/shader/offscreen_blit.wgsl') diff --git a/wgpu/src/shader/offscreen_blit.wgsl b/wgpu/src/shader/offscreen_blit.wgsl index 9c764c36..08952d62 100644 --- a/wgpu/src/shader/offscreen_blit.wgsl +++ b/wgpu/src/shader/offscreen_blit.wgsl @@ -1,22 +1,27 @@ -@group(0) @binding(0) var u_texture: texture_2d; -@group(0) @binding(1) var out_texture: texture_storage_2d; +@group(0) @binding(0) var frame_texture: texture_2d; +@group(0) @binding(1) var frame_sampler: sampler; -fn srgb(color: f32) -> f32 { - if (color <= 0.0031308) { - return 12.92 * color; - } else { - return (1.055 * (pow(color, (1.0/2.4)))) - 0.055; - } +struct VertexInput { + @location(0) v_pos: vec2, + @location(1) texel_coord: vec2, } -@compute @workgroup_size(1) -fn main(@builtin(global_invocation_id) id: vec3) { - // texture coord must be i32 due to a naga bug: - // https://github.com/gfx-rs/naga/issues/1997 - let coords = vec2(i32(id.x), i32(id.y)); +struct VertexOutput { + @builtin(position) clip_pos: vec4, + @location(0) uv: vec2, +} + +@vertex +fn vs_main(input: VertexInput) -> VertexOutput { + var output: VertexOutput; - let src: vec4 = textureLoad(u_texture, coords, 0); - let srgb_color: vec4 = vec4(srgb(src.x), srgb(src.y), srgb(src.z), src.w); + output.clip_pos = vec4(input.v_pos, 0.0, 1.0); + output.uv = input.texel_coord; - textureStore(out_texture, coords, srgb_color); + return output; } + +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { + return textureSample(frame_texture, frame_sampler, input.uv); +} \ No newline at end of file -- cgit