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 

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 6:06 pm    Post subject:
Help on multitexturing..
Reply with 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!
)

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


Joined: 18 Mar 2009
Posts: 11758

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

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
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 810

PostPosted: Fri Apr 20, 2018 9:16 am    Post subject:
Help on multitexturing..
Reply with quote

Hi Marlin,


Re-phrasing Roberts advice:
<code>
osg::Uniform* sampler = new osg::Uniform(osg::Uniform::SAMPLER_2D,
"NameOfTheSamplerInGLSL");
sampler->set(0); //assign unit
ss->addUniform(sampler);
ss->setTextureAttribute(0/*unit*/, texture0 ,osg::StateAttribute:ON );

osg::Uniform* sampler_1 = new osg::Uniform(osg::Uniform::SAMPLER_2D,
"NameOfTheSamplerInGLSL_1");
sampler->set(1); //assign unit
ss->addUniform(sampler);
ss->setTextureAttribute(1/*unit*/, texture1 ,osg::StateAttribute:ON );
</code>
This works fine with two sampler2D objects in GLSL.


HTH & Cheers
Sebastian

Am 19.04.2018 um 20:06 schrieb Rowley, Marlin R:
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:

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

cid:

/Missiles and Fire Control/

972-603-1931 (office)

214-926-0622 (mobile)

<mailto:>







------------------
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: 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
No new posts EXTERNAL: Re: EXTERNAL: Re: Help on m... Rowley, Marlin R General 2 Thu Apr 19, 2018 8:25 pm View latest post
No new posts EXTERNAL: Re: Help on multitexturing.. Rowley, Marlin R General 1 Thu Apr 19, 2018 7:30 pm View latest post
No new posts common conventions for multitexturing... cbuchner1 General 5 Wed Jan 28, 2015 10:46 am 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