Examples/DeferredShading: Improve bloom quality

This commit is contained in:
Jérôme Leclercq
2021-12-12 23:04:05 +01:00
parent f64e16f7d8
commit 31c71e542e
6 changed files with 250 additions and 114 deletions

View File

@@ -20,7 +20,8 @@ external
struct FragIn
{
[builtin(fragcoord)] fragcoord: vec4<f32>
[builtin(fragcoord)] fragcoord: vec4<f32>,
[location(0)] uv: vec2<f32>
}
struct FragOut
@@ -30,31 +31,38 @@ struct FragOut
struct VertIn
{
[location(0)] pos: vec3<f32>
[location(0)] pos: vec2<f32>,
[location(1)] uv: vec2<f32>
}
struct VertOut
{
[builtin(position)] position: vec4<f32>
[builtin(position)] position: vec4<f32>,
[location(0)] uv: vec2<f32>
}
[entry(frag)]
fn main(input: FragIn) -> FragOut
{
let BrightLuminance = 0.8;
/*let BrightLuminance = 0.8;
let BrightMiddleGrey = 0.5;
let BrightThreshold = 0.7;
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize * 10.0;
let color = colorTexture.Sample(fragcoord).rgb;
let color = colorTexture.Sample(input.uv).rgb;
color *= BrightMiddleGrey / BrightLuminance;
color *= vec3<f32>(1.0, 1.0, 1.0) + (color / (BrightThreshold*BrightThreshold));
color -= vec3<f32>(0.5, 0.5, 0.5);
color /= vec3<f32>(1.0, 1.0, 1.0) + color;
color /= vec3<f32>(1.0, 1.0, 1.0) + color;*/
let output: FragOut;
output.color = vec4<f32>(max(color, vec3<f32>(0.0, 0.0, 0.0)), 1.0);
//output.color = vec4<f32>(max(color, vec3<f32>(0.0, 0.0, 0.0)), 1.0);
let color = colorTexture.Sample(input.uv).rgb;
let brightness = dot(color, vec3<f32>(0.2126, 0.7152, 0.0722));
if (brightness > 1.0)
output.color = vec4<f32>(color, 1.0);
else
output.color = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return output;
}
@@ -63,7 +71,8 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
output.position = vec4<f32>(input.pos, 0.0, 1.0);
output.uv = input.uv;
return output;
}

View File

@@ -15,7 +15,7 @@ struct ViewerData
external
{
[set(0), binding(0)] viewerData: uniform<ViewerData>,
[set(0), binding(1)] colorTexture: sampler2D<f32>,
//[set(0), binding(1)] colorTexture: sampler2D<f32>,
[set(0), binding(2)] bloomTexture: sampler2D<f32>,
}
@@ -31,7 +31,7 @@ struct FragOut
struct VertIn
{
[location(0)] pos: vec3<f32>
[location(0)] pos: vec2<f32>
}
struct VertOut
@@ -45,7 +45,7 @@ fn main(input: FragIn) -> FragOut
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
let output: FragOut;
output.color = colorTexture.Sample(fragcoord) + bloomTexture.Sample(fragcoord);
output.color = /*colorTexture.Sample(fragcoord) + */bloomTexture.Sample(fragcoord);
return output;
}
@@ -54,7 +54,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
output.position = vec4<f32>(input.pos, 0.0, 1.0);
return output;
}

View File

@@ -15,7 +15,7 @@ struct FragOut
struct VertIn
{
[location(0)] pos: vec3<f32>,
[location(0)] pos: vec2<f32>,
[location(1)] uv: vec2<f32>
}
@@ -40,7 +40,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
output.position = vec4<f32>(input.pos, 0.0, 1.0);
output.vertUV = input.uv;
return output;
}

View File

@@ -12,10 +12,18 @@ struct ViewerData
eyePosition: vec3<f32>
}
[layout(std140)]
struct BlurData
{
direction: vec2<f32>,
sizeFactor: f32
}
external
{
[set(0), binding(0)] viewerData: uniform<ViewerData>,
[set(0), binding(1)] colorTexture: sampler2D<f32>,
[set(0), binding(2)] blurData: uniform<BlurData>
}
struct FragIn
@@ -30,7 +38,7 @@ struct FragOut
struct VertIn
{
[location(0)] pos: vec3<f32>
[location(0)] pos: vec2<f32>
}
struct VertOut
@@ -41,26 +49,16 @@ struct VertOut
[entry(frag)]
fn main(input: FragIn) -> FragOut
{
let invTargetSize = viewerData.invRenderTargetSize * 10.0;
let invTargetSize = viewerData.invRenderTargetSize * blurData.sizeFactor;
let fragcoord = input.fragcoord.xy * invTargetSize;
let color = colorTexture.Sample(fragcoord).rgb * 0.2270270270;
let filter = vec2<f32>(1.0, 0.0);
color += colorTexture.Sample(fragcoord + filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord - filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord + blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord - blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord + filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color += colorTexture.Sample(fragcoord - filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
filter = vec2<f32>(0.0, 1.0);
color += colorTexture.Sample(fragcoord + filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord - filter * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
color += colorTexture.Sample(fragcoord + filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color += colorTexture.Sample(fragcoord - filter * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color += colorTexture.Sample(fragcoord + blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
color += colorTexture.Sample(fragcoord - blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
let output: FragOut;
output.color = vec4<f32>(color, 1.0);
@@ -72,7 +70,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
output.position = vec4<f32>(input.pos, 0.0, 1.0);
return output;
}

View File

@@ -30,7 +30,7 @@ struct FragOut
struct VertIn
{
[location(0)] pos: vec3<f32>
[location(0)] pos: vec2<f32>
}
struct VertOut
@@ -60,7 +60,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4<f32>(input.pos, 1.0);
output.position = vec4<f32>(input.pos, 0.0, 1.0);
return output;
}