Demo/DeferredShading: Add tone-mapping (without automatic exposure for now)

This commit is contained in:
Jérôme Leclercq
2021-12-05 17:03:08 +01:00
parent 0aec863300
commit f64e16f7d8
3 changed files with 151 additions and 28 deletions

View File

@@ -54,7 +54,7 @@ fn main(input: FragIn) -> FragOut
color /= vec3<f32>(1.0, 1.0, 1.0) + color;
let output: FragOut;
output.color = vec4<f32>(color, 1.0);
output.color = vec4<f32>(max(color, vec3<f32>(0.0, 0.0, 0.0)), 1.0);
return output;
}

View File

@@ -0,0 +1,66 @@
[layout(std140)]
struct ViewerData
{
projectionMatrix: mat4<f32>,
invProjectionMatrix: mat4<f32>,
viewMatrix: mat4<f32>,
invViewMatrix: mat4<f32>,
viewProjMatrix: mat4<f32>,
invViewProjMatrix: mat4<f32>,
renderTargetSize: vec2<f32>,
invRenderTargetSize: vec2<f32>,
eyePosition: vec3<f32>
}
external
{
[set(0), binding(0)] viewerData: uniform<ViewerData>,
[set(0), binding(1)] inputTexture: sampler2D<f32>
}
struct FragIn
{
[builtin(fragcoord)] fragcoord: vec4<f32>
}
struct FragOut
{
[location(0)] color: vec4<f32>
}
struct VertIn
{
[location(0)] pos: vec3<f32>
}
struct VertOut
{
[builtin(position)] position: vec4<f32>
}
[entry(frag)]
fn main(input: FragIn) -> FragOut
{
let exposure = 0.8;
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
let hdrColor = inputTexture.Sample(fragcoord).rgb;
// reinhard tone mapping
let mapped = vec3<f32>(1.0, 1.0, 1.0) - exp(-hdrColor * exposure);
let output: FragOut;
output.color = vec4<f32>(mapped, 1.0);
return output;
}
[entry(vert)]
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
return output;
}