Animate variables in Custom Filter

Hi. I currently busy with making a Intro for my game project. My idea is to show a text in the beginning thats blurred and slowly becomes sharper until it’s not blurred anymore. Just like this:



I found a filter on the internet that is able to blur but I can’t change the blur amount variable in real time.


How to animate this variable?
-Thanks in advance.

Make a video in internal(or cycles) and playing it using a video texture or make the blur variable use property as result(float maxblur = own[“blur”] or something like that and than make the property always add value. The bigger value it adds, the faster it fades in…

make the blur variable use property as result(float maxblur = own[“blur”]

If I replace float maxblur = 16.0 with float maxblur = own[“blur”] the filter doesn’t work anymore… (and yes, i have a property called blur)
Does anyone know ??

You can make the attribute into a uniform.

See this example:


<b>import</b> bge
 
cont = bge.logic.getCurrentController()
 
VertexShader = """
         uniform mat4 viewMatrixInverse; // view to world 
            // transformation (the view matrix corresponds to the 
            // world to view transformation; thus, the inverse 
            // matrix corresponds to the view to world trafo)
 
         varying vec4 position_in_world_space;
 
         void main()
         {
            vec4 position_in_view_space = 
               gl_ModelViewMatrix * gl_Vertex;
               // transformation of gl_Vertex from object coordinates 
               // to view coordinates;
            position_in_world_space = viewMatrixInverse * 
               position_in_view_space;
               // transformation of gl_Vertex from view coordinates 
               // to world coordinates;
 
            gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
         }
"""
 
FragmentShader = """
         varying vec4 position_in_world_space;
 
         void main()
         {
            float dist = distance(position_in_world_space, 
               vec4(0.0, 0.0, 0.0, 1.0));
               // computes the distance between the fragment position 
               // and the origin (the 4th coordinate should always 
               // be 1 for points). 
 
            if (dist &lt; 5.0)
            {
               gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); 
                  // color near origin
            }
            else
            {
               gl_FragColor = vec4(0.3, 0.3, 0.3, 1.0); 
                  // color far from origin
            }
         }
"""
 
mesh = cont.owner.meshes[0]
<b>for</b> mat <b>in</b> mesh.materials:
    shader = mat.getShader()
    <b>if</b> shader != None:
        <b>if</b> <b>not</b> shader.isValid():
            shader.setSource(VertexShader, FragmentShader, 1)
        value_of_uniform = \
            bge.logic.getCurrentScene().active_camera.camera_to_world         shader.setUniformMatrix4('viewMatrixInverse', value_of_uniform) # this is sent


http://en.wikibooks.org/wiki/GLSL_Programming/Blender/Shading_in_View_Space

or

In short “uniform float maxBlur;” is what you are after,
You can set it from python.
http://www.blender.org/api/blender_python_api_2_73_5/bge.types.BL_Shader.html#bge.types.BL_Shader.setUniform1f

wow… thanks for your information but I’m just a beginner/noob with filters and python. Can you tell me exactly what i have to do?

Could you post the shader as I can’t tell if it is a material shader or filter.

The first post was about material shader.

The filter basically the same, but maybe easier to change:

Just specify a variable as ‘uniform’ in the shader’s script, and create an object property (not a script variable) of the same name in the object that runs the 2D filter (i.e. if the Camera runs the 2D filter, make sure it has an object property (in the Game Logic’s Properties panel) that has the same name as the uniform variable that you’re using in the GLSL script).

Basically what I understand:
Add the word ‘uniform’ before your variable.
Have a property of same name.

You have replace in the shader the line:
float maxblur = 16.0;
to:
float maxblur;

And put one property called: maxblur, in the object that have the 2d filter, and later use a script to change that variable.

got it:
float uniform maxblur;
Thanks.

But does anyone know how to animate the property value, I know i can with a always sensor with a frequenty but is there a better way?


hmm… nevermind this works fine for now… but if you have idea’s i would like to hear it.

Thanks for the help! :eyebrowlift:

Edit:
I added a greater than 0 property sensor so it stops change the property when it’s 0. Does this affect the peformance in a positive way?