MultiRenderTarget Texture rendering with jit.gl.slab
Hi
I am looking for an elegant way to process a list of textures - like the result from a MRT render pass - through one [jit.gl.slab] object.
currently I am using this akward contraption in order to keep the shader short and uncluttered:
<jittershader name="blur">
<description>
baking border extender
</description>
<param name="width" type="float" default="2">
<description>Width of filter</description>
</param>
<language name="glsl" version="1.0">
<bind param="width" program="vp" />
<program name="vp" type="vertex">
<![CDATA[
uniform float width;
varying vec2 texcoord11;
varying vec2 texcoord00;
varying vec2 texcoord02;
varying vec2 texcoord20;
varying vec2 texcoord22;
void main()
{
// perform standard transform on vertex
gl_Position = ftransform();
// transform texcoord
vec2 texcoord = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
// get texcoords
texcoord11 = texcoord;
texcoord00 = texcoord + vec2(-width, -width);
texcoord02 = texcoord + vec2( width, -width);
texcoord20 = texcoord + vec2( width, width);
texcoord22 = texcoord + vec2(-width, width);
}
]]>
</program>
<program name="fp" type="fragment">
<![CDATA[
/*
* GLSL fragment program baking border extender.
*/
uniform sampler2DRect image;
varying vec2 texcoord11;
varying vec2 texcoord00;
varying vec2 texcoord02;
varying vec2 texcoord20;
varying vec2 texcoord22;
void main()
{
vec4 blur;
vec4 seed = texture2DRect(image, texcoord11);
vec4 s1 = texture2DRect(image, texcoord00);
vec4 s2 = texture2DRect(image, texcoord02);
vec4 s3 = texture2DRect(image, texcoord20);
vec4 s4 = texture2DRect(image, texcoord22);
blur = (s1.r == 0.)?(s2.r == 0.)?(s3.r == 0.)?(s4.r == 0.)?seed:s4:s3:s2:s1;
gl_FragColor = (seed.r == 0.)?blur:seed;
}
]]>
</program>
</language>
</jittershader>But I wonder if there is more elegant solution. I know, [jit.gl.slab] can handle the input and output of multiple textures - my problem with the inlet-outlet approach is I have a varying number of textures I need to process - sometime its only one, sometime its up to 6. And the shader would get very cluttered. The provided max example can handle this.
In short: I am looking for an elegant solution that can process a varying number of textures with the same simple texture shader without the need of a cluttered patch.
cheers