[osg-users] Render To Texture attached Image do not support RGBA32 format, value clamped to 1!

Wojciech Lewandowski lewandowski at ai.com.pl
Thu Jul 3 02:52:10 PDT 2008


Hi Hesicong, 

You could try seting Image::internalTextureFormat to GL_RGBA32F_ARB. When you attach image to RTT camera its FBO Renderbuffer format is selected based on this parameter.  If your image had not set internalTextureFormat Render buffer should be standard 32bit RGBA. 

There was also a fix two days ago which preserved internalTextureFormat from being reset in Image::readPixels called at the end of RTT render to read FBO contents. So just to be safe I suggest you use OSG in latest SVN version.

Cheers,
Wojtek

  ----- Original Message ----- 
  From: hesicong2006 
  To: OpenSceneGraph Users 
  Sent: Thursday, July 03, 2008 10:05 AM
  Subject: Re: [osg-users] Render To Texture attached Image do not support RGBA32 format, value clamped to 1!


  I found out the tricky code!
  YOU MUST ATTACH the texture and your image~, see the code segment of osgmultiplerendertargets.cpp from line 343 to 360:

          for (int i=0; i<NUM_TEXTURES; i++) {
              camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i]);
          }
       
          // we can also read back any of the targets as an image, modify this image and push it back
          if (useImage) {
              // which texture to get the image from
              const int tex_to_get = 0;
              
              osg::Image* image = new osg::Image;
              if (useHDR) {
                  image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT);
              } else {
                  image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
              }

              // attach the image so its copied on each frame.
              camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0 + tex_to_get), image);

  That's OK!


  hesicong2006 wrote: 
    Hi, Delport:
        I tried your method, that's OK, I see the output. I'll check what's wrong with my code or if there's some tricky code I ignore. Thanks!

    J.P. Delport wrote: 
      Hi, 

      I have just edited osgmultiplerendertargets example and can confirm you can get values > 1. 

      In the example, search for e-12 and change to e12 in the shader. 

      Run with: 
      osgmultiplerendertargets --hdr --image. 

      You will see that it prints values > 1. 

      jp 


      hesicong2006 wrote: 

        Hi, Robert: 
            I'm now writing shader to compute world coordinate of the scene and save them as image. The value output by shader will exceed 1 and require float values, so I use GL_RGBA32F_ARB for RTT texture. Since I must save them to an image, I must allocate a Image and attach it to the texture. My texture setup code is : 

            osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D(); 

            osg::ref_ptr<osg::Image> image=new osg::Image; 
            image->allocateImage(1024,768 , 1, GL_RGBA, GL_FLOAT); 

            texture->setTextureSize(1024,768); 
            texture->setInternalFormat(GL_RGBA32F_ARB); 
            texture->setSourceFormat(GL_RGBA); 
            texture->setSourceType(GL_FLOAT); 
            texture->setResizeNonPowerOfTwoHint(false); 
            texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); 
            texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); 
            texture->setImage(0, image.get()); 


        And then I attach the image to camera: 

            camera=viewer->getCamera(); 
            camera->setGraphicsContext(gc.get()); 
            camera->setViewport(0,0,wWidth,wHeight); 
            camera->attach(osg::Camera::COLOR_BUFFER, texture->getImage()); 
            camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); 

        But after I ran the program and saved the image, I found out the shader output value which exceed 1 is clamped to 1! In order to check the problem, I wrote a small callback to check it: 

            class VoxlizationPreDrawCallback : public osg::Camera::DrawCallback 
            { 
            public: 
                virtual void operator () (osg::RenderInfo& ) const 
                { 
                    for(int y=0;y<768;y++) 
                    { 
                        for(int x=0;x<1024;x++) 
                        { 
                            float value=*(float*)imageToSave->data(x,y); 
                            if(value>1) 
                            { 
                                std::cout<<"x="<<x<<" y="<<y<<std::endl; 
                            } 
                        } 
                    } 
                } 

                osg::Image* imageToSave; 
            }; 

        But no value exceed 1. I changed the value>1 to value==1, it will give me a lot of values. 

        I also tried if my shader can't output values above 1, I changed the camera setting from 

                camera->attach(osg::Camera::COLOR_BUFFER, texture->getImage()); 
            to 
                camera->attach(osg::Camera::COLOR_BUFFER, texture->get()); 

        And I can see in GDebugger 4.2 frame buffer object, some values actually above 1. 
        So I guess the process of camera writing values to osg::Image does not support RGBA32 float format or it clamp the value to 1, float value should not clamp to 1, it buggy! 
        Please check it! Thanks! And I also attached my little code and a box model which size is (2*2*2) to help reproduce the problem. 

        Hesicong 
        2008-7-3 


        ------------------------------------------------------------------------ 

        _______________________________________________ 
        osg-users mailing list 
        osg-users at lists.openscenegraph.org 
        http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 





    __________ Information from ESET NOD32 Antivirus, version of virus signature database 3236 (20080702) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com

----------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



__________ Information from ESET NOD32 Antivirus, version of virus signature database 3236 (20080702) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

------------------------------------------------------------------------------


  _______________________________________________
  osg-users mailing list
  osg-users at lists.openscenegraph.org
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080703/1f378edc/attachment-0003.htm>


More information about the osg-users mailing list