Hi Ümit,

I am using PerPixel lighting on my some model which has created with Blender. My model has lots of textures on it.

Do you mean that it has lots of textures to be applied to the same primitives (i.e. it needs lots of texture units) or just that it uses lots of texture *files* but only one (or a few) per primitive?

If the first case, then you need to figure out how many texture units your target video cards can handle (generally even older cards can handle 8 or 16) and make sure your shader is set up correctly to render the textures from your model in the same way as the model... For example sometimes unit 0 is the diffuse color texture, unit 1 might be a normal map, unit 2 a specular (gloss) map, unit 3 a lightmap, etc. You can set up a convention like that and then code your shader to take that into account.

And my question is, do I have to send all textures in uniform variable to shader?

When you load the model, the state will have been set up so that your textures are applied for the appropriate node on the appropriate texture unit (depending on what the Blender exporter supports of course). All you need to do is set up a uniform sampler2D with a name and the value corresponding to the texture unit you want to use, and then in the shader, you use that sampler to do the texture lookup, i.e.

sampler2D samplerName;

void main(void)
{
  // ...
  vec4 textureColor = texture2D(samplerName, gl_TexCoord[0].st);
  // ...
}

That makes all think to complex, doesn't that? I have try to send only one texture to shader and saw that it can texture all of texture on my model instead of only send one.

I don't understand what you're trying to say here.

Then I realize that declared "uniform sampler2 sampleTexture" definition doesn't hold the related texture file. It only hold texture unit, I mean 0,1 or 7.

See above, you don't need the texture itself in the shader, since the OpenGL state will have been set so that texture unit n holds the texture. Your sampler uniform and declaration in the shader associate a name to that unit number n, and then you use that name in your shader.

My question is what is the standart shadering operation when we have canned model? Should we send texture's to shader or what else?

That's already done, the loader will set up the state so that the texture is in the appropriate node's stateset. All you need to do is add a uniform. For example, if your base color texture is always in unit 0 (that's generally the case) then you can do

osg::Uniform* sampler = new osg::Uniform(osg::Uniform::SAMPLER_2D, "baseTexture");
  sampler->set(0);
  modelRoot->getOrCreateStateSet()->addUniform(sampler);

And sending texture is meaningless, because if we have ive or another texture integrated model what should we do this time? We haven't related texture separately? This time what should we send?

Once again, the actual state is set up by the loader, so you don't need to send anything. Just set up the uniforms.

Uniforms are inherited from root to children like any state, so if you always use texture unit 0 for the base texture for example, you can just set a single uniform on the root as above, and set the shader on the root as well (or have one shader for your whole scene, or however you want to manage it). If you need more control (such as setting a uniform on given nodes to control their appearance) then you can make a visitor that will go set uniforms on the right children of your model.

Hope that clears things up,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [email protected]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to