Hi,

I am trying to attach additional per-vertex information to each vertex. For 
each vertex, there are 3 sets of RGBA values I want to attach (each called 
controlSetA, controlSetB, controlSetC) to. The controlSet values are from an 
additional file in JSON format, and it is not embedded in the original 3D 
model. So, my plan here is that I will load those controlSet values and keep 
each controlSet in a Texture Buffer Object, and I will sample them in GLSL 
vertex shader.

However I encounter an problem :

Just say my 3D model is a sphere consists of 382 vertices. So the JSON file has 
1528 values ( 382 x 4 channels = 1528) for each Control Set. In total : 1528 x 
3 sets = 4584 values).  So, in "tboImage->allocateImage", I request a texture 
with dimension 382 x 1 x 1 with RGBA float texels. During the runtime in this 
initialization function, I see from Visual Studio watch that it has correct 382 
x 1 x 1 dimension. However, when I check it using codeXL, the texture's 
dimension is only 47 x 1 x 1 (if I am not wrong). Moreover, if I try to 
visualize the value in rendering, I can see that the sphere is painted with the 
value until about one quarter of the surface (from bottom) only.

I am using OpenSceneGraph version 3.5.6, 64-bit, Visual Studio 2013

The following is the relevant code


Code:


std::vector<std::string> controlSetNames = { "controlSetA", "controlSetB", 
"controlSetC" };
std::vector<int> controlSetIDs = { 3, 4, 6 };

...

itrcontrolSet = 0
//for each control set
{
        int vertexCount = 0;
        std::vector<float> values;

        //just pseudocode here
        //for each vertex
        //{
        //      vertexCount++;
        //      for each channel
        //      {
        //              values.push_back(channel->GetFloat());
        //      }
        //}

        //create the texture image
        osg::ref_ptr<osg::Image> tboImage = new osg::Image;
        tboImage->allocateImage(vertexCount, 1, 1, GL_RGBA, GL_FLOAT);
        float *dataF = (float*)tboImage->data();

        //copy the json data to it
        //memcpy(dataF, texels, sizeof(GL_FLOAT) * values.size());
        for (int i = 0; i < values.size(); i++)
                *(dataF++) = values[i];

        //create texture buffer object
        osg::ref_ptr<osg::TextureBuffer> tbo = new osg::TextureBuffer;
        tbo->setImage(tboImage.get());
        tbo->setInternalFormat(GL_RGBA32F_ARB);
        tbo->setTextureWidth(vertexCount);
        tbo->dirtyTextureParameters();

        //attach to the TBO
        osg::ref_ptr<osg::StateSet> stateset = foundNode->getOrCreateStateSet();
        osg::Uniform* texControlSet = new 
osg::Uniform(controlSetNames[itrcontrolSet].c_str(), 
controlSetIDs[itrcontrolSet]);
        stateset->addUniform(texControlSet); 
        stateset->setTextureAttributeAndModes(controlSetIDs[itrcontrolSet], 
tbo.get());

        itrcontrolSet++;
}




And here's the shader code

Code:

#version 330 compatibility
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_explicit_uniform_location : enable

layout( location = 3) uniform samplerBuffer controlSetA;
layout( location = 4) uniform samplerBuffer controlSetB;
layout( location = 6) uniform samplerBuffer controlSetC;

...

layout( location = 0 ) out vec4 out_vColor0;
layout( location = 1 ) out vec4 out_vColor1;
layout( location = 2 ) out vec4 out_vColor2;
layout( location = 3 ) out vec4 out_vColor3;

..

void main()
{

...
        vec4 in_vColor0         = gl_Color; 

        out_vColor0 = saturate(in_vColor0);
        out_vColor1 = texelFetch(controlSetA, gl_VertexID);
        out_vColor2 = texelFetch(controlSetB, gl_VertexID);
        out_vColor3 = texelFetch(controlSetC, gl_VertexID);

...

}





Thank you!

Cheers,
Eon
[/code]

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





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

Reply via email to