HDR rendering
This commit is contained in:
parent
2b185c43da
commit
b59d0b1a10
|
|
@ -50,8 +50,9 @@ fn main() {
|
|||
let envmap = load_envmap(&device, &queue);
|
||||
queue.submit([]);
|
||||
|
||||
let format = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
let mut tracer = Tracer::new(&device, format);
|
||||
let output_format = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
let hdr_format = wgpu::TextureFormat::Rgba16Float;
|
||||
let mut tracer = Tracer::new(&device, hdr_format);
|
||||
let sphere_params: Vec<_> = {
|
||||
let mut rng = rand_pcg::Pcg32::new(42, 0);
|
||||
let distr = anim::SphereParamsDistribution::default();
|
||||
|
|
@ -59,7 +60,7 @@ fn main() {
|
|||
};
|
||||
let tracer_env = TracerEnv::new(&device, &tracer, &envmap);
|
||||
|
||||
let presenter = Presenter::new(&device, format);
|
||||
let presenter = Presenter::new(&device, output_format);
|
||||
|
||||
let mut frame = 0;
|
||||
let mut time = 0.0;
|
||||
|
|
@ -75,7 +76,7 @@ fn main() {
|
|||
&device,
|
||||
&wgpu::SurfaceConfiguration {
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST,
|
||||
format,
|
||||
format: output_format,
|
||||
width: physical_size.width,
|
||||
height: physical_size.height,
|
||||
present_mode: wgpu::PresentMode::Fifo,
|
||||
|
|
@ -109,7 +110,7 @@ fn main() {
|
|||
let output = surface.get_current_texture().unwrap();
|
||||
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let size = output.texture.size();
|
||||
let buf = device.create_texture(&wgpu::TextureDescriptor {
|
||||
let hdr = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: wgpu::Extent3d {
|
||||
width: 2 * size.width,
|
||||
|
|
@ -119,17 +120,17 @@ fn main() {
|
|||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format,
|
||||
format: hdr_format,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
});
|
||||
let buf = buf.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let hdr = hdr.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
{
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: None,
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &buf,
|
||||
view: &hdr,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
|
||||
|
|
@ -157,7 +158,7 @@ fn main() {
|
|||
occlusion_query_set: None,
|
||||
timestamp_writes: None,
|
||||
});
|
||||
presenter.render(&device, &mut render_pass, &buf);
|
||||
presenter.render(&device, &mut render_pass, &hdr);
|
||||
}
|
||||
queue.submit(std::iter::once(encoder.finish()));
|
||||
output.present();
|
||||
|
|
|
|||
|
|
@ -17,5 +17,9 @@ fn on_vertex(in: Vertex) -> Varying {
|
|||
|
||||
@fragment
|
||||
fn on_fragment(in: Varying) -> @location(0) vec4f {
|
||||
return textureSample(tex, smp, in.tex);
|
||||
let hdr = textureSample(tex, smp, in.tex).xyz;
|
||||
let luminosity = dot(hdr, vec3(0.2126, 0.7152, 0.0722));
|
||||
let color = hdr / luminosity;
|
||||
let luma = luminosity / (luminosity + 1.0);
|
||||
return vec4(luma * color, 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ fn trace_fragment(in: Varying) -> vec4f {
|
|||
}
|
||||
}
|
||||
|
||||
return clamp(result, vec4(0.0), vec4(1.0));
|
||||
return result;
|
||||
}
|
||||
|
||||
fn hash(key : u32) -> u32 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user