| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- include = [
- "core/shaders/common.shader"
- "core/shaders/default.shader"
- ]
- render_states = {
- bloom_upsample = {
- inherit = "default"
- states = {
- blend_enable = true
- blend_src = "one"
- blend_dst = "one"
- }
- }
- bloom_combine = {
- inherit = "default"
- states = {
- depth_write_enable = false
- }
- }
- }
- bgfx_shaders = {
- bloom_params = {
- includes = [ "common" ]
- code = """
- uniform vec4 u_bloom_params;
- #define bloom_weight u_bloom_params.x
- #define bloom_intensity u_bloom_params.y
- #define bloom_threshold u_bloom_params.z
- """
- }
- bloom_downsample = {
- includes = [ "common" ]
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0) );
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- /*
- * Copyright 2018 Eric Arnebäck. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
- */
- SAMPLER2D(s_color_map, 0);
- uniform vec4 u_map_pixel_size; // pixel size of the target texture.
- void main()
- {
- vec2 halfpixel = 0.5 * vec2(u_map_pixel_size.x, u_map_pixel_size.y);
- vec2 oneepixel = 1.0 * vec2(u_map_pixel_size.x, u_map_pixel_size.y);
- vec2 uv = v_texcoord0.xy;
- vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
- sum += (4.0/32.0) * texture2D(s_color_map, uv).rgba;
- sum += (4.0/32.0) * texture2D(s_color_map, uv + vec2(-halfpixel.x, -halfpixel.y) );
- sum += (4.0/32.0) * texture2D(s_color_map, uv + vec2(+halfpixel.x, +halfpixel.y) );
- sum += (4.0/32.0) * texture2D(s_color_map, uv + vec2(+halfpixel.x, -halfpixel.y) );
- sum += (4.0/32.0) * texture2D(s_color_map, uv + vec2(-halfpixel.x, +halfpixel.y) );
- sum += (2.0/32.0) * texture2D(s_color_map, uv + vec2(+oneepixel.x, 0.0) );
- sum += (2.0/32.0) * texture2D(s_color_map, uv + vec2(-oneepixel.x, 0.0) );
- sum += (2.0/32.0) * texture2D(s_color_map, uv + vec2(0.0, +oneepixel.y) );
- sum += (2.0/32.0) * texture2D(s_color_map, uv + vec2(0.0, -oneepixel.y) );
- sum += (1.0/32.0) * texture2D(s_color_map, uv + vec2(+oneepixel.x, +oneepixel.y) );
- sum += (1.0/32.0) * texture2D(s_color_map, uv + vec2(-oneepixel.x, +oneepixel.y) );
- sum += (1.0/32.0) * texture2D(s_color_map, uv + vec2(+oneepixel.x, -oneepixel.y) );
- sum += (1.0/32.0) * texture2D(s_color_map, uv + vec2(-oneepixel.x, -oneepixel.y) );
- gl_FragColor.xyzw = sum;
- }
- """
- }
- bloom_upsample = {
- includes = [ "common" "bloom_params" ]
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0) );
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- /*
- * Copyright 2018 Eric Arnebäck. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
- */
- SAMPLER2D(s_color_map, 0);
- uniform vec4 u_map_pixel_size;
- void main()
- {
- vec2 halfpixel = u_map_pixel_size.xy;
- vec2 uv = v_texcoord0.xy;
- vec4 sum = vec4_splat(0.0);
- sum += (2.0 / 16.0) * texture2D(s_color_map, uv + vec2(-halfpixel.x, 0.0) );
- sum += (2.0 / 16.0) * texture2D(s_color_map, uv + vec2( 0.0, halfpixel.y) );
- sum += (2.0 / 16.0) * texture2D(s_color_map, uv + vec2( halfpixel.x, 0.0) );
- sum += (2.0 / 16.0) * texture2D(s_color_map, uv + vec2( 0.0, -halfpixel.y) );
- sum += (1.0 / 16.0) * texture2D(s_color_map, uv + vec2(-halfpixel.x, -halfpixel.y) );
- sum += (1.0 / 16.0) * texture2D(s_color_map, uv + vec2(-halfpixel.x, halfpixel.y) );
- sum += (1.0 / 16.0) * texture2D(s_color_map, uv + vec2( halfpixel.x, -halfpixel.y) );
- sum += (1.0 / 16.0) * texture2D(s_color_map, uv + vec2( halfpixel.x, halfpixel.y) );
- sum += (4.0 / 16.0) * texture2D(s_color_map, uv);
- gl_FragColor = bloom_intensity * sum;
- }
- """
- }
- bloom_combine = {
- includes = [ "common" "bloom_params" ]
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0) );
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- SAMPLER2D(s_color_map, 0);
- SAMPLER2D(s_bloom_map, 1);
- void main()
- {
- vec3 color = texture2D(s_color_map, v_texcoord0).rgb;
- vec3 bloom = texture2D(s_bloom_map, v_texcoord0).rgb;
- gl_FragColor = vec4(mix(color, bloom, bloom_weight), 1.0);
- }
- """
- }
- tonemap = {
- includes = [ "common" ]
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0) );
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- SAMPLER2D(s_color_map, 0);
- uniform vec4 u_tonemap_type;
- void main()
- {
- vec4 color = vec4(texture2D(s_color_map, v_texcoord0).rgb, 1.0);
- if (u_tonemap_type.x == 0.0)
- gl_FragColor = toGammaAccurate(color);
- else if (u_tonemap_type.x == 1.0)
- gl_FragColor = toReinhard(color);
- else if (u_tonemap_type.x == 2.0)
- gl_FragColor = toFilmic(color);
- else if (u_tonemap_type.x == 3.0)
- gl_FragColor = toAcesFilmic(color);
- else
- gl_FragColor = color;
- }
- """
- }
- }
- shaders = {
- bloom_downsample = {
- bgfx_shader = "bloom_downsample"
- render_state = "default"
- }
- bloom_upsample = {
- bgfx_shader = "bloom_upsample"
- render_state = "bloom_upsample"
- }
- bloom_combine = {
- bgfx_shader = "bloom_combine"
- render_state = "bloom_combine"
- }
- tonemap = {
- bgfx_shader = "tonemap"
- render_state = "blit"
- }
- }
- static_compile = [
- { shader = "bloom_downsample" defines = [] }
- { shader = "bloom_upsample" defines = [] }
- { shader = "bloom_combine" defines = [] }
- { shader = "tonemap" defines = [] }
- ]
|