[osg-users] transfer data to shader with osg::texture
Wojciech Lewandowski
w.p.lewandowski at gmail.com
Tue Oct 4 15:35:29 PDT 2016
Hi,
I think internal format GL_RGBA16 normalizes your float values to 0..1
range. Try GL_RGBA16F_ARB instead.
Cheers,
Wojtek Lewandowski
2016-10-04 17:00 GMT+02:00 liu ming <81792534 at qq.com>:
> Hi,
>
> I want to send a set of data to geometry shader with osg::texture,I've
> got a problem:in the geometry shader,I can use glsl function"texelFetch"to
> get the texel's values,and use the values to draw a triangle,But the values
> is not correct. the values always are "0" or "1",not the original input.It
> make me confused. whether the code" texture0->setInternalFormat(GL_RGBA16);"
> wrong?How can I get the correctly texel's values?
>
> The code:
>
>
> Code:
> //.....
> osg::ref_ptr< osg::StateSet > ss = new osg::StateSet;
> osg::Texture1D * texture0 = new osg::Texture1D;
> texture0->setDataVariance(osg::Object::DYNAMIC);
> osg::ref_ptr<osg::Image> image = new osg::Image;
> image->allocateImage( 4, 1, 1, GL_RGB, GL_FLOAT );
> //write data to the image
> osg::Vec3* ptr1 = (osg::Vec3*)image->data();
> *ptr1=osg::Vec3( 0.0,0.0,0.0);
> *ptr1++;
> *ptr1= osg::Vec3( 40.0,0.0,0.0);
> *ptr1++;
> *ptr1=osg::Vec3( 20.0,0.0,20.0);
>
> texture0->setImage(image);
> texture0->setInternalFormat(GL_RGBA16);
> //
> osg::ref_ptr< osg::Uniform > sample0 = new osg::Uniform( "data", 0 );
> ss->addUniform(sample0);
> ss->setTextureAttributeAndModes(0,
> texture0,osg::StateAttribute::ON);
> // ....
>
> //--------------------------
> //geometyr shader code
> //------------------------------
> //.....
> uniform sampler1D data;
> void main()
> {
> //get the texel's value,but the value is wrong
> vec4 C0=vec4(texelFetch(data,0,0).xyz,1.0);
> vec4 C1=vec4(texelFetch(data,1,0).xyz,1.0);
> vec4 C2=vec4(texelFetch(data,2,0).xyz,1.0);
>
> //use value to draw a triangle
> gl_Position=osg_ModelViewProjectionMatrix*C0;
> EmitVertex();
> gl_Position=osg_ModelViewProjectionMatrix*C1;
> EmitVertex();
> gl_Position=osg_ModelViewProjectionMatrix*C2;
> EmitVertex();
>
> EndPrimitive();
> }
>
>
>
> Thank you! My english is poor ,sorry.
>
> Cheers,
> liu
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68848#68848
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20161005/3d1b78c1/attachment-0003.htm>
More information about the osg-users
mailing list