Ignore:
Timestamp:
Dec 10, 2004, 8:13:41 PM (20 years ago)
Author:
darran
Message:
  • terrible destruction of Swollen moving towards changes Robert suggests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Swollen/swollen/watersurface.cpp

    r43 r44  
    88
    99#include <watersurface.h>
     10#include <osg/AlphaFunc>
    1011#include <osg/BlendFunc>
    1112#include <osg/PolygonMode>
     
    1819#include <osgDB/ReadFile>
    1920
     21#include <osgUtil/TriStripVisitor>
     22
    2023
    2124#define DEF_WATER_COLOUR        0, 0, 0.5, 1        // R, G, B, Alpha (blue)
    2225#define DEF_WATER_TRANSPARENCY  0.1                 // 0=opaque, 1=transparent
    23 #define DEF_ZOFFSET             0.00
     26#define DEF_ZOFFSET             0.01
    2427
    2528// constructor
     
    3841    _node->addDrawable(_geom);
    3942    _node->setStateSet(_stateset);
    40     _stateset->setAttribute(_material);
     43    //_stateset->setAttribute(_material);
    4144
    42     // why???
    43     _geom->setUseDisplayList(false);
     45    _geom->setUseDisplayList(true);
    4446
    4547    // initial geometry
    4648    setTimeStep(0);
    4749
    48     _material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));
    49     _material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));
    50     _material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);
    51     _material->setShininess(osg::Material::FRONT, 128);
     50    //_material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));
     51    //_material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));
     52    //_material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);
     53    //_material->setShininess(osg::Material::FRONT, 128);
    5254
    5355    // environment map
     
    5759    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    5860    texture->setImage(osgDB::readImageFile("envmap.jpg"));
    59     _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );
     61    //_stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );
    6062    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
    6163
    6264    // surface transparency
    63     osg::BlendFunc* osgBlendFunc = new osg::BlendFunc();
    64     osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
    65     _stateset->setAttribute(osgBlendFunc);
    66     _stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
     65    //osg::BlendFunc* osgBlendFunc = new osg::BlendFunc();
     66    //osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
     67    //_stateset->setAttribute(osgBlendFunc);
     68    //_stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
     69
     70    osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
     71    //alphaFunc->setFunction(osg::AlphaFunc::GEQUAL,0.1f);
     72    alphaFunc->setFunction(osg::AlphaFunc::ALWAYS);
     73    _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON );
     74
    6775    _stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
     76
    6877
    6978    // automatically generate texture coords
     
    7483    texenv->setMode( osg::TexEnv::DECAL );
    7584    texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) );
    76     _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
    77     _stateset->setTextureAttribute( 1, texenv );
     85    //_stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
     86    //_stateset->setTextureAttribute( 1, texenv );
    7887}
    7988
     
    97106    osg::ref_ptr<osg::Vec3Array> normals = _sww->getStagePrimitiveNormalArray();
    98107    osg::ref_ptr<osg::Vec3Array> vertexnormals = _sww->getStageVertexNormalArray();
    99 
     108    osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray();
    100109
    101110    // vertical (z) offset to eliminate potential zbuffer problems with bedslope
    102     //for( unsigned int iv=0; iv < vertices.get()->size(); iv++ )
    103     //  vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset );
     111    osg::UIntArray* colorindices = new osg::UIntArray(vertices.get()->size());
     112    for( unsigned int iv=0; iv < vertices.get()->size(); iv++ )
     113    {
     114        vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset );
     115        colorindices->at(iv) = iv;
     116    }
    104117
     118    // geometry
    105119    _geom->setVertexArray( vertices.get() );
    106120    _geom->setVertexIndices( indices.get() );
     
    108122           osg::PrimitiveSet::TRIANGLES, 0, _sww->getNumberOfStageIndices() ) );
    109123
    110     //_geom->setNormalArray( normals.get() );
    111     //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
     124    // per vertex colors (using only alpha)
     125    _geom->setColorArray( colors.get() );
     126    _geom->setColorIndices( colorindices );
     127    _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
    112128
     129    // normals
    113130    _geom->setNormalArray( vertexnormals.get() );
    114131    _geom->setNormalIndices( indices.get() );
    115132    _geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
     133
     134    // osgUtil::TriStripVisitor* optimize = new osgUtil::TriStripVisitor();
     135    // optimize->stripify( *_geom );
    116136
    117137}
Note: See TracChangeset for help on using the changeset viewer.