About first blur shader don't work :(

Hi,

I am trying to learn about shader development because I need blur effect.
I found some tutoriais and concepts about blur, like move some pixel and with alpha make a blur effect, after my research about theme I tried this code

varying mediump vec4 position;
varying mediump vec2 var_texcoord0;

uniform lowp sampler2D DIFFUSE_TEXTURE;

void main()
{

    float blur = 1.2;
    float vstep = 1.0;
    float hstep = 0.0;
    
    vec4 texturesSums = vec4(0.0);
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -4.0*blur*vstep, var_texcoord0.y -4.0*blur*hstep)) * 0.0162162162;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -3.0*blur*vstep, var_texcoord0.y -3.0*blur*hstep)) * 0.0540540541;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -2.0*blur*vstep, var_texcoord0.y -2.0*blur*hstep)) * 0.1216216216;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -1.0*blur*vstep, var_texcoord0.y -1.0*blur*hstep)) * 0.1945945946;
   
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x, var_texcoord0.y)) * 0.1;
   
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -4.0*blur*hstep, var_texcoord0.y -4.0*blur*vstep)) * 0.1945945946;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -3.0*blur*hstep, var_texcoord0.y -3.0*blur*vstep)) * 0.1216216216;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -2.0*blur*hstep, var_texcoord0.y -2.0*blur*vstep)) * 0.0540540541;
    texturesSums += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x -1.0*blur*hstep, var_texcoord0.y -1.0*blur*vstep)) * 0.0162162162;
   
   
    gl_FragColor = 3.0* vec4(texturesSums.rgb, 1.0);
}

When I run this shader it’s only run a image with alpha without blur :frowning:

Sorry my dumb quest but It is my first contact with shaders…

Thanks advanced.
Victor C Tavernari

I think found the answer for this question :stuck_out_tongue:

In the tutorial said about resolution and when I tried put my own value in blur var, I putted a wrong value, read again I understand about BlurRadian/Resolution and my var blur now is value/640 and it work perfectly…

It is my first shader and I need understand more about this logic…

If someone have some tips to give me :smiley:

I just want register my solution

3 Likes

I am no expert on shaders, but your solution seems to be a very common one. Is it some part of the shader program that you do not understand?

This shader now work fine, but I am trying understand how can I make it dynamic.

It worked with fixed value but I need change this in runtime.

Do you How Can I change values in material?

I did it

Thanks @britzl

1 Like

If you take a look at the default sprite material in builtins you can see that the tint is exposed as a fragment constant of type CONSTANT_TYPE_USER. This means that the tint can be accessed using these functions:

go.set("#sprite", "tint", vmath.vector4(1)
local tint = go.get("#sprite", "tint")
go.animat("#sprite", "tint", ...)

You should be able to use the same functions to modify blur and direction in your material.

4 Likes

It work perfectly… :smiley: thanks @britzl

2 Likes