[osg-users] uniform vec2 array with setElement for convolution

Fabian Bützow buetz at uni-koblenz.de
Mon Sep 1 22:26:54 PDT 2008


Hello,
i want to pass a uniform vec2 array as convolution mask to a image 
processing shader.
A former post says I should use setElement.. here my trial (it doesent 
work ;) ):

osg:
    Uniform* filter= new Uniform();
    filter->setName("kernel");  
    filter->setElement(0, Vec2(-1,1));
    ...
    filter->setElement(8, Vec2(1,-1));
    meanStateSet->addUniform(filter);

shader:
    uniform sampler2DRect inTex;
    uniform vec2 kernel[9];
    void main(){
        int i;    float sum= 0.0;
        for (i = 0; i < 9; ++i){
            sum+= (texture2DRect(inTex, gl_TexCoord[0].st + kernel[i])).r;
        }
        gl_FragColor = (sum/9);
    }

when i change kernel[i] to (for instance) vec2(0,0) it works...

any ideas?
what do i forget to set?

cheers,
Fabian



More information about the osg-users mailing list