Hi,

when using shaders (SimpleSHLChunk) with automatic variables (such as OSGInvViewMatrix) within a ChunkOverrideGroup, the corresponding variable is never evaluated (the evaluate function in which the uniform should be set is not called) and remains zero. A minimal example is attached.

Any ideas on how to solve this?

Best regards

--
Johannes S. Mueller-Roemer, MSc
Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)

Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roe...@igd.fraunhofer.de  |  www.igd.fraunhofer.de

#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGSimpleSHLChunk.h>
#include <OpenSG/OSGMaterialGroup.h>
#include <OpenSG/OSGChunkOverrideGroup.h>

#define STRINGIFY(A) #A

static const char *vs = STRINGIFY(
        uniform mat4 OSGInvViewMatrix;
        varying vec3 objPos;
        
        void main()
        {
                objPos = (OSGInvViewMatrix * gl_ModelViewMatrix * 
gl_Vertex).xyz;
                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        }
);

static const char *fs = STRINGIFY(
        varying vec3 objPos;

        void main()
        {
                gl_FragColor = vec4(.5*objPos+.5, 1.);
        }
);

OSG::SimpleSceneManager *mgr;

int setupGLUT( int *argc, char *argv[] );

#define CHUNK_OVERRIDE

int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);

    int winid = setupGLUT(&argc, argv);

    {
        OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
        gwin->setGlutId(winid);
        gwin->init();

                OSG::NodeRefPtr torus = OSG::makeTorus(.25, 1., 64, 128);

                OSG::SimpleSHLChunkRefPtr shader = 
OSG::SimpleSHLChunk::create();
                shader->setVertexProgram(vs);
                shader->setFragmentProgram(fs);
                shader->addOSGVariable("OSGInvViewMatrix");
                OSG::ChunkMaterialRefPtr material = 
OSG::ChunkMaterial::create();
                material->addChunk(shader);
                OSG::MaterialGroupRefPtr mg = OSG::MaterialGroup::create();
                mg->setMaterial(material);
                OSG::NodeRefPtr mgNode = OSG::makeNodeFor(mg);
                mgNode->addChild(torus);

#ifdef CHUNK_OVERRIDE
                OSG::SimpleSHLChunkRefPtr overrideShader = 
OSG::SimpleSHLChunk::create();
                overrideShader->setVertexProgram(vs);
                overrideShader->setFragmentProgram(fs);
                overrideShader->addOSGVariable("OSGInvViewMatrix");
                OSG::ChunkOverrideGroupRefPtr overrideChunk = 
OSG::ChunkOverrideGroup::create();
                overrideChunk->addChunk(overrideShader);
                OSG::NodeRefPtr overrideNode = OSG::makeNodeFor(overrideChunk);
                overrideNode->addChild(mgNode);
#endif

        OSG::commitChanges();

        mgr = new OSG::SimpleSceneManager;
        mgr->setWindow(gwin);
#ifndef CHUNK_OVERRIDE
        mgr->setRoot(mgNode);
#else
                mgr->setRoot(overrideNode);
#endif
        mgr->showAll();
    }

    glutMainLoop();

    return 0;
}

void display(void)
{
    mgr->redraw();
}

void reshape(int w, int h)
{
    mgr->resize(w, h);
    glutPostRedisplay();
}

void mouse(int button, int state, int x, int y)
{
        if(button > 2)
                return;

    if(state)
        mgr->mouseButtonRelease(button, x, y);
    else
        mgr->mouseButtonPress(button, x, y);
        
    glutPostRedisplay();
}

void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

void keyboard(unsigned char k, int x, int y)
{
    switch(k)
    {
        case 27:
        {
            delete mgr;
        
            OSG::osgExit();
            exit(0);
        }
        break;

        case 's':
        {
            mgr->setStatistics(!mgr->getStatistics());
        }
        break;
    }
}

int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    int winid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    return winid;
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to