Fixing bloom

This commit is contained in:
Lubos Lenco 2017-11-16 08:52:42 +01:00
parent c3bdf0efda
commit ae60a6e078
6 changed files with 36 additions and 64 deletions

View file

@ -5,7 +5,6 @@ precision mediump float;
#endif
#include "../compiled.glsl"
//const float bloomThreshold = 3.0;
uniform sampler2D tex;
uniform vec2 texStep;
@ -14,17 +13,9 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
// vec4 col = texture(tex, texCoord);
vec4 col = vec4(0.0);
col += texture(tex, vec2(texCoord.x - texStep.x * 1.5, texCoord.y));
col += texture(tex, vec2(texCoord.x + texStep.x * 1.5, texCoord.y));
col += texture(tex, vec2(texCoord.x, texCoord.y - texStep.y * 1.5));
col += texture(tex, vec2(texCoord.x, texCoord.y + texStep.y * 1.5));
col /= 4.0;
// float brightness = dot(col.rgb, vec3(0.2126, 0.7152, 0.0722));
// if (brightness > bloomThreshold) {
if (col.r + col.g + col.b > bloomThreshold) {
vec4 col = texture(tex, texCoord);
float brightness = dot(col.rgb, vec3(0.2126, 0.7152, 0.0722));
if (brightness > bloomThreshold) {
fragColor.rgb = col.rgb;
return;
}

View file

@ -6,44 +6,24 @@ precision mediump float;
#endif
#include "../compiled.glsl"
//const float bloomStrength = 0.4;
uniform sampler2D tex;
uniform vec2 dir;
// uniform vec2 screenSize;
uniform vec2 screenSize;
in vec2 texCoord;
out vec4 fragColor;
// const float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
// const float weight[8] = float[] (0.197448, 0.174697, 0.120999, 0.065602, 0.02784, 0.009246, 0.002403, 0.000489);
// const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
const float weight[20] = float[] (0.06649, 0.065575, 0.062905, 0.058694, 0.053269, 0.047023, 0.040375, 0.033719, 0.027391, 0.021642, 0.016633, 0.012433, 0.00904, 0.006393, 0.004398, 0.002943, 0.001915, 0.001212, 0.000746, 0.000447);
const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
void main() {
vec2 step = dir / 200.0 * bloomRadius; //screenSize.xy;
vec2 step = (dir / screenSize.xy / 4) * bloomRadius * 2.0;
// vec2 step = (dir / 200) * bloomRadius;
fragColor.rgb = texture(tex, texCoord).rgb * weight[0];
// fragColor.rgb += texture(tex, texCoord + step * 1.5).rgb * weight[1];
// fragColor.rgb += texture(tex, texCoord - step * 1.5).rgb * weight[1];
// fragColor.rgb += texture(tex, texCoord + step * 2.5).rgb * weight[2];
// fragColor.rgb += texture(tex, texCoord - step * 2.5).rgb * weight[2];
// fragColor.rgb += texture(tex, texCoord + step * 3.5).rgb * weight[3];
// fragColor.rgb += texture(tex, texCoord - step * 3.5).rgb * weight[3];
// fragColor.rgb += texture(tex, texCoord + step * 4.5).rgb * weight[4];
// fragColor.rgb += texture(tex, texCoord - step * 4.5).rgb * weight[4];
// fragColor.rgb += texture(tex, texCoord + step * 5.5).rgb * weight[5];
// fragColor.rgb += texture(tex, texCoord - step * 5.5).rgb * weight[5];
// fragColor.rgb += texture(tex, texCoord + step * 6.5).rgb * weight[6];
// fragColor.rgb += texture(tex, texCoord - step * 6.5).rgb * weight[6];
// fragColor.rgb += texture(tex, texCoord + step * 7.5).rgb * weight[7];
// fragColor.rgb += texture(tex, texCoord - step * 7.5).rgb * weight[7];
// fragColor.rgb += texture(tex, texCoord + step * 8.5).rgb * weight[8];
// fragColor.rgb += texture(tex, texCoord - step * 8.5).rgb * weight[8];
// fragColor.rgb += texture(tex, texCoord + step * 9.5).rgb * weight[9];
// fragColor.rgb += texture(tex, texCoord - step * 9.5).rgb * weight[9];
fragColor.rgb += texture(tex, texCoord + step * 1.5).rgb * weight[1];
fragColor.rgb += texture(tex, texCoord - step * 1.5).rgb * weight[1];
fragColor.rgb += texture(tex, texCoord + step * 2.5).rgb * weight[2];
@ -62,26 +42,6 @@ void main() {
fragColor.rgb += texture(tex, texCoord - step * 8.5).rgb * weight[8];
fragColor.rgb += texture(tex, texCoord + step * 9.5).rgb * weight[9];
fragColor.rgb += texture(tex, texCoord - step * 9.5).rgb * weight[9];
fragColor.rgb += texture(tex, texCoord + step * 10.5).rgb * weight[10];
fragColor.rgb += texture(tex, texCoord - step * 10.5).rgb * weight[10];
fragColor.rgb += texture(tex, texCoord + step * 11.5).rgb * weight[11];
fragColor.rgb += texture(tex, texCoord - step * 11.5).rgb * weight[11];
fragColor.rgb += texture(tex, texCoord + step * 12.5).rgb * weight[12];
fragColor.rgb += texture(tex, texCoord - step * 12.5).rgb * weight[12];
fragColor.rgb += texture(tex, texCoord + step * 13.5).rgb * weight[13];
fragColor.rgb += texture(tex, texCoord - step * 13.5).rgb * weight[13];
fragColor.rgb += texture(tex, texCoord + step * 14.5).rgb * weight[14];
fragColor.rgb += texture(tex, texCoord - step * 14.5).rgb * weight[14];
fragColor.rgb += texture(tex, texCoord + step * 15.5).rgb * weight[15];
fragColor.rgb += texture(tex, texCoord - step * 15.5).rgb * weight[15];
fragColor.rgb += texture(tex, texCoord + step * 16.5).rgb * weight[16];
fragColor.rgb += texture(tex, texCoord - step * 16.5).rgb * weight[16];
fragColor.rgb += texture(tex, texCoord + step * 17.5).rgb * weight[17];
fragColor.rgb += texture(tex, texCoord - step * 17.5).rgb * weight[17];
fragColor.rgb += texture(tex, texCoord + step * 18.5).rgb * weight[18];
fragColor.rgb += texture(tex, texCoord - step * 18.5).rgb * weight[18];
fragColor.rgb += texture(tex, texCoord + step * 19.5).rgb * weight[19];
fragColor.rgb += texture(tex, texCoord - step * 19.5).rgb * weight[19];
fragColor.rgb *= bloomStrength / 40;
fragColor.rgb *= bloomStrength / 10;
}

View file

@ -13,8 +13,28 @@
},
{
"name": "screenSize",
"link": "_screenSize",
"ifdef": ["_Disabled"]
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_gaus_pass.vert.glsl",
"vertex_shader_path": "../include/pass.vert.glsl",
"fragment_shader": "blur_gaus_pass.frag.glsl"
},
{
"name": "blur_gaus_pass_y",
"color_write_alpha": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [
{
"name": "dir",
"link": "_vec2y"
},
{
"name": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
@ -38,8 +58,7 @@
},
{
"name": "screenSize",
"link": "_screenSize",
"ifdef": ["_Disabled"]
"link": "_screenSize"
}
],
"texture_params": [],

View file

@ -379,6 +379,8 @@ def make_ssgi_pass(stages, node_group, node):
def make_bloom_pass(stages, node_group, node):
make_quad_pass(stages, node_group, node, target_index=2, bind_target_indices=[4], bind_target_constants=['tex'], shader_context='bloom_pass/bloom_pass/bloom_pass')
make_quad_pass(stages, node_group, node, target_index=3, bind_target_indices=[2], bind_target_constants=['tex'], shader_context='blur_gaus_pass/blur_gaus_pass/blur_gaus_pass_x')
make_quad_pass(stages, node_group, node, target_index=2, bind_target_indices=[3], bind_target_constants=['tex'], shader_context='blur_gaus_pass/blur_gaus_pass/blur_gaus_pass_y')
make_quad_pass(stages, node_group, node, target_index=3, bind_target_indices=[2], bind_target_constants=['tex'], shader_context='blur_gaus_pass/blur_gaus_pass/blur_gaus_pass_x')
make_quad_pass(stages, node_group, node, target_index=1, bind_target_indices=[3], bind_target_constants=['tex'], shader_context='blur_gaus_pass/blur_gaus_pass/blur_gaus_pass_y_blend')
def make_motion_blur_pass(stages, node_group, node):

View file

@ -288,9 +288,9 @@ def init_properties():
('5', '5', '5'),
],
name="SSGI Rays", description="Number of rays to trace for RTAO/RTGI", default='5', update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_threshold = bpy.props.FloatProperty(name="Threshold", default=5.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_strength = bpy.props.FloatProperty(name="Strength", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_radius = bpy.props.FloatProperty(name="Radius", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_threshold = bpy.props.FloatProperty(name="Threshold", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_strength = bpy.props.FloatProperty(name="Strength", default=5.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_bloom_radius = bpy.props.FloatProperty(name="Radius", default=5.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_motion_blur_intensity = bpy.props.FloatProperty(name="Intensity", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_ssr_ray_step = bpy.props.FloatProperty(name="Ray Step", default=0.04, update=assets.invalidate_shader_cache)
bpy.types.World.arm_ssr_min_ray_step = bpy.props.FloatProperty(name="Ray Step Min", default=0.05, update=assets.invalidate_shader_cache)

Binary file not shown.