Robert, This problem has been solved.
Answer: 1. Passing strings to set a uniform name will NOT automatically convert numbers to strings (i.e. getOrCreateUniform(“some_string” + 4, … ) will not work. It must be converted first. (i.e. getOrCreateUniform(“some_string” + std::to_string(4), … ) 2. You can NOT index an array when setting a uniform’s value (i.e. uniform->set(num_array[0])).. It needs to be copied first (i.e. int x = num_array[0]; uniform->set(x); Hope this helps others who are getting their feet wet with OSG. Cheers, -M ---------------------------------------- Marlin Rowley Software Engineer, Staff [cid:image002.jpg@01D39374.DEC5A2E0] Missiles and Fire Control 972-603-1931 (office) 214-926-0622 (mobile) marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com> From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Rowley, Marlin R (US) Sent: Thursday, April 19, 2018 3:54 PM To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org> Subject: EXTERNAL: Re: [osg-users] EXTERNAL: Re: EXTERNAL: Re: EXTERNAL: Re: Help on multitexturing.. 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 [cid:image002.jpg@01D39374.DEC5A2E0] Missiles and Fire Control 972-603-1931 (office) 214-926-0622 (mobile) marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com> From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Rowley, Marlin R (US) Sent: Thursday, April 19, 2018 3:25 PM To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org<mailto:osg-users@lists.openscenegraph.org>> Subject: EXTERNAL: Re: [osg-users] 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 [cid:image002.jpg@01D39374.DEC5A2E0] Missiles and Fire Control 972-603-1931 (office) 214-926-0622 (mobile) marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com> From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Rowley, Marlin R (US) Sent: Thursday, April 19, 2018 2:30 PM To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org<mailto:osg-users@lists.openscenegraph.org>> Subject: EXTERNAL: Re: [osg-users] 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::ON); 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 [cid:image002.jpg@01D39374.DEC5A2E0] Missiles and Fire Control 972-603-1931 (office) 214-926-0622 (mobile) marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com> From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield Sent: Thursday, April 19, 2018 2:05 PM To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org<mailto:osg-users@lists.openscenegraph.org>> Subject: EXTERNAL: Re: [osg-users] 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 <marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com>> wrote: 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::ON); 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::ON); 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:image002.jpg@01D39374.DEC5A2E0] Missiles and Fire Control 972-603-1931 (office) 214-926-0622 (mobile) marlin.r.row...@lmco.com<mailto:marlin.r.row...@lmco.com> _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org<mailto:osg-users@lists.openscenegraph.org> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org