Changeset 332 for experimental


Ignore:
Timestamp:
Mar 11, 2012, 4:50:14 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/distortionNG.cpp

    r331 r332  
    130130        - Verzerrung der Textur-Koordinaten aus der RTT-Szene
    131131    - Verzerrung des Meshes im Verzerrungs-Rendern
    132  Die IntensityMap muss über das fertige verzerrte Bild gelegt werden.
     132 *
     133 Die IntensityMap kann folgendermaßen angewendet werden:
     134 * Extrahierung der Coloran den Mesh-Nodes und anwendung als Color im Mesh node. Vorteil : Einfach. Nachteil: Helligkeiten werden zwischen Mesh-Nodes interpoliert: nur grobe Intensity Steuerung möglich
     135 * Anwendung der Intensity-Textur pro Pixel: Verwenden eines Sharders um die Frament-Color mit der Farbe der Intensity-color zu multiplizieren
     136 *
     137 -> Evtl. sollte die Funktion der Intensitysteuerung aus den OSG-Distortion-Funktionen ausgeklammert und als eigene OSG-Schnittstelle/Funktion angestrebt werden.
    133138
    134139
  • experimental/distortionNG/extViewer.cpp

    r331 r332  
    3232}
    3333
    34 static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, const osg::Matrix& projectorMatrix)
     34static void configureShaders( osg::StateSet* stateSet )
     35{
     36        // Create Shaders
     37    const std::string vertexSource =
     38                "uniform sampler2D sceneTexture;\n"
     39                "uniform sampler2D intensityMapTexture;\n"
     40        "uniform mat4 osg_ModelViewProjectionMatrix; \n"
     41                //"uniform vec3 ecLightDir; \n"
     42        " \n"
     43        "in vec4 osg_Vertex; \n"
     44                "in vec4 osg_Color; \n"
     45        " \n"
     46        "void main() \n"
     47        "{ \n"
     48        "    gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n"
     49                "        gl_FrontColor = osg_Color;\n"
     50                " \n"
     51        "} \n";
     52
     53    osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, vertexSource );
     54        vShader->setName("intensityMapVertShader");
     55
     56    const std::string fragmentSource =
     57                "uniform sampler2D sceneTexture;\n"
     58                "uniform sampler2D intensityMapTexture;\n"
     59        "varying vec2 texcoord;\n"
     60        "\n"
     61        "void main(void) \n"
     62        "{\n"
     63                "        vec2 texcoord0 = vec2( gl_TexCoord[0] );\n"
     64                "        vec2 texcoord1 = vec2( gl_TexCoord[1] );\n"
     65        "    gl_FragColor = texture2D( sceneTexture, texcoord0) * texture2D( sceneTexture, texcoord0); \n"
     66        "}\n";
     67    osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, fragmentSource );
     68        fShader->setName("intensityMapFragShader");
     69
     70        // Create Programm
     71    osg::Program* program = new osg::Program;
     72    program->addShader( vShader );
     73    program->addShader( fShader );
     74        program->setName("intensityMapFragProgramm");
     75    stateSet->setAttribute( program );
     76
     77        osg::Uniform* sceneTextureSampler = new osg::Uniform("sceneTexture",0);
     78    stateSet->addUniform(sceneTextureSampler);
     79        osg::Uniform* intensityMapTextureSampler = new osg::Uniform("intensityMapTexture",1);
     80    stateSet->addUniform(intensityMapTextureSampler);
     81
     82
     83    /*osg::Vec3f lightDir( 0., 0.5, 1. );
     84    lightDir.normalize();
     85    stateSet->addUniform( new osg::Uniform( "ecLightDir", lightDir ) );*/
     86}
     87
     88static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, bool applyIntensityMapAsColours, const osg::Matrix& projectorMatrix)
    3589{
    3690        // Create Quad to render on
     
    73127
    74128                        // Set Color of the mesh node
    75                         if (intensityMap)
     129                        if (intensityMap && applyIntensityMapAsColours)
    76130                        {
    77131                                colors->push_back(intensityMap->getColor(texcoord));
     
    109163                }
    110164                geom->addPrimitiveSet( de.get() );
     165        }
     166
     167        if (intensityMap && !applyIntensityMapAsColours)
     168        {
     169                configureShaders( geom->getOrCreateStateSet() );
     170                geom->setInitialBound( osg::BoundingBox(origin, origin+widthVector+heightVector) );
    111171        }
    112172
     
    215275        osg::Geode* geode = new osg::Geode();
    216276                //geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 1, 0.45, intensityMap, projectorMatrix));
    217                 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, projectorMatrix);
     277                osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, applyIntensityMapAsColours, projectorMatrix);
    218278                geode->addDrawable(distortionMesh);
    219279
Note: See TracChangeset for help on using the changeset viewer.