Shaders Glow shader

jf_knight

Member
I'm trying to implement a glow shader. I want to get the bloom effect without the accompanying "brightness" effect. What can I change to decrease this brightness intensity?
It's based on this shader:
https://marketplace.yoyogames.com/assets/4729/simple-bloom-shader
https://www.shadertoy.com/view/lsXGWn

Here is what I've edited so far. I get a black screen when room starts (as "glow" is initialized to 0 and (glow * colors.a) = 0 ).

```
vec4 glow(vec4 colors, float glow)
{
vec4 sum = vec4(0);
int j;
int i;
float blurSize = 0.00390625;

sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 4.0*blurSize, v_texcoord.y)) * 0.05;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 3.0*blurSize, v_texcoord.y)) * 0.09;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 2.0*blurSize, v_texcoord.y)) * 0.12;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - blurSize, v_texcoord.y)) * 0.15;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y)) * 0.16;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + blurSize, v_texcoord.y)) * 0.15;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 2.0*blurSize, v_texcoord.y)) * 0.12;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 3.0*blurSize, v_texcoord.y)) * 0.09;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 4.0*blurSize, v_texcoord.y)) * 0.05;

sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - 4.0*blurSize)) * 0.05;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - 3.0*blurSize)) * 0.09;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - 2.0*blurSize)) * 0.12;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - blurSize)) * 0.15;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y)) * 0.16;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + blurSize)) * 0.15;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 2.0*blurSize)) * 0.12;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 3.0*blurSize)) * 0.09;
sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 4.0*blurSize)) * 0.05;

colors += (sum );
colors.rgb *= ( (glow * colors.a)/1.96 );
colors.rgb /= ((colors.a / glow) *1.96);

return colors;
}
```


The variable "glow" goes from 0 to 1; The goal is to go from the original image to an image with a subtle glow effect,
 

Tyg

Member
ok..this shader passes the intensity in the drawgui event of the object(not sure why its using drawgui..but anyways)
the intensity can be limited by using the clamp statement like so...

Bint = clamp(((window_mouse_get_y()-250)/100),-.1,2);
shader_set_uniform_f(bloomIntensity, Bint);

i found that the range of -.1 to 2 was good
your code has no uniforms so if you want a constant value it would be coded in
you dont return values from a shader like a function...i see return colors;
you use gl_FragColor
your ...vec4 glow(vec4 colors, float glow) is in the format glow([1,1,1,1],1] which is not a vec4 as it is assigned
it could be vec4 glow(vec3 colors.rgb, float intensity) which would make a vec4 intensity is in the alpha channel
glow cannot be used twice as a vec4 and a float
a vec4 color format is glow[r,g,b,a] red green blue alpha
so...colors.rgb *= ( (glow * colors.a)/1.96 ); is actually doing this vec3 colors multiplied by an incorrect glow format multiplied by colors alpha channel then diiveded by 1.96...


to remove the intensity you could simply do this

gl_FragColor = sum * intensity + texture2D(gm_BaseTexture, v_vTexcoord);
gl_FragColor = sum + texture2D(gm_BaseTexture, v_vTexcoord);

Hope that helps :)

also you can remove the code that brings the intensity from the y mouse position and use whatever your using for varying
 
Last edited:

jf_knight

Member
ok..this shader passes the intensity in the drawgui event of the object(not sure why its using drawgui..but anyways)
the intensity can be limited by using the clamp statement like so...

Bint = clamp(((window_mouse_get_y()-250)/100),-.1,2);
shader_set_uniform_f(bloomIntensity, Bint);

i found that the range of -.1 to 2 was good
your code has no uniforms so if you want a constant value it would be coded in
you dont return values from a shader like a function...i see return colors;
you use gl_FragColor
your ...vec4 glow(vec4 colors, float glow) is in the format glow([1,1,1,1],1] which is not a vec4 as it is assigned
it could be vec4 glow(vec3 colors.rgb, float intensity) which would make a vec4 intensity is in the alpha channel
glow cannot be used twice as a vec4 and a float
a vec4 color format is glow[r,g,b,a] red green blue alpha
so...colors.rgb *= ( (glow * colors.a)/1.96 ); is actually doing this vec3 colors multiplied by an incorrect glow format multiplied by colors alpha channel then diiveded by 1.96...


to remove the intensity you could simply do this

gl_FragColor = sum * intensity + texture2D(gm_BaseTexture, v_vTexcoord);
gl_FragColor = sum + texture2D(gm_BaseTexture, v_vTexcoord);

Hope that helps :)

also you can remove the code that brings the intensity from the y mouse position and use whatever your using for varying
Thank you for your thorough explanation! It put me on the right direction. :D
 
Top