OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Image containing floats


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
ivar
Newbie


Joined: 10 Oct 2017
Posts: 5

PostPosted: Thu Sep 20, 2018 9:18 am    Post subject:
Image containing floats
Reply with quote

Hi,

I'm trying to generate my own lookup table containing floats and store it in an image, and apply it to a texture to send it to the shader. I am having issues with getting the image to store floats though. Is there any way to do so, or am I trying something impossible?

cheers,
Ivar
Back to top
View user's profile Send private message
d_a_heitbrink (David Heitbrink)
User


Joined: 23 Sep 2013
Posts: 57

PostPosted: Thu Sep 20, 2018 9:07 pm    Post subject:
Reply with quote

yes this is doable. You need to set the internal format to something like: GL_RGBA32F

and the source type to float on your texture.

You might look at the OSG forest example, and its use of osg::TextureBuffer. Basically with the forest example, its doing instancing where the transforms are loaded into a texture, and the data is used in the vertex shader.
Back to top
View user's profile Send private message Send e-mail
ivar
Newbie


Joined: 10 Oct 2017
Posts: 5

PostPosted: Mon Sep 24, 2018 8:02 am    Post subject:
Reply with quote

Thanks David! I got it to work now.

Here my function creating a 2D texture from a 2-Dimensional vector, in case it's of any use to anyone.

Code:

osg::Texture2D* createTextureLUT2D(std::vector<std::vector<float> >& data)
{
   int rows = data.size();
   int cols = data[0].size();
   
   //create image containing one channel of float, we use the RED channel
   osg::Image* image = new osg::Image;
   image->allocateImage(cols, rows, 1, GL_RED, GL_FLOAT);
   image->setInternalTextureFormat(GL_R32F);   

   //set the data to the image; the image stores successive columns rather than succesive rows
   float* dataPtr = (float*)image->data();
   for (int b = 0; b < cols; b++)
      for (int a = 0; a < rows; a++)
         *dataPtr++  = data[a][b];

   //create the texture and set its image
   osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
   texture->setImage(image);
   texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
   texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);

   return texture.release();
}


cheers, Ivar
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Image from shader lucasamparo General 14 Thu Oct 03, 2019 5:46 pm View latest post
No new posts problem about reconstructing world co... swaggydong General 0 Sun Jun 23, 2019 8:26 am View latest post
No new posts remove mipmap data from osg::Image Trajce Nikolov NICK General 0 Tue May 28, 2019 2:40 pm View latest post
No new posts Write Image From texture Generated by... GarfieldPig General 1 Wed May 08, 2019 11:42 am View latest post
No new posts Image capture in memory icf80 General 12 Fri Apr 12, 2019 6:11 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP