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

Robert Osfield robert.osfield at gmail.com
Tue Sep 2 01:03:01 PDT 2008


Hi Fabian,

You need to set the size of the uniform, preferably using the constructor:

        Uniform( Type type, const std::string& name, int numElements=1 );

Or use setNumElements(num);

Note, Uniform doesn't allow you to change the size of the array after
its been set for the first time.

Robert.

On Tue, Sep 2, 2008 at 6:26 AM, Fabian Bützow <buetz at uni-koblenz.de> wrote:
> 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
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list