diff --git a/crates/graphics/src/lib.rs b/crates/graphics/src/lib.rs index 8ce9a7e1..be408013 100644 --- a/crates/graphics/src/lib.rs +++ b/crates/graphics/src/lib.rs @@ -113,8 +113,10 @@ impl GraphicsState { } pub fn push_constants_supported(render_state: &egui_wgpu::RenderState) -> bool { - render_state + let feature_supported = render_state .device .features() - .contains(wgpu::Features::PUSH_CONSTANTS) + .contains(wgpu::Features::PUSH_CONSTANTS); + let is_dx_12 = render_state.adapter.get_info().backend == wgpu::Backend::Dx12; + feature_supported && !is_dx_12 } diff --git a/crates/graphics/src/sprite/mod.rs b/crates/graphics/src/sprite/mod.rs index 270dec36..04968cae 100644 --- a/crates/graphics/src/sprite/mod.rs +++ b/crates/graphics/src/sprite/mod.rs @@ -91,6 +91,7 @@ impl Sprite { graphics_state: &'rpass GraphicsState, render_pass: &mut wgpu::RenderPass<'rpass>, ) { + render_pass.push_debug_group("sprite render"); render_pass.set_pipeline(&graphics_state.pipelines.sprites[&self.blend_mode]); render_pass.set_bind_group(0, &self.bind_group, &[]); @@ -108,6 +109,7 @@ impl Sprite { } self.vertices.draw(render_pass); + render_pass.pop_debug_group(); } } diff --git a/crates/graphics/src/sprite/sprite.wgsl b/crates/graphics/src/sprite/sprite.wgsl index 7f8ca28a..d9f66723 100644 --- a/crates/graphics/src/sprite/sprite.wgsl +++ b/crates/graphics/src/sprite/sprite.wgsl @@ -78,6 +78,19 @@ fn vs_main( return out; } +// 0-1 sRGB gamma from 0-1 linear +fn gamma_from_linear_rgb(rgb: vec3) -> vec3 { + let cutoff = rgb < vec3(0.0031308); + let lower = rgb * vec3(12.92); + let higher = vec3(1.055) * pow(rgb, vec3(1.0 / 2.4)) - vec3(0.055); + return select(higher, lower, cutoff); +} + +// 0-1 sRGBA gamma from 0-1 linear +fn gamma_from_linear_rgba(linear_rgba: vec4) -> vec4 { + return vec4(gamma_from_linear_rgb(linear_rgba.rgb), linear_rgba.a); +} + @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { var tex_sample = textureSample(t_diffuse, s_diffuse, in.tex_coords); @@ -98,5 +111,5 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4 { tex_sample = vec4(hsv_to_rgb(hsv), tex_sample.a); } - return tex_sample; + return gamma_from_linear_rgba(tex_sample); } diff --git a/crates/graphics/src/tiles/atlas.rs b/crates/graphics/src/tiles/atlas.rs index 9a959478..98068844 100644 --- a/crates/graphics/src/tiles/atlas.rs +++ b/crates/graphics/src/tiles/atlas.rs @@ -153,7 +153,7 @@ impl Atlas { dimension: wgpu::TextureDimension::D2, mip_level_count: 1, sample_count: 1, - format: wgpu::TextureFormat::Rgba8Unorm, + format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, diff --git a/crates/graphics/src/tiles/tilemap.wgsl b/crates/graphics/src/tiles/tilemap.wgsl index d3c85bd0..a8873b50 100644 --- a/crates/graphics/src/tiles/tilemap.wgsl +++ b/crates/graphics/src/tiles/tilemap.wgsl @@ -112,6 +112,18 @@ fn vs_main(vertex: VertexInput, instance: InstanceInput) -> VertexOutput { return out; } +// 0-1 sRGB gamma from 0-1 linear +fn gamma_from_linear_rgb(rgb: vec3) -> vec3 { + let cutoff = rgb < vec3(0.0031308); + let lower = rgb * vec3(12.92); + let higher = vec3(1.055) * pow(rgb, vec3(1.0 / 2.4)) - vec3(0.055); + return select(higher, lower, cutoff); +} + +// 0-1 sRGBA gamma from 0-1 linear +fn gamma_from_linear_rgba(linear_rgba: vec4) -> vec4 { + return vec4(gamma_from_linear_rgb(linear_rgba.rgb), linear_rgba.a); +} @fragment fn fs_main(input: VertexOutput) -> @location(0) vec4 { @@ -128,5 +140,5 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4 { discard; } - return color; + return gamma_from_linear_rgba(color); }