From fd65b5a36ecb3128e491d5673cebbe9002a74956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 20 Sep 2018 15:49:56 -0700 Subject: [PATCH] Cleanup. --- examples/38-bloom/fs_albedo_output.sc | 4 +-- examples/38-bloom/fs_bloom_combine.sc | 6 ++-- examples/38-bloom/fs_downsample.sc | 42 +++++++++++++-------------- examples/38-bloom/fs_upsample.sc | 14 +++++---- examples/38-bloom/vs_albedo_output.sc | 3 +- examples/38-bloom/vs_fullscreen.sc | 4 +++ 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/examples/38-bloom/fs_albedo_output.sc b/examples/38-bloom/fs_albedo_output.sc index 85605736d..b445c1ef0 100644 --- a/examples/38-bloom/fs_albedo_output.sc +++ b/examples/38-bloom/fs_albedo_output.sc @@ -7,16 +7,14 @@ $input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 #include "../common/common.sh" - uniform vec4 u_color; void main() { - // the albedo-buffer of the g-buffer. + // the albedo-buffer of the g-buffer. gl_FragData[0] = u_color; // for convenience, we also output the same color, to the first texture of the texture chain used for bloom. // this color will now be bloomed, in the following passes. gl_FragData[1] = u_color; - } diff --git a/examples/38-bloom/fs_bloom_combine.sc b/examples/38-bloom/fs_bloom_combine.sc index 0fbe74fbe..8e70488fe 100644 --- a/examples/38-bloom/fs_bloom_combine.sc +++ b/examples/38-bloom/fs_bloom_combine.sc @@ -13,12 +13,12 @@ SAMPLER2D(s_light, 1); void main() { vec3 hdrColor = texture2D(s_albedo, v_texcoord0).rgb; - + hdrColor += texture2D(s_light, v_texcoord0).rgb; // instead of some fancy tonemapping operator, we just clamp it, to keep it simple. vec3 finalColor = clamp(hdrColor, 0.0, 1.0); - + float g = 2.2; - gl_FragColor = vec4(pow(finalColor, vec3(1.0 / g, 1.0 / g, 1.0 / g) ), 1.0); + gl_FragColor = vec4(pow(finalColor, vec3(1.0 / g, 1.0 / g, 1.0 / g) ), 1.0); } diff --git a/examples/38-bloom/fs_downsample.sc b/examples/38-bloom/fs_downsample.sc index 8a4f40ed1..f9ec13a29 100644 --- a/examples/38-bloom/fs_downsample.sc +++ b/examples/38-bloom/fs_downsample.sc @@ -14,29 +14,29 @@ uniform vec4 u_pixelSize; void main() { - vec2 halfpixel = 0.5 * vec2(u_pixelSize.x, u_pixelSize.y); - vec2 oneepixel = 1.0 * vec2(u_pixelSize.x, u_pixelSize.y); - + vec2 halfpixel = 0.5 * vec2(u_pixelSize.x, u_pixelSize.y); + vec2 oneepixel = 1.0 * vec2(u_pixelSize.x, u_pixelSize.y); + vec2 uv = v_texcoord0.xy; - + vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); - + sum += (4.0/32.0) * texture2D(s_tex, uv).rgba; - - sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, -halfpixel.y)); - sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, +halfpixel.y)); - sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, -halfpixel.y)); - sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, +halfpixel.y) ); - - sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, 0.0)); - sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, 0.0)); - sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, +oneepixel.y)); - sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, -oneepixel.y)); - - sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, +oneepixel.y)); - sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, +oneepixel.y)); - sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, -oneepixel.y)); - sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, -oneepixel.y)); - + + sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, -halfpixel.y) ); + sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, +halfpixel.y) ); + sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, -halfpixel.y) ); + sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, +halfpixel.y) ); + + sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, 0.0) ); + sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, 0.0) ); + sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, +oneepixel.y) ); + sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, -oneepixel.y) ); + + sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, +oneepixel.y) ); + sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, +oneepixel.y) ); + sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, -oneepixel.y) ); + sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, -oneepixel.y) ); + gl_FragColor.xyzw = sum; } diff --git a/examples/38-bloom/fs_upsample.sc b/examples/38-bloom/fs_upsample.sc index c6ad1f63c..20237dfac 100644 --- a/examples/38-bloom/fs_upsample.sc +++ b/examples/38-bloom/fs_upsample.sc @@ -1,9 +1,13 @@ $input v_texcoord0 +/* + * Copyright 2018 Eric Arnebäck. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + #include "../common/common.sh" SAMPLER2D(s_tex, 0); -//SAMPLER2D(s_target_tex, 1); uniform vec4 u_pixelSize; uniform vec4 u_intensity; @@ -12,20 +16,20 @@ void main() { vec2 halfpixel = 1.0 * vec2(u_pixelSize.x, u_pixelSize.y); vec2 uv = v_texcoord0.xy; - + vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); - + sum += (2.0 / 16.0) * texture2D(s_tex, uv + vec2(-halfpixel.x , 0.0)); sum += (2.0 / 16.0) * texture2D(s_tex, uv + vec2(0.0, halfpixel.y)); sum += (2.0 / 16.0) * texture2D(s_tex, uv + vec2(halfpixel.x , 0.0)); sum += (2.0 / 16.0) * texture2D(s_tex, uv + vec2(0.0, -halfpixel.y)); - + sum += (1.0 / 16.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, -halfpixel.y)); sum += (1.0 / 16.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, halfpixel.y)); sum += (1.0 / 16.0) * texture2D(s_tex, uv + vec2(halfpixel.x, -halfpixel.y)); sum += (1.0 / 16.0) * texture2D(s_tex, uv + vec2(halfpixel.x, halfpixel.y)); sum += (4.0 / 16.0) * texture2D(s_tex, uv); - + gl_FragColor.xyzw = u_intensity.x * sum; } diff --git a/examples/38-bloom/vs_albedo_output.sc b/examples/38-bloom/vs_albedo_output.sc index c9ec6ee82..d526a0261 100644 --- a/examples/38-bloom/vs_albedo_output.sc +++ b/examples/38-bloom/vs_albedo_output.sc @@ -6,13 +6,12 @@ $output v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0 * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ - #include "../common/common.sh" void main() { vec3 wpos = mul(u_model[0], vec4(a_position, 1.0) ).xyz; gl_Position = mul(u_viewProj, vec4(wpos, 1.0) ); - + v_texcoord0 = a_texcoord0; } diff --git a/examples/38-bloom/vs_fullscreen.sc b/examples/38-bloom/vs_fullscreen.sc index 177dc6f46..0e6a23be1 100644 --- a/examples/38-bloom/vs_fullscreen.sc +++ b/examples/38-bloom/vs_fullscreen.sc @@ -1,6 +1,10 @@ $input a_position, a_texcoord0 $output v_texcoord0 +/* + * Copyright 2018 Eric Arnebäck. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ #include "../common/common.sh"