Ignore:
Timestamp:
01/11/07 21:40:49 (18 years ago)
Author:
mattausch
Message:

global lines nearly useable!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp

    r1968 r1969  
    77#include "Exporter.h" 
    88#include "ViewCellsManager.h" 
     9#include "SamplingStrategy.h" 
    910 
    1011 
     
    161162                        return; 
    162163                } 
     164        case '5': 
     165                { 
     166                        VssRayContainer rays; 
     167 
     168                        HwGlobalLinesDistribution glStrategy(*globalLinesRenderer->mPreprocessor); 
     169 
     170                        SimpleRayContainer simpleRays; 
     171                        glStrategy.GenerateSamples(5, simpleRays); 
     172 
     173                        //cout << "simple ray: " << simpleRays[4] << endl; 
     174                        globalLinesRenderer->CastGlobalLines(simpleRays[1], rays); 
     175 
     176                        // visualize 
     177                        VssRayContainer outRays; 
     178                        VssRayContainer::const_iterator vit, vit_end = rays.end(); 
     179 
     180                        const float p = 8.0f / (float)rays.size(); 
     181 
     182                        for (vit = rays.begin(); vit != vit_end; ++ vit) 
     183                        { 
     184                                if (Random(1.0f) < p) 
     185                                { 
     186                                        outRays.push_back(*vit); 
     187                                } 
     188                        } 
     189 
     190                        globalLinesRenderer->Visualize(rays); 
     191 
     192                        CLEAR_CONTAINER(rays); 
     193                        return; 
     194                } 
    163195        case '8': 
    164196                { 
     
    170202                        VssRayContainer rays; 
    171203                        globalLinesRenderer->ApplyDepthPeeling(rays); 
     204 
     205                        // visualize 
    172206                        VssRayContainer outRays; 
    173207                        VssRayContainer::const_iterator vit, vit_end = rays.end(); 
     
    209243mOldTexture(NULL),  
    210244mPreprocessor(preprocessor), 
    211 mTexHeight(mTexHeight), 
    212 mTexWidth(mTexWidth), 
     245mTexHeight(texHeight), 
     246mTexWidth(texWidth), 
    213247mEpsilon(eps), 
    214248mMaxDepth(maxDepth), 
     
    325359void GlobalLinesRenderer::InitScene(const float alpha, const float beta) 
    326360{ 
     361        cout << "here44"<<endl; 
    327362        AxisAlignedBox3 bbox =  
    328363                globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 
    329          
     364        cout << "here77"<<endl; 
    330365        const float sceneSize = Magnitude(bbox.Diagonal()); 
    331366 
     
    356391        mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec; 
    357392 
    358         cout << "termination point: " << mTermination << endl; 
    359         cout << "view point: " << mViewPoint << endl; 
    360         cout << "scene: " << bbox << endl; 
     393        //cout << "termination point: " << mTermination << endl; 
     394        //cout << "view point: " << mViewPoint << endl; 
     395        //cout << "scene: " << bbox << endl; 
    361396 
    362397        InitRenderTexture(mNewTexture); 
    363398        InitRenderTexture(mOldTexture); 
    364399         
    365         cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
     400        //cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
    366401} 
    367402 
     
    385420 
    386421        mEyeVec.RightHandedBase(mUpVec, mLeftVec); 
    387     mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec; 
    388  
    389         cout << "termination point: " << mTermination << endl; 
    390         cout << "view point: " << mViewPoint << endl; 
    391         cout << "scene: " << bbox << endl; 
     422 
     423        //cout << "termination point: " << mTermination << endl; 
     424        //cout << "view point: " << mViewPoint << endl; 
     425        //cout << "scene: " << bbox << endl; 
    392426 
    393427        InitRenderTexture(mNewTexture); 
    394428        InitRenderTexture(mOldTexture); 
    395429         
    396         cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
    397 } 
    398  
    399  
    400 void GlobalLinesRenderer::CastGlobalLines(const float alpha,  
     430        //cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl; 
     431} 
     432 
     433 
     434int GlobalLinesRenderer::CastGlobalLines(const float alpha,  
    401435                                                                                  const float beta,  
    402                                                                                   //const int samples, 
    403436                                                                                  VssRayContainer &rays) 
    404437{ 
     
    406439 
    407440        // bind pixel shader implementing the front depth buffer functionality 
    408         ApplyDepthPeeling(rays); 
    409 } 
    410  
    411  
    412 void GlobalLinesRenderer::CastGlobalLines(const SimpleRay &ray,  
     441        const int layers = ApplyDepthPeeling(rays); 
     442 
     443        return layers; 
     444} 
     445 
     446 
     447int GlobalLinesRenderer::CastGlobalLines(const SimpleRay &ray,  
    413448                                                                                  VssRayContainer &rays) 
    414449{ 
     450        const long startTime = GetTime(); 
     451        cout << "casting global lines ... " << endl; 
     452 
    415453        InitScene(ray); 
    416454 
    417455        // bind pixel shader implementing the front depth buffer functionality 
    418         ApplyDepthPeeling(rays); 
    419 } 
    420  
    421 void GlobalLinesRenderer::RenderObject(Intersectable *obj) 
    422 { 
    423         mRenderer->RenderIntersectable(obj); 
     456        const int layers = ApplyDepthPeeling(rays); 
     457 
     458        const float rays_per_sec = rays.size() / TimeDiff(startTime, GetTime()) * 1e-3; 
     459        cout << "cast " << rays.size() << " samples in " << layers << " layers in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs (" << rays_per_sec << " r / s)" << endl; 
     460        return layers; 
    424461} 
    425462 
     
    436473 
    437474                Intersectable::NewMail(); 
    438  
    439                 for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit) 
    440                 { 
    441                         //cout << (*oit)->GetId() << " "; 
    442                         RenderObject(*oit); 
    443                 } 
     475         
     476                mRenderer->RenderScene(); 
    444477        } 
    445478        glPopMatrix(); 
     
    534567        // depth and stencil. 
    535568        // Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware 
    536          
     569        cout << "texwidth: " << mTexWidth << " texheight: " << mTexHeight << endl; 
    537570        mNewTexture = new RenderTexture(mTexWidth, mTexHeight, true, true); 
    538571#ifdef ATI 
    539         mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
     572        mNewTexture->Initialize(true, true, false, false, false, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
    540573#else 
    541         mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
     574        mNewTexture->Initialize(true, true, false, false, false, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
    542575#endif 
    543576 
     
    545578 
    546579#ifdef ATI 
    547         mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
     580        mOldTexture ->Initialize(true, true, false, false, false, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE); 
    548581#else 
    549         mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
     582        mOldTexture ->Initialize(true, true, false, false, false, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE); 
    550583#endif 
    551584 
     
    579612                if (!mNewTexture->IsRectangleTexture())  
    580613                { 
    581                         sTexWidthParam = cgGetNamedParameter(sCgDepthPeelingProgram, "texWidth"); 
     614                        sTexWidthParam = cgGetNamedParameter(sCgDepthPeelingProgram, "invTexWidth"); 
    582615                } 
    583616 
    584617                sStepSizeParam = cgGetNamedParameter(sCgDepthPeelingProgram, "stepSize");  
    585618 
    586                 cgGLSetParameter1f(sTexWidthParam, (float)mTexWidth); 
     619                cgGLSetParameter1f(sTexWidthParam, 1.0f / (float)mTexWidth); 
    587620                cgGLSetParameter1f(sStepSizeParam, mEpsilon); 
    588621        } 
     
    600633                cgGLLoadProgram(sCgPassThroughProgram); 
    601634        } 
    602  
     635cout << "here45" << endl; 
    603636        const float alpha = 1.1; 
    604637        const float beta = 0.9; 
    605638        InitScene(alpha, beta); 
    606  
     639cout << "here4005" << endl; 
    607640        PrintGLerror("init"); 
    608641} 
     
    748781                        Vector3 clippedOldPt, clippedNewPt; 
    749782 
    750                         ClipToViewSpaceBox(oldPt, newPt, clippedOldPt, clippedNewPt); 
    751                         //clippedOldPt = oldPt; 
    752                         //clippedNewPt = newPt; 
    753  
    754                         // create rays in both directions 
    755                         if (termObj1) 
     783                        ClipToViewSpaceBox(oldPt, newPt, clippedOldPt, clippedNewPt);if(1) 
    756784                        { 
    757                                 vssRays.push_back(new VssRay(clippedOldPt, clippedNewPt, NULL, termObj1, pass)); 
    758                                 //cout << "new pt: " << newPt << endl; 
    759                         } 
    760  
    761                         if (mSampleReverse && termObj2) 
    762                         { 
    763                                 vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass)); 
    764                                 //cout << "old pt: " << oldPt << endl; 
     785                                //clippedOldPt = oldPt; 
     786                                //clippedNewPt = newPt; 
     787 
     788                                // create rays in both directions 
     789                                if (termObj1) 
     790                                { 
     791                                        vssRays.push_back(new VssRay(clippedOldPt, clippedNewPt, NULL, termObj1, pass)); 
     792                                        //cout << "new pt: " << newPt << endl; 
     793                                } 
     794 
     795                                if (mSampleReverse && termObj2) 
     796                                { 
     797                                        vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass)); 
     798                                        //cout << "old pt: " << oldPt << endl; 
     799                                } 
    765800                        } 
    766801                } 
     
    936971 
    937972 
    938 void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays) 
    939 { 
     973int GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays) 
     974{ 
     975        int layers = 1; 
     976 
    940977        mNewTexture->BeginCapture(); 
    941978        { 
     
    952989        ProcessDepthBuffer(rays, false, 0); 
    953990 
    954         for(int i = 1; i < mMaxDepth; ++ i)  
     991        for(; layers < mMaxDepth; ++ layers)  
    955992        { 
    956993                // Peel another layer 
     
    9761013                // process the buffers for following layer 
    9771014                // jump out of loop for the first invalid buffer 
    978                 if (!ProcessDepthBuffer(rays, true, i)) 
     1015                if (!ProcessDepthBuffer(rays, true, layers)) 
    9791016                        break; 
    9801017        } 
    9811018 
    9821019        PrintGLerror("endpeeling"); 
    983 } 
    984  
    985  
    986 } 
     1020 
     1021        return layers; 
     1022} 
     1023 
     1024 
     1025} 
Note: See TracChangeset for help on using the changeset viewer.