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: 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 8:25 pm    Post subject:
EXTERNAL: Re: EXTERNAL: Re: Help on multitexturing..
Reply with quote

Robert,

Changing the sampler_2d to an (int) doesn’t seem to fix the problem. I still get a black texture in the scene.

Here is my updated code:

mGroupState->getOrCreateUniform("MySecondSampler", osg::Uniform::SAMPLER_2D)->set(BASE_TEXTURE_UNIT + 1);
mGroupState->setTextureAttributeAndModes(BASE_TEXTURE_UNIT + 1, mSecondColor, osg::StateAttribute::OVERRIDE);

I want to write this second texture to unit 2. (base_texture_unit = 1 + 1). I still get a black object.

----------------------------------------
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 Rowley, Marlin R (US)
Sent: Thursday, April 19, 2018 2:30 PM
To: OpenSceneGraph Users <>
Subject: EXTERNAL: Re: EXTERNAL: Re: Help on multitexturing..



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: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)] On Behalf Of Robert Osfield
Sent: Thursday, April 19, 2018 2:05 PM
To: OpenSceneGraph Users < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
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: 11829

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

Hi Marlin,

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

Robert,
 
Changing the sampler_2d to an (int) doesn’t seem to fix the problem.  I still get a black texture in the scene.
 
Here is my updated code:



What still wrong I can't say as I know snippets of your code.



The best thing I can recommend is to start simple, write a small example program that just sets up a couple of textures and the uniforms and shaders for them.


Robert


 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Rowley, Marlin R
Guest





PostPosted: Mon Apr 23, 2018 4:29 pm    Post subject:
EXTERNAL: Re: EXTERNAL: Re: Help on multitexturing..
Reply with quote

Thanks Robert. I got it working and will do text only for code in the future.

-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: Friday, April 20, 2018 2:06 AM
To: OpenSceneGraph Users <>
Subject: EXTERNAL: Re: EXTERNAL: Re: Help on multitexturing..

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
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: 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
No new posts EXTERNAL: Re: Getting the combined ma... Rowley, Marlin R General 0 Tue May 08, 2018 3:25 pm View latest post
No new posts EXTERNAL: Re: EXTERNAL: Re: EXTERNAL:... Rowley, Marlin R General 0 Thu Apr 19, 2018 10:16 pm View latest post
No new posts EXTERNAL: Re: EXTERNAL: Re: EXTERNAL:... Rowley, Marlin R General 0 Thu Apr 19, 2018 8:54 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