ac
Full Member
Offline
Posts: 237
Re: OpenGL Offscreen buffer for glow effect
Reply #5 - Apr 9th , 2008, 4:30am
Hi, Here is a sample of an xml file: <filter name="pulsating emboss"> <description>Emboss with pulsating grid</description> <vertex>PulseGrid.glsl</vertex> <fragment>DynEmboss.glsl</fragment> <grid> <resolution nx="10" ny="10"></resolution> </grid> </filter> The three important tags are <vertex>, <fragment> and <grid> In <vertex> and <fragment> you just specify the filename of the vertex and fragment glsl shaders. If no vertex shader is needed, just don't add a <vertex> tag. The <grid> tag is used to define a rectangular grid the input texture is applied onto. The advantage of having a grid instead of just a rectangle is that you can modify the vertices of the grid inside the vertex shader, allowing for interesting distortions of the texture. However, if there is no need for such type of distortions, you can just skip the <grid> tag. With <resolution nx="10" ny="10"></resolution> you just specify the number of points on the grid, along the x and y directions. In this case, the grid has 10x10 points. So, if you don't need to change the vertex stage nor a grid, the xml file would reduce to something like this: <filter name="gaussian blur"> <description>3x3 Gaussian blur filter</description> <fragment>Blur.glsl</fragment> </filter> Now, the glsl shaders themselves have to follow certain conventions in order to be used inside a filter. These conventions are basically the way you are supposed to name the uniform parameters inside the shaders, for the filter to be able of recognizing those uniforms and link them to the parameters that can be passed from processing. The naming conventions are the following: 1) the name of the source/input texture units should be "src_tex_unit" + n, where n = 0, 1, 2, etc. I.e., the first texture unit should be named src_tex_unit0, the second src_tex_unit1, and so on. 2) The offset of the source textures is identified by "src_tex_offset" + n, with n = 0, 1, 2, etc. The offset is, in other words, the inverse of the width and height of the texture, and represents the step size to move from one texel to the next. At least one src_tex_unit0 uniform should be defined in the fragment shader, since a filter needs at least one source texture to operate on. Then you can define the following optional uniforms to pass general parameters into the shader: 3) timing_data (of type vec2): the first component of this vector is the frameCount and the second is millis() at the time the shader program is executed. This allows to pass timing information into the shader. 4) par_flt1, par_flt2 and par_flt3 (of type float): these float uniforms can be used to pass float numbers into the shader. 5) par_mat2 (of type mat2), to pass a 2x2 matrix into the shader. 6) par_mat3 (of type mat3), to pass a 3x3 matrix into the shader. 7) par_mat4 (of type mat4), to pass a 4x4 matrix into the shader. These uniforms don't need to be defined inside the shader, and also the shader can have other uniforms with different names. However, the advantage of having the uniforms listed here is that they are handled automatically inside the filter class. In order to set the value of these uniforms from processing, you use the GLTextureFilterParams object, inside which you have the parFlt1, parFlt2, parFlt3 float variables and parMat2, parMat3 and parMat4 float arrays. So, if the glsl shader that defines the filter has the float uniform par_flt1, you can set its value with the following code: GLTextureFilterParams params = new GLTextureFilterParams(); params.parFlt1 = map(mouseX, 20, 640, 1, 30); tex0.filter(pixelate, tex1, params); I hope this helps. Please let me know if you have further questions.