tirbofish/dropbear · commit
e4ca62f6c3ef70816087a0729def7cd617e4b467
feature: hdr
Signature present but could not be verified.
Unverified
@@ -13,6 +13,7 @@ use wgpu::*; use winit::window::Window; use crate::mipmap::MipMapper; +use crate::pipelines::hdr::HdrPipeline; pub const NO_TEXTURE: &[u8] = include_bytes!("../../../resources/textures/no-texture.png"); @@ -32,6 +33,7 @@ pub struct SharedGraphicsContext { pub future_queue: Arc<FutureQueue>, pub supports_storage: bool, pub mipmapper: Arc<MipMapper>, + pub hdr: Arc<RwLock<HdrPipeline>>, // pub yakui_renderer: Arc<Mutex<yakui_wgpu::YakuiWgpu>>, // pub yakui_texture: yakui::TextureId, } @@ -76,6 +78,7 @@ impl SharedGraphicsContext { surface_format: state.surface_format, supports_storage: state.supports_storage, mipmapper: state.mipmapper.clone(), + hdr: state.hdr.clone(), // yakui_renderer: state.yakui_renderer.clone(), // yakui_texture: state.yakui_texture.clone(), surface_config: state.config.clone(), @@ -62,7 +62,7 @@ pub use gilrs; pub use wgpu; pub use winit; use winit::window::{WindowAttributes, WindowId}; -// use crate::pipelines::hdr::HdrPipeline; +use crate::pipelines::hdr::HdrPipeline; use crate::scene::Scene; pub struct BindGroupLayouts { @@ -95,7 +95,7 @@ pub struct State { pub texture_id: Arc<TextureId>, pub future_queue: Arc<FutureQueue>, pub mipmapper: Arc<MipMapper>, - // pub hdr: Arc<HdrPipeline>, + pub hdr: Arc<RwLock<HdrPipeline>>, physics_accumulator: Duration, @@ -214,16 +214,16 @@ Hardware: let surface_caps = surface.get_capabilities(&adapter); - // let surface_format = surface_caps - // .formats - // .iter() - // .find(|f| f.is_srgb()) - // .copied() - // .unwrap_or(TextureFormat::Rgba16Float); + let surface_format = surface_caps + .formats + .iter() + .find(|f| f.is_srgb()) + .copied() + .unwrap_or(TextureFormat::Rgba16Float); let config = SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: Texture::TEXTURE_FORMAT, + format: surface_format, width: initial_width, height: initial_height, present_mode: surface_caps.present_modes[0], @@ -245,7 +245,7 @@ Hardware: let mut egui_renderer = Arc::new(Mutex::new(EguiRenderer::new( &device, - Texture::TEXTURE_FORMAT, + surface_format, None, 1, &window, @@ -335,7 +335,11 @@ Hardware: let device = Arc::new(device); let queue = Arc::new(queue); - // let hdr = Arc::new(HdrPipeline::new(&device, &config)); + let hdr = Arc::new(RwLock::new(HdrPipeline::new( + &device, + &config, + Texture::TEXTURE_FORMAT, + ))); // let yakui_renderer = Arc::new(Mutex::new(yakui_wgpu::YakuiWgpu::new( // &device, @@ -352,7 +356,7 @@ Hardware: let result = Self { surface: Arc::new(surface), - surface_format: Texture::TEXTURE_FORMAT, + surface_format, device, queue, config: Arc::new(RwLock::new(config)), @@ -379,7 +383,7 @@ Hardware: supports_storage: supports_storage_resources, // yakui_renderer, // yakui_texture, - // hdr, + hdr, }; Ok(result) @@ -395,8 +399,7 @@ Hardware: } self.surface.configure(&self.device, &self.config.read()); self.is_surface_configured = true; - // Arc::get_mut(&mut self.hdr) - // .resize(&self.device, width, height); + self.hdr.write().resize(&self.device, width, height); } self.depth_texture = @@ -470,11 +473,12 @@ Hardware: let mut encoder = CommandEncoder::new(graphics.clone(), Some("surface clear render encoder")); { + let hdr = self.hdr.read(); let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("surface clear pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - // view: &self.hdr.view(), - view: &view, + view: hdr.view(), + // view: &view, depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -528,6 +532,11 @@ Hardware: label: Some("egui render encoder"), }); + { + let hdr = self.hdr.read(); + hdr.process(&mut encoder, &self.viewport_texture.view); + } + self.egui_renderer.lock().end_frame_and_draw( &self.device, &self.queue, @@ -271,10 +271,7 @@ impl Light { label: Option<&str>, ) -> Self { let forward = DVec3::new(0.0, 0.0, -1.0); - let mut direction = transform.rotation * forward; - if matches!(light.light_type, LightType::Directional) { - direction = -direction; - } + let direction = transform.rotation * forward; let uniform = LightUniform { position: dvec3_to_uniform_array(transform.position), @@ -343,10 +340,7 @@ impl Light { self.uniform.position = dvec3_to_uniform_array(transform.position); let forward = DVec3::new(0.0, 0.0, -1.0); - let mut direction = transform.rotation * forward; - if matches!(light.light_type, LightType::Directional) { - direction = -direction; - } + let direction = transform.rotation * forward; self.uniform.direction = dvec3_direction_to_uniform_array(direction, light.outer_cutoff_angle); @@ -13,7 +13,11 @@ pub struct HdrPipeline { } impl HdrPipeline { - pub fn new(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> Self { + pub fn new( + device: &wgpu::Device, + config: &wgpu::SurfaceConfiguration, + output_format: wgpu::TextureFormat, + ) -> Self { let width = config.width; let height = config.height; @@ -82,7 +86,7 @@ impl HdrPipeline { Some("hdr render pipeline"), device, &pipeline_layout, - config.format.add_srgb_suffix(), + output_format, None, // We'll use some math to generate the vertex data in // the shader, so we don't need any vertex buffers @@ -38,6 +38,7 @@ impl DropbearShaderPipeline for LightCubePipeline { push_constant_ranges: &[], }); + let hdr_format = graphics.hdr.read().format(); let pipeline = graphics.device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("light cube pipeline"), layout: Some(&pipeline_layout), @@ -56,7 +57,7 @@ impl DropbearShaderPipeline for LightCubePipeline { module: &shader.module, entry_point: Some("fs_main"), targets: &[Some(wgpu::ColorTargetState { - format: Texture::TEXTURE_FORMAT, + format: hdr_format, blend: Some(wgpu::BlendState { alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, @@ -5,7 +5,7 @@ use crate::shader::Shader; pub mod shader; pub mod light_cube; pub mod globals; -// pub mod hdr; +pub mod hdr; pub use globals::{Globals, GlobalsUniform}; @@ -38,6 +38,7 @@ impl DropbearShaderPipeline for MainRenderPipeline { push_constant_ranges: &[], }); + let hdr_format = graphics.hdr.read().format(); let pipeline = graphics.device .create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -57,7 +58,7 @@ impl DropbearShaderPipeline for MainRenderPipeline { Some("u_fs_main") }, targets: &[Some(wgpu::ColorTargetState { - format: Texture::TEXTURE_FORMAT, + format: hdr_format, blend: Some(wgpu::BlendState::REPLACE), write_mask: wgpu::ColorWrites::ALL, })], @@ -34,6 +34,7 @@ impl DropbearShaderPipeline for ColliderWireframePipeline { push_constant_ranges: &[], }); + let hdr_format = graphics.hdr.read().format(); let pipeline = graphics.device.create_render_pipeline(&RenderPipelineDescriptor { label: Some("Collider Wireframe Pipeline"), layout: Some(&pipeline_layout), @@ -60,7 +61,7 @@ impl DropbearShaderPipeline for ColliderWireframePipeline { module: &shader.module, entry_point: Some("fs_main"), targets: &[Some(ColorTargetState { - format: Texture::TEXTURE_FORMAT, + format: hdr_format, blend: Some(BlendState::ALPHA_BLENDING), write_mask: ColorWrites::ALL, })], @@ -481,7 +481,7 @@ fn inspect_light_transform( if ui.button("Reset Rotation").clicked() { transform.rotation = glam::DQuat::IDENTITY; - cfg.transform_rotation_cache.insert(*entity, DVec3::ZERO); + cfg.transform_rotation_cache.insert(*entity, DVec3::NEG_Y); } ui.add_space(5.0); } @@ -351,6 +351,8 @@ impl Scene for Editor { self.texture_id = Some(*graphics.texture_id.clone()); self.window = Some(graphics.window.clone()); + let hdr = graphics.hdr.read(); + self.show_ui(&graphics.get_egui_context()); let clear_color = Color { r: 100.0 / 255.0, @@ -394,7 +396,7 @@ impl Scene for Editor { let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("viewport clear pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -503,7 +505,7 @@ impl Scene for Editor { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("light cube render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -551,7 +553,7 @@ impl Scene for Editor { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("model render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -601,7 +603,7 @@ impl Scene for Editor { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("model render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -220,11 +220,12 @@ impl PlayMode { self.shader_globals = Some(GlobalsUniform::new(graphics.clone(), Some("runtime shader globals"))); self.collider_wireframe_pipeline = Some(ColliderWireframePipeline::new(graphics.clone())); + let hdr_format = graphics.hdr.read().format(); self.kino = Some(KinoState::new( KinoWGPURenderer::new( &graphics.device, &graphics.queue, - Texture::TEXTURE_FORMAT, + hdr_format, [ graphics.viewport_texture.size.width as f32, graphics.viewport_texture.size.height as f32, @@ -618,6 +618,8 @@ impl Scene for PlayMode { a: 1.0, }; + let hdr = graphics.hdr.read(); + let mut encoder = CommandEncoder::new(graphics.clone(), Some("runtime viewport encoder")); let Some(active_camera) = self.active_camera else { @@ -646,7 +648,7 @@ impl Scene for PlayMode { let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("viewport clear pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -755,7 +757,7 @@ impl Scene for PlayMode { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("light cube render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -802,7 +804,7 @@ impl Scene for PlayMode { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("model render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -853,7 +855,7 @@ impl Scene for PlayMode { .begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("model render pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &graphics.viewport_texture.view, + view: hdr.view(), depth_slice: None, resolve_target: None, ops: wgpu::Operations { @@ -994,7 +996,7 @@ impl Scene for PlayMode { if let Some(kino) = &mut self.kino { let mut encoder = CommandEncoder::new(graphics.clone(), Some("kino encoder")); - kino.render(&graphics.device, &graphics.queue, &mut encoder, &graphics.viewport_texture.view); + kino.render(&graphics.device, &graphics.queue, &mut encoder, hdr.view()); if let Err(e) = encoder.submit() { log_once::error_once!("Unable to submit kino: {}", e); }