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 

EXTERNAL: Re: Help on multitexturing..


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Rowley, Marlin R
Guest





PostPosted: Thu Apr 19, 2018 7:30 pm    Post subject:
EXTERNAL: Re: Help on multitexturing..
Reply with quote

I thought the sampler value was a pointer to a texture?

I set the texture unit to 1 because we’ll need the base texture unit 0 later on. My goal is to turn on up to 10 texture units and blend them all together.

To be more clear, he is some more code:

mGroupState = mBoundGeometry->getOrCreateStateSet();
mGroupState->getOrCreateUniform("BaseTexSampler", osg::Uniform::SAMPLER_2D)->set(mBaseColor.get());
mGroupState->getOrCreateUniform("BaseWeight", osg::Uniform::FLOAT)->set(mBaseWeight);
mGroupState->setTextureAttributeAndModes(BASE_TEXTURE_UNIT, mBaseColor, osg::StateAttribute:ShockedN);

This sets the base texture unit 1 to be bound to the mBaseColor (which is a osg::ref_ptr<osg::Texture2D>) created before the function call.

Then, I do this right afterwards:

if (mNumLayers)
{
int indx = 0;
osg::ref_ptr<osg::Texture2D> tex = mTextureMap[indx];// iter->second;
mGroupState->getOrCreateUniform("TexLayerSampler0", osg::Uniform::SAMPLER_2D)->set(tex.get());
mGroupState->setTextureAttributeAndModes(BASE_TEXTURE_UNIT + 1, tex, osg::StateAttribute::OVERRIDE);
}

Here I get the texture from a std::map. And then I set the sampler to be bound to the texture. I then bind the texture unit 2 to the texture.

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

From: osg-users [mailto:] On Behalf Of Robert Osfield
Sent: Thursday, April 19, 2018 2:05 PM
To: OpenSceneGraph Users <>
Subject: EXTERNAL: Re: Help on multitexturing..

Hi Marlin,

The sampler value should be an int, so you shouldn't pass a texture pointer to your setting of the TexLayerSampler0 second sampler. Perhaps this was just a copy and paste error.

As a general note, normally one would assign a base texture on texture unit 0 rather than 1.



Robert.




On 19 April 2018 at 19:06, Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:

Hello,

I’ve been wracking my brain all day on trying to figure out how to do this with no clear examples found online.

I have this set of calls in my C++:

mGroupState = mBoundGeometry->getOrCreateStateSet();
mGroupState->getOrCreateUniform("BaseTexSampler", osg::Uniform::SAMPLER_2D)->set(mBaseColor);
mGroupState->getOrCreateUniform("BaseWeight", osg::Uniform::FLOAT)->set(mBaseWeight);
mGroupState->setTextureAttributeAndModes(BASE_TEXTURE_UNIT, mBaseColor, osg::StateAttribute:ShockedN);

I’ve bound this base texture to texture unit (BASE_TEXTURE_UNIT = 1).

Later in the code, I have this in another function if I create another layer with another texture:
Quote:
mGroupState->getOrCreateUniform("TexLayerSampler0",osg::Uniform::SAMPLER_2D)->set(tex); mGroupState->setTextureAttribute(BASE_TEXTURE_UNIT+1,tex,osg::StateAttribute:ShockedN);


Where I’ve created a second texture and want it to reside in texture unit 2.

However, in my shader code when indexing the TexLayerSampler0, I only get base texture.

finalColor = texture(TexLayerSampler0, LayeredTexCoords[0].st);

Which is wrong. I’m stil trying to figure out OpenGL and how it works along with OSG so sorry for the inexperience.

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12024

PostPosted: Fri Apr 20, 2018 7:05 am    Post subject:
EXTERNAL: Re: Help on multitexturing..
Reply with quote

On 19 April 2018 at 20:30, Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:

I thought the sampler value was a pointer to a texture?




Where did you get that idea?  None of the OSG example attempt this.  When using OpenGL you pass the sampler uniforms as int, when it comes to OpenGL the OSG is just a lightweight wrapper around it. 




Quote:

 
I set the texture unit to 1 because we’ll need the base texture unit 0 later on.  My goal is to turn on up to 10 texture units and blend them all together.
 
To be more clear, he is some more code:
 
mGroupState = mBoundGeometry->getOrCreateStateSet();
      mGroupState->getOrCreateUniform("BaseTexSampler", osg::Uniform::SAMPLER_2D)->set(mBaseColor.get());
      mGroupState->getOrCreateUniform("BaseWeight", osg::Uniform::FLOAT)->set(mBaseWeight);
      mGroupState->setTextureAttributeAndModes(BASE_TEXTURE_UNIT, mBaseColor, osg::StateAttribute:ShockedN);
 
This sets the base texture unit 1 to be bound to the mBaseColor (which is a osg::ref_ptr<osg::Texture2D>) created before the function call.




I tell you want the problem is and you copy and paste more code with that exact problem in.  Pass in an int value for the sampler texture unit, so BASE_TEXTURE_UNIT, not the texture pointer.


For future reference, could you refrrame from using this black and white blocks, it's painful to look at.  Just putting everything in plain texture but using indentation for code is perfectly fine.


Robert.

------------------
Post generated by Mail2Forum
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 EXTERNAL: Re: LookAt() function param... Rowley, Marlin R General 0 Mon Aug 13, 2018 2:59 pm View latest post
No new posts EXTERNAL: Re: World space normal. Rowley, Marlin R General 1 Wed Jul 11, 2018 4:30 pm View latest post
No new posts EXTERNAL: Announcement: VulkanSceneGr... Rowley, Marlin R General 0 Mon Jun 04, 2018 3:00 pm View latest post
No new posts EXTERNAL: Re: EXTERNAL: Re: FBO setup... Rowley, Marlin R General 0 Thu May 10, 2018 12:56 pm View latest post
No new posts EXTERNAL: Re: FBO setup not working.. Rowley, Marlin R General 1 Thu May 10, 2018 12:49 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