Show
Ignore:
Timestamp:
03/21/12 18:36:20 (2 years ago)
Author:
robert
Message:

Ran script to remove trailing spaces and tabs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgShadow/MinimalShadowMap.cpp

    r12292 r13041  
    1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield  
     1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
    22 * 
    3  * This library is open source and may be redistributed and/or modified under   
    4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or  
     3 * This library is open source and may be redistributed and/or modified under 
     4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
    55 * (at your option) any later version.  The full license is in LICENSE file 
    66 * included with this distribution, and on the openscenegraph.org website. 
    7  *  
     7 * 
    88 * This library is distributed in the hope that it will be useful, 
    99 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1111 * OpenSceneGraph Public License for more details. 
    1212 * 
     
    2525#define PRINT_SHADOW_TEXEL_TO_PIXEL_ERROR 0 
    2626 
    27 MinimalShadowMap::MinimalShadowMap():  
    28     BaseClass(),  
     27MinimalShadowMap::MinimalShadowMap(): 
     28    BaseClass(), 
    2929    _maxFarPlane( FLT_MAX ), 
    3030    _minLightMargin( 0 ), 
    3131    _shadowReceivingCoarseBoundAccuracy( BOUNDING_BOX ) 
    3232{ 
    33      
     33 
    3434} 
    3535 
     
    4343} 
    4444 
    45 MinimalShadowMap::~MinimalShadowMap()  
     45MinimalShadowMap::~MinimalShadowMap() 
    4646{ 
    4747} 
     
    5858    { 
    5959        // One may skip coarse scene bounds computation if light is infinite. 
    60         // Empty box will be intersected with view frustum so in the end  
     60        // Empty box will be intersected with view frustum so in the end 
    6161        // view frustum will be used as bounds approximation. 
    62         // But if light is nondirectional and bounds come out too large  
    63         // they may bring the effect of almost 180 deg perspective set  
    64         // up for shadow camera. Such projection will significantly impact  
     62        // But if light is nondirectional and bounds come out too large 
     63        // they may bring the effect of almost 180 deg perspective set 
     64        // up for shadow camera. Such projection will significantly impact 
    6565        // precision of further math. 
    6666 
     
    8787        frustum.cut( box ); 
    8888 
    89         // approximate sphere with octahedron. Ie first cut by box then  
     89        // approximate sphere with octahedron. Ie first cut by box then 
    9090        // additionaly cut with the same box rotated 45, 45, 45 deg. 
    9191        box.transform( // rotate box around its center 
    9292            osg::Matrix::translate( -bs.center() ) * 
    93             osg::Matrix::rotate( osg::PI_4, 0, 0, 1 ) *  
    94             osg::Matrix::rotate( osg::PI_4, 1, 1, 0 ) *  
     93            osg::Matrix::rotate( osg::PI_4, 0, 0, 1 ) * 
     94            osg::Matrix::rotate( osg::PI_4, 1, 1, 0 ) * 
    9595            osg::Matrix::translate( bs.center() ) ); 
    9696        frustum.cut( box ); 
    97      
    98         return frustum.computeBoundingBox( );     
    99     } 
    100      
     97 
     98        return frustum.computeBoundingBox( ); 
     99    } 
     100 
    101101    if( accuracy == MinimalShadowMap::BOUNDING_BOX ) // Default 
    102102    { 
    103         // more precise method but slower method  
    104         // bound visitor traversal takes lot of time for complex scenes  
     103        // more precise method but slower method 
     104        // bound visitor traversal takes lot of time for complex scenes 
    105105        // (note that this adds to cull time) 
    106106 
     
    115115} 
    116116 
    117 void MinimalShadowMap::ViewData::aimShadowCastingCamera(  
     117void MinimalShadowMap::ViewData::aimShadowCastingCamera( 
    118118                                        const osg::BoundingSphere &bs, 
    119119                                        const osg::Light *light, 
    120120                                        const osg::Vec4 &lightPos, 
    121121                                        const osg::Vec3 &lightDir, 
    122                                         const osg::Vec3 &lightUpVector  
     122                                        const osg::Vec3 &lightUpVector 
    123123                                        /* by default = osg::Vec3( 0, 1 0 )*/ ) 
    124124{ 
     
    129129 ( const osg::Light *light, const osg::Vec4 &lightPos, 
    130130   const osg::Vec3 &lightDir, const osg::Vec3 &lightUp ) 
    131 {     
     131{ 
    132132    osg::BoundingBox bb = computeScenePolytopeBounds(); 
    133133    if( !bb.valid() ) { // empty scene or looking at the sky - substitute something 
     
    137137    osg::Vec3 up = lightUp; 
    138138 
    139     if( up.length2() <= 0 )  
     139    if( up.length2() <= 0 ) 
    140140    { 
    141     // This is extra step (not really needed but helpful in debuging)  
     141    // This is extra step (not really needed but helpful in debuging) 
    142142    // Compute such lightUp vector that shadow cam is intuitively aligned with eye 
    143143    // We compute this vector on -ZY view plane, perpendicular to light direction 
     
    158158        up.set( -m( 2, 0 ), -m( 2, 1 ), -m( 2, 2 ) ); 
    159159#endif 
    160     }  
     160    } 
    161161 
    162162    aimShadowCastingCamera( osg::BoundingSphere( bb ), light, lightPos, lightDir, up ); 
     
    176176     ( const osg::Camera* cameraMain, osg::Camera* cameraShadow, int pass ) 
    177177{ 
    178     osg::Matrix mvp =  
     178    osg::Matrix mvp = 
    179179        cameraShadow->getViewMatrix() * cameraShadow->getProjectionMatrix(); 
    180180 
     
    195195 
    196196        // So I replaced it with safer code working with spot lights as well 
    197         osg::Vec3d normal =  
     197        osg::Vec3d normal = 
    198198            osg::Vec3d(0,0,-1) * transform - osg::Vec3d(0,0,1) * transform; 
    199199 
     
    202202 
    203203        // Zero pass does crude shadowed scene hull approximation. 
    204         // Its important to cut it to coarse light frustum properly  
     204        // Its important to cut it to coarse light frustum properly 
    205205        // at this stage. 
    206         // If not cut and polytope extends beyond shadow projection clip  
    207         // space (-1..1), it may get "twisted" by precisely adjusted shadow cam  
    208         // projection in second pass.  
     206        // If not cut and polytope extends beyond shadow projection clip 
     207        // space (-1..1), it may get "twisted" by precisely adjusted shadow cam 
     208        // projection in second pass. 
    209209 
    210210        if ( pass == 0 && _frameShadowCastingCameraPasses > 1 ) 
     
    223223    } 
    224224 
    225     setDebugPolytope( "extended",  
     225    setDebugPolytope( "extended", 
    226226        _sceneReceivingShadowPolytope, osg::Vec4( 1, 0.5, 0, 1 ), osg::Vec4( 1, 0.5, 0, 0.1 ) ); 
    227227 
    228228    _sceneReceivingShadowPolytope = polytope; 
    229229    _sceneReceivingShadowPolytopePoints = points; 
    230      
    231     // Warning: Trim light projection at near plane may remove shadowing  
     230 
     231    // Warning: Trim light projection at near plane may remove shadowing 
    232232    // from objects outside of view space but still casting shadows into it. 
    233233    // I have not noticed this issue so I left mask at default: all bits set. 
     
    236236 
    237237    ///// Debuging stuff ////////////////////////////////////////////////////////// 
    238     setDebugPolytope( "scene", _sceneReceivingShadowPolytope, osg::Vec4(0,1,0,1) );     
     238    setDebugPolytope( "scene", _sceneReceivingShadowPolytope, osg::Vec4(0,1,0,1) ); 
    239239 
    240240 
     
    254254            frustum.transform( osg::Matrix::inverse( mvp ), mvp ); 
    255255 
    256             setDebugPolytope( "shadowCamFrustum", frustum, osg::Vec4(0,0,1,1) );     
     256            setDebugPolytope( "shadowCamFrustum", frustum, osg::Vec4(0,0,1,1) ); 
    257257        } 
    258258 
     
    271271            dump( *filename ); 
    272272            filename->clear(); 
    273         }  
     273        } 
    274274    } 
    275275} 
     
    284284 
    285285        // Redo steps from CullVisitor::popProjectionMatrix() 
    286         // which clamps projection matrix when Camera & Projection  
     286        // which clamps projection matrix when Camera & Projection 
    287287        // completes traversal of their children 
    288288 
    289         // We have to do this now manually  
    290         // because we did not complete camera traversal yet but  
     289        // We have to do this now manually 
     290        // because we did not complete camera traversal yet but 
    291291        // we need to know how this clamped projection matrix will be 
    292292 
    293293        _cv->computeNearPlane(); 
    294          
     294 
    295295        osgUtil::CullVisitor::value_type n = _cv->getCalculatedNearPlane(); 
    296296        osgUtil::CullVisitor::value_type f = _cv->getCalculatedFarPlane(); 
     
    298298        if( n < f ) 
    299299            _cv->clampProjectionMatrix( _clampedProjection, n, f ); 
    300     }  
    301  
    302     // Aditionally clamp far plane if shadows don't need to be cast as  
    303     // far as main projection far plane  
     300    } 
     301 
     302    // Aditionally clamp far plane if shadows don't need to be cast as 
     303    // far as main projection far plane 
    304304    if( 0 < *_maxFarPlanePtr ) 
    305305        clampProjection( _clampedProjection, 0.f, *_maxFarPlanePtr ); 
    306306 
    307     // Give derived classes chance to initialize _sceneReceivingShadowPolytope      
     307    // Give derived classes chance to initialize _sceneReceivingShadowPolytope 
    308308    osg::BoundingBox bb = computeShadowReceivingCoarseBounds( ); 
    309309    if( bb.valid() ) 
    310310        _sceneReceivingShadowPolytope.setToBoundingBox( bb ); 
    311     else  
     311    else 
    312312        _sceneReceivingShadowPolytope.clear(); 
    313313 
    314     // Cut initial scene using main camera frustum.  
    315     // Cutting will work correctly on empty polytope too.  
     314    // Cut initial scene using main camera frustum. 
     315    // Cutting will work correctly on empty polytope too. 
    316316    // Take into consideration near far calculation and _maxFarPlane variable 
    317317 
     
    337337 
    338338void MinimalShadowMap::ViewData::cutScenePolytope 
    339     ( const osg::Matrix & transform,  
    340       const osg::Matrix & inverse,  
     339    ( const osg::Matrix & transform, 
     340      const osg::Matrix & inverse, 
    341341      const osg::BoundingBox & bb ) 
    342 {    
     342{ 
    343343    _sceneReceivingShadowPolytopePoints.clear(); 
    344344 
     
    347347        polytope.setToBoundingBox( bb ); 
    348348        polytope.transformProvidingInverse( inverse ); 
    349         _sceneReceivingShadowPolytope.cut( polytope );         
     349        _sceneReceivingShadowPolytope.cut( polytope ); 
    350350        _sceneReceivingShadowPolytope.getPoints 
    351351                                ( _sceneReceivingShadowPolytopePoints ); 
     
    354354} 
    355355 
    356 osg::BoundingBox  
     356osg::BoundingBox 
    357357    MinimalShadowMap::ViewData::computeScenePolytopeBounds( const osg::Matrix & m ) 
    358358{ 
     
    362362        for( unsigned i = 0; i < _sceneReceivingShadowPolytopePoints.size(); ++i ) 
    363363            bb.expandBy( _sceneReceivingShadowPolytopePoints[i] * m ); 
    364     else  
     364    else 
    365365        for( unsigned i = 0; i < _sceneReceivingShadowPolytopePoints.size(); ++i ) 
    366366            bb.expandBy( _sceneReceivingShadowPolytopePoints[i] ); 
     
    399399    if( !bb.valid() || !( trimMask & (1|2|4|8|16|32) ) ) return; 
    400400    double l, r, t, b, n, f; 
    401     bool ortho = projectionMatrix.getOrtho( l, r, b, t, n, f );  
     401    bool ortho = projectionMatrix.getOrtho( l, r, b, t, n, f ); 
    402402    if( !ortho && !projectionMatrix.getFrustum( l, r, b, t, n, f ) ) 
    403403        return; // rotated or skewed or other crooked projection - give up 
     
    410410 
    411411    osg::Matrix projectionToView = osg::Matrix::inverse( projectionMatrix ); 
    412      
     412 
    413413    osg::Vec3 min = 
    414414        osg::Vec3( bb._min[0], bb._min[1], bb._min[2] ) * projectionToView; 
     
    453453    } 
    454454 
    455     if( ortho )  
     455    if( ortho ) 
    456456        projectionMatrix.makeOrtho( l, r, b, t, n, f ); 
    457     else  
     457    else 
    458458        projectionMatrix.makeFrustum( l, r, b, t, n, f ); 
    459459#endif 
     
    480480            } 
    481481            n = new_near; 
    482         }  
     482        } 
    483483 
    484484        if( n < new_far && new_far < f ) { 
    485             f = new_far;              
     485            f = new_far; 
    486486        } 
    487487 
     
    489489            projection.makeFrustum( l, r, b, t, n, f ); 
    490490        else 
    491             projection.makeOrtho( l, r, b, t, n, f );                      
    492     } 
    493 } 
    494  
    495 // Imagine following scenario:  
     491            projection.makeOrtho( l, r, b, t, n, f ); 
     492    } 
     493} 
     494 
     495// Imagine following scenario: 
    496496// We stand in the room and look through the window. 
    497497// How should our view change if we were looking through larger window ? 
    498 // In other words how should projection be adjusted if  
    499 // window had grown by some margin ?  
     498// In other words how should projection be adjusted if 
     499// window had grown by some margin ? 
    500500// Method computes such new projection which maintains perpective/world ratio 
    501501 
     
    515515 
    516516  osg::Matrix window = viewport->computeWindowMatrix(); 
    517   
    518   osg::Vec3 vMin( viewport->x() - margin.x(),  
    519                  viewport->y() - margin.y(),  
     517 
     518  osg::Vec3 vMin( viewport->x() - margin.x(), 
     519                 viewport->y() - margin.y(), 
    520520                 0.0 ); 
    521521 
    522   osg::Vec3 vMax( viewport->width() + margin.x() * 2  + vMin.x(),  
    523                   viewport->height() + margin.y() * 2  + vMin.y(),  
     522  osg::Vec3 vMax( viewport->width() + margin.x() * 2  + vMin.x(), 
     523                  viewport->height() + margin.y() * 2  + vMin.y(), 
    524524                  0.0 ); 
    525    
     525 
    526526  osg::Matrix inversePW = osg::Matrix::inverse( projection * window ); 
    527527 
    528528  vMin = vMin * inversePW; 
    529529  vMax = vMax * inversePW; 
    530    
    531   l = vMin.x();  
     530 
     531  l = vMin.x(); 
    532532  r = vMax.x(); 
    533   b = vMin.y();  
     533  b = vMin.y(); 
    534534  t = vMax.y(); 
    535535 
    536536  if( frustum ) 
    537537    projection.makeFrustum( l,r,b,t,n,f ); 
    538   else  
     538  else 
    539539    projection.makeOrtho( l,r,b,t,n,f ); 
    540540}