Changeset 20


Ignore:
Timestamp:
01/07/2008 04:53:38 PM (4 years ago)
Author:
art
Message:
  • Hack with unbounded textures is solved
  • Shaders and ppus seems to work now fine, my another application (refEiko), works now also fine with osgPPU
  • example application slightly changed
Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/osgPPU/PostProcessUnit.h

    r19 r20  
    181181        inline osg::Viewport* getViewport() { return mViewport.get(); } 
    182182         
    183         inline void setExpireBlendTime(float time) { mExpireTime = time; } 
     183        inline void setEndBlendTime(float time) { mExpireTime = time; } 
    184184        inline void setBlendDuration(float time) { mExpireTime = mStartTime + time; } 
    185         inline float getExpireBlendTime() const { return mExpireTime; } 
     185        inline float getEndBlendTime() const { return mExpireTime; } 
    186186 
    187187        inline void setStartBlendTime(float time) { mStartTime = time; } 
     
    271271 
    272272        //! Shall we use mipmaps at all  
    273         inline void setUseMipmaps(bool b) { mbUseMipmaps = b; } 
     273        inline void setUseMipmaps(bool b) { mbUseMipmaps = b; if (b) enableMipmapGeneration(); } 
    274274 
    275275        //! Set user data 
     
    429429        //! Dirty Shader 
    430430        bool mbDirtyShader; 
    431  
    432         //! Current color fo the geometry quad 
    433         osg::ref_ptr<osg::Vec4Array> mScreenQuadColor; 
    434431 
    435432                //! This ppu is marked as not to be included into the rendering graph  
  • trunk/src/example/Makefile

    r11 r20  
    2121LIBS += -losgPPU -losgViewer 
    2222LDFLAGS = $(LIBPATH) $(LIBS) 
     23#CFLAGS= -g -Wall -m32 $(INCPATH) 
    2324 
    2425# directory where to put result in 
  • trunk/src/example/hdrppu.cpp

    r14 r20  
    6969                    lumShader->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, "Data/luminance_fp.glsl")); 
    7070                    lumShader->setName("LuminanceShader"); 
    71                      
     71                    lumShader->add("texUnit0", osg::Uniform::SAMPLER_2D); 
     72                    lumShader->set("texUnit0", 0); 
     73 
    7274                    // create shader which do compute the scene's luminance in mipmap levels 
    7375                    osgPPU::Shader* lumShaderMipmap = new osgPPU::Shader(); 
    7476                    lumShaderMipmap->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, "Data/luminance_mipmap_fp.glsl")); 
    7577                    lumShaderMipmap->setName("LuminanceShaderMipmap"); 
     78 
     79                    // setup input texture 
     80                    lumShader->add("texUnit0", osg::Uniform::SAMPLER_2D); 
     81                    lumShader->set("texUnit0", 0); 
    7682                     
    7783                    // setup shader parameters 
     
    180186                    gaussx->set("radius", mHDRBlurRadius); 
    181187 
     188                    gaussx->add("texUnit0", osg::Uniform::SAMPLER_2D); 
     189                    gaussx->set("texUnit0", 0); 
     190 
    182191                    blurx->setShader(gaussx); 
    183192                     
     
    193202                    gaussy->set("sigma", mHDRBlurSigma); 
    194203                    gaussy->set("radius", mHDRBlurRadius); 
     204 
     205                    gaussy->add("texUnit0", osg::Uniform::SAMPLER_2D); 
     206                    gaussy->set("texUnit0", 0); 
    195207 
    196208                    blury->setShader(gaussy);                     
  • trunk/src/osgPPU/PPUInOut.cpp

    r19 r20  
    6666    if (mShader.valid())  
    6767    { 
    68         //mShader->set("g_TextureWidth", (float)(mViewport->x() + mViewport->width())); 
    69         //mShader->set("g_TextureHeight",(float)(mViewport->y() + mViewport->height())); 
    7068        mShader->set("g_ViewportWidth", (float)mViewport->width()); 
    7169        mShader->set("g_ViewportHeight", (float)mViewport->height()); 
     
    7977    // apply viewport if such is valid 
    8078    if (mViewport.valid()) mViewport->apply(*sState.getState()); 
    81          
     79 
    8280    // render the content of the input texture into the frame buffer 
    8381    if (useBlendMode()) 
    8482    { 
    85         //glEnable(GL_BLEND); 
     83        glEnable(GL_BLEND); 
    8684        glColor4f(1,1,1, getCurrentBlendValue()); 
    8785    } 
     
    8987    if (useBlendMode()) 
    9088    { 
    91         //glDisable(GL_BLEND); 
     89        glDisable(GL_BLEND); 
    9290        glColor4f(1,1,1,1); 
    9391    }    
     
    244242 
    245243            // setup viewport 
    246             osg::Viewport* vp = new osg::Viewport(*mViewport); 
    247             setViewport(vp); 
    248         } 
    249         sScreenQuad->getOrCreateStateSet()->setAttribute(mViewport.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
     244            //osg::Viewport* vp = new osg::Viewport(*mViewport); 
     245            //setViewport(*mViewport); 
     246        } 
     247        //sScreenQuad->getOrCreateStateSet()->setAttribute(mViewport.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 
    250248 
    251249        // clean mipmap data for output 
     
    313311                // set fbo of current level with to this output          
    314312                fbo->setAttachment(GL_COLOR_ATTACHMENT0_EXT + mrt, osg::FrameBufferAttachment(output.get(), level)); 
    315  
    316                 //printf("fbo %s: %d (%d) = %p, fmt=0x%x\n", getResourceName().c_str(), mrt, level, output.get(), output->getInternalFormat()); 
    317313            } 
    318314 
     
    344340        for (int i=0; i < mNumLevels; i++) 
    345341        { 
    346             // set mipmap level 
    347             //if (mShaderMipmapLevelUniform.valid()) mShaderMipmapLevelUniform->set(float(i)); 
    348             //if (mShader.valid()) mShader->set("g_MipmapLevel", i); 
    349  
    350342            // assign new viewport and fbo 
    351343            mViewport = mIOMipmapViewport[i]; 
    352344            mFBO = mIOMipmapFBO[i]; 
    353345     
    354             //printf("io-mipmap %s %d, (%dx%d) \n", getName().c_str(), i, (int)mViewport->width(), (int)mViewport->height()); 
    355      
    356346            // render the content 
    357347            doRender(i); 
     
    373363    mbDirtyOutputTextures = b; 
    374364    mbMipmappedIO = b; 
     365    if (b) enableMipmapGeneration(); 
    375366} 
    376367 
     
    386377        if (mipmapLevel < 0) mipmapLevel = 0; 
    387378        // update shaders manually, because they are do not updated from scene graph 
    388         /*if (mShaderMipmapLevelUniform.valid() && mShaderMipmapLevelUniform->getUpdateCallback()) 
    389         { 
    390             (*mShaderMipmapLevelUniform->getUpdateCallback())(mShaderMipmapLevelUniform.get(), new osgUtil::UpdateVisitor()); 
    391         }*/ 
    392         // setup shader values 
    393379        if (mShader.valid())  
    394380        { 
    395             mShader->set("g_TextureWidth", (float)(mViewport->x() + mViewport->width())); 
    396             mShader->set("g_TextureHeight",(float)(mViewport->y() + mViewport->height())); 
     381            mShader->set("g_ViewportWidth", (float)mViewport->width()); 
     382            mShader->set("g_ViewportHeight", (float)mViewport->height()); 
    397383            mShader->set("g_MipmapLevel", mipmapLevel); 
    398384            mShader->update(); 
     
    408394        mViewport->apply(*sState.getState()); 
    409395 
    410         // bind all input texture 
    411         TextureMap::const_iterator it = mInputTex.begin(); 
    412         for (int unit=0; it != mInputTex.end(); it++, unit++) 
    413         { 
    414             sState.getState()->applyTextureMode(unit, it->second->getTextureTarget(), true); 
    415             sState.getState()->applyTextureAttribute(unit, it->second.get()); 
    416         } 
    417  
    418         #if 0 
    419         if (mShader.valid()) 
    420             printf("render: %s - %s (level=%d, %dx%d)\n", getName().c_str(), mShader->getName().c_str(), mipmapLevel, int(mViewport->x() + mViewport->width()), int(mViewport->y() + mViewport->height())); 
    421         else 
    422             printf("render: %s (level=%d, %dx%d)\n", getName().c_str(),mipmapLevel, int(mViewport->x() + mViewport->width()), int(mViewport->y() + mViewport->height())); 
    423         #endif 
    424          
    425396        // render the content of the input texture into the frame buffer 
    426397        if (useBlendMode() && getOfflineMode() == false) 
  • trunk/src/osgPPU/PostProcess.cpp

    r19 r20  
    350350            printf("\t vp (ref %d): %d %d %d %d\n", (*it)->getInputTextureIndexForViewportReference(), (int)(*it)->getViewport()->x(), (int)(*it)->getViewport()->y(),(int)(*it)->getViewport()->width(), (int)(*it)->getViewport()->height()); 
    351351            printf("\t alpha: %f (%f %f)\n", (*it)->getCurrentBlendValue(), (*it)->getStartBlendValue(), (*it)->getEndBlendValue()); 
    352             printf("\t time: %f-%f\n", (*it)->getStartTime(), (*it)->getExpireTime());//, Engine::sClock()->getTime()); 
     352            printf("\t time: %f-%f\n", (*it)->getStartBlendTime(), (*it)->getEndBlendTime());//, Engine::sClock()->getTime()); 
    353353            printf("\t shader: %p\n", (*it)->getShader()); 
    354354 
     
    375375                        { 
    376376                osg::Texture* tex = (*it)->getInputTexture(i); 
    377                 printf(" %p ", tex); 
    378                 if (tex) printf("(%dx%d)", tex->getTextureWidth(), tex->getTextureHeight()); 
    379             } 
     377                printf(" %p", tex); 
     378                if (tex) 
     379                { 
     380                    if ((*it)->getStateSet()->getTextureAttribute(i, osg::StateAttribute::TEXTURE)) 
     381                        printf("-attr"); 
     382                    printf(" (%dx%d), ", tex->getTextureWidth(), tex->getTextureHeight()); 
     383                } 
     384            } 
     385 
    380386                        printf("\n\t output: "); 
    381387                        for (unsigned int i=0; i < (*it)->getOutputTextureMap().size(); i++) 
  • trunk/src/osgPPU/PostProcessUnit.cpp

    r19 r20  
    5050    // we do steup defaults 
    5151    setStartBlendTime(0); 
    52     setExpireBlendTime(0); 
     52    setEndBlendTime(0); 
    5353    setStartBlendValue(1); 
    5454    setEndBlendValue(1); 
     
    7777             
    7878    // remove colors form geometry 
    79     mScreenQuadColor = new osg::Vec4Array(1); 
    80     (*mScreenQuadColor)[0].set(1.0f,1.0f,1.0,1.0f); 
    81     sScreenQuad->setColorArray(NULL); 
     79    osg::Vec4Array* screenQuadColor = new osg::Vec4Array(1); 
     80    (*screenQuadColor)[0].set(1.0f,1.0f,1.0,1.0f); 
     81    sScreenQuad->setColorArray(screenQuadColor); 
    8282    sScreenQuad->setColorBinding(osg::Geometry::BIND_OFF); 
    8383 
     
    9898     
    9999    // setup per default local state equal to the parent state  
    100     sState.setState(mParent->getState()); 
     100    if (mParent.valid()) 
     101        sState.setState(mParent->getState()); 
    101102 
    102103    // setup uniform variable 
     
    134135    mbDirtyOutputTextures(ppu.mbDirtyOutputTextures), 
    135136    mbDirtyShader(ppu.mbDirtyShader), 
    136     mScreenQuadColor(ppu.mScreenQuadColor), 
    137137    mbOfflinePPU(ppu.mbOfflinePPU), 
    138138    mOutputInternalFormat(ppu.mOutputInternalFormat), 
     
    345345 
    346346        // check if input textures are dirty 
    347         if (mbDirtyInputTextures) 
     347        if (mbDirtyInputTextures || mbDirtyShader) 
    348348    { 
    349349        // reassign them 
     
    424424         
    425425        // if we get 0 as expire time, so the factor is the start value  
    426         if (getExpireBlendTime() < 0.0001) 
     426        if (getEndBlendTime() < 0.0001) 
    427427            factor = 0; 
    428428        else 
    429             factor = (mTime - getStartBlendTime()) / (getExpireBlendTime() - getStartBlendTime()); 
     429            factor = (mTime - getStartBlendTime()) / (getEndBlendTime() - getStartBlendTime()); 
    430430         
    431431        // compute blend value for the ppu 
    432432        float alpha = getStartBlendValue()*(1-factor) + factor*getEndBlendValue(); 
    433         if (alpha > 1.0 ) { alpha = 1.0; setExpireBlendTime(0); setStartBlendValue(1.0); } 
    434         if (alpha < 0.0 ) { alpha = 0.0; setExpireBlendTime(0); setStartBlendValue(0.0); } 
     433        if (alpha > 1.0 ) { alpha = 1.0; setEndBlendTime(0); setStartBlendValue(1.0); } 
     434        if (alpha < 0.0 ) { alpha = 0.0; setEndBlendTime(0); setStartBlendValue(0.0); } 
    435435         
    436436        // setup new alpha value  
     
    626626{ 
    627627    // if viewport is valid and we have to ignore new settings 
    628     if (mViewport.valid() && getInputTextureIndexForViewportReference() >=0) 
     628    if ((mViewport.valid() && getInputTextureIndexForViewportReference() >=0) 
     629        || vp == NULL) 
    629630        return; 
    630631 
  • trunk/src/osgPPU/Shader.cpp

    r13 r20  
    183183        mUniforms[name] = osg::StateSet::RefUniformPair(param, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED); 
    184184        onAddUniform(param); 
     185        //printf("%s add uniform %s\n", getName().c_str(), param->getName().c_str()); 
    185186    } 
    186187} 
     
    345346    // check whenever such an uniform already exists, if not so add it 
    346347    if (!isUniformExists(name)) add(name, osg::Uniform::INT, 1); 
    347     else{ 
     348    /*else{ 
    348349        // non valid texture, so remove it 
    349         if (!t) 
     350        if (t == NULL) 
    350351        { 
    351352            TexUnitDb::iterator it = mTexUnits.find(name); 
     
    353354            return false; 
    354355        } 
    355     } 
     356    }*/ 
    356357 
    357358    // check if index is valid 
     
    393394    // texture boundings are dirty now     
    394395    mDirtyBoundings = true; 
     396 
     397    //printf("%s bind %s-%d\n", getName().c_str(), name.c_str(), unit); 
    395398     
    396399    // just set value if predefined 
    397     if (unit >= 0) set(index, name, (int)unit); 
     400    if (unit >= 0) 
     401    { 
     402        set(index, name, (int)unit); 
     403    } 
    398404 
    399405    // inform derived classes  about this  
     
    537543     
    538544    // remove all previous texture attributes 
    539     for (int i=0; i < mMaxTextureUnits; i++) 
    540     { 
    541         ss->removeTextureAttribute(i, osg::StateAttribute::TEXTURE); 
    542     } 
     545    //for (int i=0; i < mMaxTextureUnits; i++) 
     546    //{ 
     547    //    ss->removeTextureAttribute(i, osg::StateAttribute::TEXTURE); 
     548    //} 
    543549     
    544550    #if DEBUG_SH     
Note: See TracChangeset for help on using the changeset viewer.