DeferredShading: Add bloom

This commit is contained in:
Jérôme Leclercq
2021-06-01 20:28:19 +02:00
parent 7bbe879d2f
commit 9ee3a0d6be
9 changed files with 441 additions and 20 deletions

View File

@@ -0,0 +1,69 @@
[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
{
[binding(0)] colorTexture: sampler2D<f32>,
[binding(1)] viewerData: uniform<ViewerData>
}
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 BrightLuminance = 0.6;
let BrightMiddleGrey = 0.5;
let BrightThreshold = 0.7;
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize * 10.0;
let color = colorTexture.Sample(fragcoord).rgb;
color = color * (BrightMiddleGrey/BrightLuminance);
color = color * (vec3<f32>(1.0, 1.0, 1.0) + (color / (BrightThreshold*BrightThreshold)));
color = color - vec3<f32>(0.5, 0.5, 0.5);
color = color / (vec3<f32>(1.0, 1.0, 1.0) + color);
let output: FragOut;
output.color = vec4<f32>(color, 1.0);
return output;
}
[entry(vert)]
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
return output;
}

View File

@@ -0,0 +1,60 @@
[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
{
[binding(0)] colorTexture: sampler2D<f32>,
[binding(1)] bloomTexture: sampler2D<f32>,
[binding(2)] viewerData: uniform<ViewerData>
}
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 fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
let output: FragOut;
output.color = colorTexture.Sample(fragcoord) + bloomTexture.Sample(fragcoord);
return output;
}
[entry(vert)]
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
return output;
}

View File

@@ -0,0 +1,78 @@
[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
{
[binding(0)] colorTexture: sampler2D<f32>,
[binding(1)] viewerData: uniform<ViewerData>
}
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 invTargetSize = viewerData.invRenderTargetSize * 10.0;
let fragcoord = input.fragcoord.xy * invTargetSize;
let color = colorTexture.Sample(fragcoord).rgb * 0.2270270270;
let filter = vec2<f32>(1.0, 0.0);
color = color + colorTexture.Sample(fragcoord + filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color = color + colorTexture.Sample(fragcoord - filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color = color + colorTexture.Sample(fragcoord + filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color = color + colorTexture.Sample(fragcoord - filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
filter = vec2<f32>(0.0, 1.0);
color = color + colorTexture.Sample(fragcoord + filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color = color + colorTexture.Sample(fragcoord - filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color = color + colorTexture.Sample(fragcoord + filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color = color + colorTexture.Sample(fragcoord - filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
let output: FragOut;
output.color = vec4<f32>(color, 1.0);
return output;
}
[entry(vert)]
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
return output;
}

View File

@@ -55,6 +55,7 @@ fn main(input: VertIn) -> VertOut
{
// Set translation part to zero
let rotationMat = viewerData.viewMatrix;
// rotationMat[3].xyz = vec3<f32>(0.0, 0.0, 0.0); // Requires SPIRV generator to handle swizzle for store expressions
rotationMat[3][0] = 0.0;
rotationMat[3][1] = 0.0;
rotationMat[3][2] = 0.0;