Hi,

Are you getting any InfoLog messages from the GLSL compile or link?

BTW a working example of GLSL generic attributes is the diffraction shader in 
http://osgtoy.svn.sourceforge.net/viewvc/osgtoy/osgtoy/trunk/osgtoy-data/compactdisc.osg
  It binds a "tangent" attribute to slot 5.

Cheers
-- mew




Mike Weiblen -- Zebra Imaging -- Austin Texas USA -- 
http://www.zebraimaging.com/

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:osg-users-
> [EMAIL PROTECTED] On Behalf Of Jean-Sébastien Guay
> Sent: Tuesday, May 08, 2007 9:35 AM
> To: OSG-users
> Subject: [osg-users] Using vertex attributes and GLSL
> 
> Hello,
> 
> I guess this is more a usage question, I've never tried what I'm doing
> now and don't really know if I'm doing it the right way.
> 
> I want to use vertex attributes in a GLSL vertex shader. Now, here is
> roughly the sequence of events I'm doing. I would appreciate if
> someone could tell me if it's wrong or missing something. (note: I
> checked osgFX/BumpMapping since it uses vertex attributes, but
> couldn't find anything I'm doing radically different - plus it doesn't
> use GLSL so that's one part I can't check)
> 
> 
> 1. I load my vertex and fragment shaders and assign them to an
> osg::Program, and also give a name to the vertex attribute slot I want
> to use:
> 
>      // createShaders just loads shaders named name.vert and name.frag
>      osg::ref_ptr<osg::Program> program = createShaders("shader_name");
>      program->addBindAttribLocation("color_value", 6);
>      loadedModel->getOrCreateStateSet()->setAttribute(program.get());
> 
> 2. Then I generate my vertex attribute array. For now I'm just testing
> by creating a Vec4Array and setting all Vec4f's to red.
> 
>      for (... each geode in my model ...)
>      {
>          for (... each geometry in my model ...)
>          {
>              const osg::Array* vertices = object->getVertexArray();
> 
>              osg::ref_ptr<osg::Vec4Array> colors =
>                  new osg::Vec4Array(normals->getDataSize());
>              osg::Vec4f* colorData = (osg::Vec4f*)colors-
> >getDataPointer();
> 
>              for (unsigned int n = 0;
>                   n < (unsigned int)vertices->getDataSize(); ++n)
>              {
>                  colorData[n] = osg::Vec4f(0.0f, 1.0f, 0.0f, 1.0f);
>              }
> 
>              // Set the computed colors as vertex attributes (attribute
> slot 6)
>              object->setVertexAttribData(6,
>                  osg::Geometry::ArrayData(colors.get(),
>                      osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
>          }
>      }
> 
> 3. My vertex shader "shader_name.vert" looks roughly like this:
> 
>      attribute vec4 color_value;
>      varying vec3 DiffuseColor;
> 
>      void main()
>      {
>          DiffuseColor = color_value.rgb;
>          gl_Position = ftransform();
>      }
> 
> And my fragment shader "shader_name.frag", unsurprisingly:
> 
>      varying vec3 DiffuseColor;
> 
>      void main()
>      {
>          gl_FragColor = vec4(DiffuseColor, 1.0);
>      }
> 
> 
> So my objects should be constant green, but they are constant black...
> :-( If I change either the fragment shader or vertex shader to
> hard-code a color, that works fine, but it just seems that my vertex
> attributes aren't getting through (or they are but they're all zero,
> which they shouldn't be considering the code above I think).
> 
> I'm sure I'm missing something, but what? Thanks in advance,
> 
> J-S
> --
> ______________________________________________________
> Jean-Sebastien Guay     [EMAIL PROTECTED]
>                          http://whitestar02.webhop.org/
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to