Show
Ignore:
Timestamp:
06/21/05 17:24:23 (9 years ago)
Author:
robert
Message:

Added matrix and simple vertex shader paths.

Files:
1 modified

Legend:

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

    r4347 r4348  
    1515#include <osgProducer/Viewer> 
    1616 
     17/////////////////////////////////////////////////////////////////// 
     18// vertex shader using just Vec4 coefficients 
    1719char vertexShaderSource_simple[] =  
    1820    "uniform vec4 coeff; \n" 
     
    2628    "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" 
    2729    "}\n"; 
    28      
     30   
     31   
     32////////////////////////////////////////////////////////////////// 
     33// vertex shader using full Matrix4 coefficients 
     34char vertexShaderSource_matrix[] =  
     35    "uniform vec4  origin; \n" 
     36    "uniform mat4  coeffMatrix; \n" 
     37    "\n" 
     38    "void main(void) \n" 
     39    "{ \n" 
     40    "\n" 
     41    "    gl_TexCoord[0] = gl_Vertex; \n" 
     42    "    vec4 v = vec4(gl_Vertex.x, gl_Vertex.x*gl_Vertex.x, gl_Vertex.y, gl_Vertex.y*gl_Vertex.y ); \n" 
     43    "    gl_Position = gl_ModelViewProjectionMatrix * (origin + coeffMatrix * v);\n" 
     44    "}\n"; 
     45 
     46 
     47////////////////////////////////////////////////////////////////// 
     48// fragment shader 
     49// 
    2950char fragmentShaderSource[] =  
    3051    "uniform sampler2D baseTexture; \n" 
     
    3657 
    3758 
     59 
    3860class UniformVarying : public osg::Uniform::Callback 
    3961{ 
     
    4668}; 
    4769 
    48 osg::Node* createModel() 
     70osg::Node* createModel(const std::string& shader) 
    4971{ 
    5072    osg::Geode* geode = new osg::Geode; 
     
    98120    stateset->setAttribute(program); 
    99121 
    100     osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource_simple); 
    101     program->addShader(vertex_shader); 
    102      
     122    if (shader=="simple") 
     123    { 
     124        osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource_simple); 
     125        program->addShader(vertex_shader); 
     126 
     127        osg::Uniform* coeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f)); 
     128        coeff->setUpdateCallback(new UniformVarying); 
     129        stateset->addUniform(coeff); 
     130    } 
     131    else if (shader=="matrix") 
     132    { 
     133        osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource_matrix); 
     134        program->addShader(vertex_shader); 
     135 
     136        osg::Uniform* origin = new osg::Uniform("origin",osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 
     137        stateset->addUniform(origin); 
     138 
     139        osg::Uniform* coeffMatrix = new osg::Uniform("coeffMatrix", 
     140            osg::Matrix(1.0f,0.0f,1.0f,0.0f, 
     141                        0.0f,0.0f,-1.0f,0.0f, 
     142                        0.0f,1.0f,-1.0f,0.0f, 
     143                        0.0f,0.0f,1.0f,0.0f)); 
     144 
     145        stateset->addUniform(coeffMatrix); 
     146    } 
     147    else if (shader=="texture") 
     148    { 
     149         
     150    } 
    103151 
    104152    osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource); 
    105153    program->addShader(fragment_shader); 
    106  
    107  
    108     osg::Uniform* xCoeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f)); 
    109     xCoeff->setUpdateCallback(new UniformVarying); 
    110     stateset->addUniform(xCoeff); 
    111  
    112154     
    113155    osg::Texture2D* texture = new osg::Texture2D(osgDB::readImageFile("lz.rgb")); 
     
    139181    // set up the value with sensible default event handlers. 
    140182    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
     183     
     184    std::string shader("simple"); 
     185    while(arguments.read("-s",shader)) {} 
     186     
    141187 
    142188    // get details on keyboard and mouse bindings used by the viewer. 
     
    161207 
    162208    // load the nodes from the commandline arguments. 
    163     osg::Node* model = createModel(); 
     209    osg::Node* model = createModel(shader); 
    164210    if (!model) 
    165211    {