Re: [osg-users] transfer data to shader with osg::texture

2016-10-06 Thread Wojciech Lewandowski
Welcome :-)
Wojtek

2016-10-06 3:46 GMT+02:00 liu ming <81792...@qq.com>:

> hi Wojtek,Thank you very much,you perfect solved my problem.According to
> your code,Texture2D worked,maybe it is something wrong about Texture1D.
> Thank you.
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68887#68887
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread liu ming
hi Wojtek,Thank you very much,you perfect solved my problem.According to your 
code,Texture2D worked,maybe it is something wrong about Texture1D.  Thank you.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68887#68887





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread Wojciech Lewandowski
Hi guys,

Here is the repro code. In cmake project.

Change use_data1D value in test.cpp to see the problem.

One note: I tested it with GL 3 Osg build. There may be issues I omitted if
you run it with GL1/GL2/GL3 compatibility OSG build.

Cheers,
Wojtek

2016-10-05 14:38 GMT+02:00 Wojciech Lewandowski :

> Hi Liu,
>
> You got me interested and I created a repro of your problem. I will send
> it in followup mail (to be sure this message passes in case zip attachments
> were prohibited and message got blocked).
>
> I think you see a genuine issue.
>
> I have found that texture1D seems to be a problem. When I used texture2D
> instead it works. One extra note, though. With GL_RGBA16 no one works
> correctly. So internal format needs to be a float format (GL_RGBA16F_ARB,
> GL_RGBA32F_ARB, GL_RGB16F_ARB, GL_RGB32F_ARB).
>
> Cheers,
> Wojtek
>
> 2016-10-05 14:20 GMT+02:00 liu ming <81792...@qq.com>:
>
>> yes,I am getting 0 and 1 in geometry shader,but my input values are :
>>
>>
>> Code:
>>  *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);
>>
>>
>>
>> --
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=68869#68869
>>
>>
>>
>>
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>


osg_liu_ming_prob_src_cmake.7z
Description: Binary data
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread Wojciech Lewandowski
Hi Liu,

You got me interested and I created a repro of your problem. I will send it
in followup mail (to be sure this message passes in case zip attachments
were prohibited and message got blocked).

I think you see a genuine issue.

I have found that texture1D seems to be a problem. When I used texture2D
instead it works. One extra note, though. With GL_RGBA16 no one works
correctly. So internal format needs to be a float format (GL_RGBA16F_ARB,
GL_RGBA32F_ARB, GL_RGB16F_ARB, GL_RGB32F_ARB).

Cheers,
Wojtek

2016-10-05 14:20 GMT+02:00 liu ming <81792...@qq.com>:

> yes,I am getting 0 and 1 in geometry shader,but my input values are :
>
>
> Code:
>  *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);
>
>
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68869#68869
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread liu ming
yes,I am getting 0 and 1 in geometry shader,but my input values are :

  
Code:
 *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); 



--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68869#68869





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread Sebastian Messerschmidt

Hi Liu,

Are you getting values between 0 and 1?
Cheers
Sebastian

thank you for your reply ,I have tried your solution ,But it still is 
invaild,the Geometry shader can not get original input values.Are there  other 
wrong in code?Thank you for your help.

SMesserschmidt wrote:

Am 10/5/2016 um 3:37 AM schrieb liu ming:


Hi Wojtek ,Thank you for your reply,I have  tried GL_RGBA16F_ARB instead like that 
"texture0->setInternalFormat(GL_RGBA16F_ARB);",but  it seemed like not 
valid.The value still is 0..1 range.Are there other solutions? Thank you.


So they are now _between_ 0 and , instead of 0 _or_ 1? Then, at least,
you're on the right track.
What  seems wrong however is your sampler setup. Try this instead:

osg::Uniform* sampler = new osg::Uniform(osg::Uniform::SAMPLER_1D, "data");
sampler->set(0); //assign unit

ss->addUniform(sampler);

ss->setTextureAttribute(0/*unit*/, texture0 ,osg::StateAttribute::ON );

Cheers
Sebastian





--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68852#68852





___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

  --
Post generated by Mail2Forum


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68858#68858





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread liu ming
thank you for your reply ,I have tried your solution ,But it still is 
invaild,the Geometry shader can not get original input values.Are there  other 
wrong in code?Thank you for your help.

SMesserschmidt wrote:
> Am 10/5/2016 um 3:37 AM schrieb liu ming:
> 
> > Hi Wojtek ,Thank you for your reply,I have  tried GL_RGBA16F_ARB instead 
> > like that "texture0->setInternalFormat(GL_RGBA16F_ARB);",but  it seemed 
> > like not valid.The value still is 0..1 range.Are there other solutions? 
> > Thank you.
> > 
> So they are now _between_ 0 and , instead of 0 _or_ 1? Then, at least, 
> you're on the right track.
> What  seems wrong however is your sampler setup. Try this instead:
> 
> osg::Uniform* sampler = new osg::Uniform(osg::Uniform::SAMPLER_1D, "data");
> sampler->set(0); //assign unit
> 
> ss->addUniform(sampler);
> 
> ss->setTextureAttribute(0/*unit*/, texture0 ,osg::StateAttribute::ON );
> 
> Cheers
> Sebastian
> 
> 
> 
> 
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=68852#68852
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> 
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68858#68858





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-05 Thread Sebastian Messerschmidt



Am 10/5/2016 um 3:37 AM schrieb liu ming:

Hi Wojtek ,Thank you for your reply,I have  tried GL_RGBA16F_ARB instead like that 
"texture0->setInternalFormat(GL_RGBA16F_ARB);",but  it seemed like not 
valid.The value still is 0..1 range.Are there other solutions? Thank you.
So they are now _between_ 0 and , instead of 0 _or_ 1? Then, at least, 
you're on the right track.

What  seems wrong however is your sampler setup. Try this instead:

osg::Uniform* sampler = new osg::Uniform(osg::Uniform::SAMPLER_1D, "data");
sampler->set(0); //assign unit

ss->addUniform(sampler);

ss->setTextureAttribute(0/*unit*/, texture0 ,osg::StateAttribute::ON );

Cheers
Sebastian





--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68852#68852





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-04 Thread liu ming
Hi Wojtek ,Thank you for your reply,I have  tried GL_RGBA16F_ARB instead like 
that "texture0->setInternalFormat(GL_RGBA16F_ARB);",but  it seemed like not 
valid.The value still is 0..1 range.Are there other solutions? Thank you.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68852#68852





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] transfer data to shader with osg::texture

2016-10-04 Thread Wojciech Lewandowski
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 <81792...@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 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@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] transfer data to shader with osg::texture

2016-10-04 Thread liu ming
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 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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org