Show
Ignore:
Timestamp:
07/05/10 18:32:58 (4 years ago)
Author:
robert
Message:

Added basic code injection fields to osg::Shader,
creation of main shader to ShaderComposer? and
collection of ShaderComponent? to osg::State.
Also added very basic shader set up in osgshadecomposition example.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgshadercomposition/osgshadercomposition.cpp

    r11664 r11666  
    3030    stateset->setAttribute(sa); 
    3131 
     32    { 
     33        const char shader_str[] = 
     34            "vec4 colour()\n" 
     35            "{\n" 
     36            "    return vec4(1.0,0.5,1.0,1.0);\n" 
     37           "}\n"; 
     38 
     39        osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, shader_str); 
     40        vertex_shader->addCodeInjection(-1,"varying vec4 c;\n"); 
     41        vertex_shader->addCodeInjection(-1,"vec4 colour();\n"); 
     42        vertex_shader->addCodeInjection(0,"gl_Position = ftransform();\n"); 
     43        vertex_shader->addCodeInjection(0,"c = colour();\n"); 
     44 
     45        sa->addShader(vertex_shader); 
     46     } 
     47 
     48     { 
     49        osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT); 
     50        fragment_shader->addCodeInjection(-1,"varying vec4 c;\n"); 
     51        fragment_shader->addCodeInjection(0,"gl_FragColor = c;\n"); 
     52 
     53        sa->addShader(fragment_shader); 
     54     } 
     55 
    3256    return node; 
    3357} 
     
    4468    viewer.setSceneData(scenegraph.get()); 
    4569 
     70    viewer.realize(); 
     71 
     72    // enable shader composition 
     73    osgViewer::Viewer::Windows windows; 
     74    viewer.getWindows(windows); 
     75    for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); 
     76        itr != windows.end(); 
     77        ++itr) 
     78    { 
     79        (*itr)->getState()->setShaderCompositionEnabled(true); 
     80    } 
     81 
    4682    return viewer.run(); 
    4783}