Hi Alejandro,
What is the purpouse of the second parameter (int) of the Uniform
constructor.
second parameter represent the texture unit which your texture can be used
from this unit in shader.
osg::Uniform* terrainTextureSampler2 = new osg::Uniform(EarthNight, 1);
osg::Uniform* terrainTextureSampler3 = new osg::Uniform(EarthCloudGloss,
1);
You have used same texture unit for 2 texture so your last initilazed
texture on unit 1 active. I mean, EarthCloudGloss active on unit 1. so you
should texture EarthCloudGloss to the unit 2.
Hope this helps.
Regards.
2008/11/18 Alejandro Aguilar Sierra [EMAIL PROTECTED]
Hello:
I built a terrain with two textures to test osgmultitexturecontrol. It
fade between both textures. Now, for the effect I am looking for in
another scene, the use of shaders would be convenient. I want to
reproduce in osg the example from chapter 10.3 of the orange book
(Multitexturing Example). The shaders are available in the book's site
http://3dshaders.com/home/index.php?page=shop.product_detailsflypage=shop.flypageproduct_id=12category_id=1manufacturer_id=0option=com_virtuemartItemid=3
The reason this shader is suitable is that it uses a daytime or a
nightime image of Earth, and uses on the sphere the corresponding
texture to the position of the sun. Actually I want to control not two
but four areas on the sphere (also the polar circles). Perhaps this
can be done with subtextures, but the shaders seems to be good for the
job.
The problem, as usual, is the lack of documentation. Currently I am
able to texture the daytime image and the clouds cover, but not the
nightime image. What is the purpouse of the second parameter (int) of
the Uniform constructor. A reference for the texture unit or something
else?
osg::Uniform* terrainTextureSampler = new osg::Uniform(EarthDay, 0);
This is the first time I use shaders with osg, so please be patient. I
am pasting the shaders and texture functions. I will appreciate any
hint.
Best regards,
-- A.
static void shaders(osg::StateSet* stateset)
{
osg::Vec3 LightPosition = osg::Vec3( 0.0f, 1.0f, 0.0f );
// uniform sampler2D EarthTexture;
osg::Uniform* LightPositionUniform = new
osg::Uniform(LightPosition, LightPosition);
stateset-addUniform(LightPositionUniform);
osg::Uniform* terrainTextureSampler = new osg::Uniform(EarthDay, 0);
stateset-addUniform(terrainTextureSampler);
osg::Uniform* terrainTextureSampler2 = new osg::Uniform(EarthNight, 1);
stateset-addUniform(terrainTextureSampler2);
osg::Uniform* terrainTextureSampler3 = new osg::Uniform(EarthCloudGloss,
1);
stateset-addUniform(terrainTextureSampler3);
osg::Program* program = new osg::Program;
stateset-setAttribute(program);
program-addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX,
CH10-earth-3tex.vert));
program-addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
CH10-earth-3tex.frag));
}
void Estaciones::textura()
{
estado = geonodo-getOrCreateStateSet();
osg::ref_ptrosg::Image imagen1 = osgDB::readImageFile(dia.jpg);
osg::ref_ptrosg::Texture2D textura1(new osg::Texture2D);
textura1-setImage(imagen1.get());
estado-setTextureAttributeAndModes(0,
textura1.get(),osg::StateAttribute::ON);
osg::ref_ptrosg::Image imagen2 = osgDB::readImageFile(noche.jpg);
osg::ref_ptrosg::Texture2D textura2(new osg::Texture2D);
textura2-setImage(imagen2.get());
estado-setTextureAttributeAndModes(1,
textura2.get(),osg::StateAttribute::ON);
osg::ref_ptrosg::Image imagen3 = osgDB::readImageFile(nubes.jpg);
osg::ref_ptrosg::Texture2D textura3(new osg::Texture2D);
textura2-setImage(imagen3.get());
estado-setTextureAttributeAndModes(2,
textura3.get(),osg::StateAttribute::ON);
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
Ümit Uzun
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org