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

Robert,

I’ve investigated further and believe I’ve found the problem but not sure how to fix it.

I have a constructor for a layered texture class where I pass it an image as the base layer. I set the texture mode and create a texture in this constructor for the base class. I also assign BASE_TEXTURE_UNIT to the sampler2D as an id to bind the texture to it for the shader (thanks for this..).

I run a function called updateShaders() (which I’ve sent snippets of code for) at the bottom of my constructor class. If I access this base sampler texture in the shader, I get what I expect on the geometry.

Now, when I call a function to create a layer for this layered class (i.e. createLayer(some image, weight, etc..)) from the application, I create a texture from this function and I run the updateShaders() function again binding the BASE_TEXTURE_UNIT + 1 to my second sampler node and trying to bind it to the texture I just created. THIS is what’s NOT working properly. When I run GPUPerf debugger, I see that the texture unit is assigned the correct #2, but the BoundID isn’t equal to the unit number. So when I sample from the texture in the shader, it’s just black because it can’t see this new binding (assume no blending in the shader just an overwrite).

To test this, I reconfigured my constructor to take 2 images instead of 1 image for the base and I forego the call to createLayer() in my application. Sure enough, the binding is properly set. Am I missing some kind of callback that should force a rebind when I call updateShaders()?

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



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: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)] On Behalf Of Rowley, Marlin R (US)
Sent: Thursday, April 19, 2018 2:30 PM
To: OpenSceneGraph Users < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
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
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: Value of a variable in... Rowley, Marlin R General 3 Fri Sep 28, 2018 1:39 pm View latest post
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


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