Hi I’m facing a huge performance drop when I use blur shader on the layer.
If using shader only for text in standard draw event, then working fine, but when I using it on layer respectively 9 different layers a massive slowdown occur. The frame drop is from 60 to 10 FPS. Real FPS don’t drop it runs around 4000 – meaning that a shader is the issue, because real FPS counting only CPU steps.
Here is my code:
Shader vertex:
Shader fragment:
Then in my control object using shader activation on layer like this:
And the scripts which handle shader activation/deactivation
scr_BlurPause_Start
scr_Blur_End
Is there any way how to optimize it?
Is it a bad way to use shader on such many layers?
I just want to achieve, if player pause button, i want to blur all objects and backgrounds except the pause object, which work but at the cost of performance, so is there any other way how to do it better?
Thank you for your answers
If using shader only for text in standard draw event, then working fine, but when I using it on layer respectively 9 different layers a massive slowdown occur. The frame drop is from 60 to 10 FPS. Real FPS don’t drop it runs around 4000 – meaning that a shader is the issue, because real FPS counting only CPU steps.
Here is my code:
Shader vertex:
Code:
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec3 size;//width,height,radius
const int Quality = 8;
const int Directions = 16;
const float Pi = 6.28318530718;//pi * 2
void main()
{
vec2 radius = size.z/size.xy;
vec4 Color = texture2D( gm_BaseTexture, v_vTexcoord);
for( float d=0.0;d<Pi;d+=Pi/float(Directions) )
{
for( float i=1.0/float(Quality);i<=1.0;i+=1.0/float(Quality) )
{
Color += texture2D( gm_BaseTexture, v_vTexcoord+vec2(cos(d),sin(d))*radius*i);
}
}
Color /= float(Quality)*float(Directions)+1.0;
gl_FragColor = Color * v_vColour;
}
Code:
//initialise pause blur shader
layer_script_begin("Backgrounds", scr_BlurPause_Start);
layer_script_end("Backgrounds", scr_Blur_End);
layer_script_begin("Backgrounds_1", scr_BlurPause_Start);
layer_script_end("Backgrounds_1", scr_Blur_End);
layer_script_begin("Backgrounds_2", scr_BlurPause_Start);
layer_script_end("Backgrounds_2", scr_Blur_End);
layer_script_begin("Backgrounds_3", scr_BlurPause_Start);
layer_script_end("Backgrounds_3", scr_Blur_End);
layer_script_begin("Backgrounds_4", scr_BlurPause_Start);
layer_script_end("Backgrounds_4", scr_Blur_End);
layer_script_begin("Backgrounds_5", scr_BlurPause_Start);
layer_script_end("Backgrounds_5", scr_Blur_End);
layer_script_begin("Backgrounds_6", scr_BlurPause_Start);
layer_script_end("Backgrounds_6", scr_Blur_End);
layer_script_begin("Backgrounds_7", scr_BlurPause_Start);
layer_script_end("Backgrounds_7", scr_Blur_End);
layer_script_begin("Instances", scr_BlurPause_Start);
layer_script_end("Instances", scr_Blur_End);
scr_BlurPause_Start
Code:
if event_type == ev_draw
{
if instance_exists(obj_controller_pause)
{
if (obj_controller_pause.pause == true)
{
usize = shader_get_uniform(shd_gausian,"size");//uniform for width, height, radius
shader_set(shd_gausian)
shader_set_uniform_f(usize,1920,1080,1.75)//width,height,radius
}
}
else if instance_exists(o_control)
{
if (o_control.victory != -1)
{
usize = shader_get_uniform(shd_gausian,"size");//uniform for width, height, radius
shader_set(shd_gausian)
shader_set_uniform_f(usize,1920,1080,stage_finish.backround_alpha*4)//width,height,radius
}
}
}
Code:
if event_type == ev_draw
{
shader_reset()
}
Is it a bad way to use shader on such many layers?
I just want to achieve, if player pause button, i want to blur all objects and backgrounds except the pause object, which work but at the cost of performance, so is there any other way how to do it better?
Thank you for your answers