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 

using 3Ds Model in osgFX::BumpMapping and the Texture UV Coords for diffuse are not loaded


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Build system [build]
View previous topic :: View next topic  
Author Message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Thu Nov 05, 2015 8:46 pm    Post subject:
using 3Ds Model in osgFX::BumpMapping and the Texture UV Coords for diffuse are not loaded
Reply with quote

Hi all,

I tried to use the example from the link in the next posts (I need to have at least two posts to send Links) to generate a bumpmap via a normal map texture.

What I did is, that I have added a Node to the osgFX::BumpMapping and the node contains the 3Ds model. When I set up the texture state, the bumpmap texture coordinates are loaded correctly but there aren't loaded any diffuse texture coordinates and the diffuse texture on the model is infinitely streched. In 3D studio max I set for the 3ds model an uvMap. My c++ Code looks like this:

Quote:
#include <osg/Group>
#include <osg/Image>
#include <osg/MatrixTransform>
#include <osg/Node>
#include <osg/StateSet>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>

#include <osgFX/BumpMapping>
#include <osg/TexMat>

int main(int argc, char **argv) {

//TODO UV Map for diffuse texture

osg::Group* bumpRoot = new osg::Group();

osgFX::BumpMapping *bump = new osgFX::BumpMapping();
osg::Node* bumpModel = new osg::Node();

bumpModel = osgDB::readNodeFile("Models/model_scifi_roadway_00straight.3ds");
bump->addChild(bumpModel);

osg::Texture2D *normal = new osg::Texture2D();
osg::Texture2D *diffuse = new osg::Texture2D();

const char* normal_texture = "Textures/Normal/texture_scifi_roadway_00normal.png";
const char* diffuse_texture = "Textures/texture_scifi_roadway_00.png";

osg::Image *normal_image = osgDB::readImageFile( normal_texture );
osg::Image *diffuse_image = osgDB::readImageFile( diffuse_texture );

normal->setImage( normal_image );
normal->setDataVariance(osg::Object::DYNAMIC);
normal->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
normal->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
normal->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
normal->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
normal->setMaxAnisotropy(8);

diffuse->setImage( diffuse_image );
diffuse->setDataVariance(osg::Object::DYNAMIC);
diffuse->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
diffuse->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
diffuse->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
diffuse->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
diffuse->setMaxAnisotropy(8);

osg::TexMat* texMat = new osg::TexMat;
osg::Vec3d texPosition(0.0, 0.0, 0.0);
osg::Vec3d texAngles(0.0, 0.0, 0.0);
osg::Vec3d texScale(1.0, 1.0, 1.0);
osg::Matrixd texRot;
texRot.makeRotate(
osg::DegreesToRadians(texAngles.x()), osg::Vec3(1, 0, 0),
osg::DegreesToRadians(texAngles.y()), osg::Vec3(0, 1, 0),
osg::DegreesToRadians(texAngles.z()), osg::Vec3(0, 0, 1));
texMat->setMatrix(osg::Matrix::scale(texScale)*texRot*osg::Matrix::translate(texPosition));

osg::StateSet *state = new osg::StateSet();
state = bumpModel->getOrCreateStateSet();
state->setTextureAttributeAndModes( 0, diffuse, osg::StateAttribute::ON );
state->setTextureAttributeAndModes(0, texMat, osg::StateAttribute::ON);
state->setTextureAttributeAndModes( 1, normal, osg::StateAttribute::ON );
state->setTextureAttributeAndModes(1, texMat, osg::StateAttribute::ON);
state->setGlobalDefaults();
state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
state->setMode(GL_BLEND, osg::StateAttribute::ON);
state->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

bump->setStateSet(state);

bump->setEnabled(true);
bump->setLightNumber(0);
bump->setOverrideNormalMapTexture(normal);
bump->setOverrideDiffuseTexture(diffuse);
bump->prepareChildren();
//bump->setUpDemo();

osg::MatrixTransform *MT = new osg::MatrixTransform();
MT->addChild(bump);
bumpRoot->addChild(MT);

osgViewer::Viewer bumpViewer;
bumpViewer.setSceneData(bumpRoot);
bumpViewer.setCameraManipulator(new osgGA::TrackballManipulator());
bumpViewer.realize();

while (!bumpViewer.done()) {
bumpViewer.frame();
}

}



I hope anybody can help.

Thank you!

Cheers,
Tobias
Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Thu Nov 05, 2015 8:47 pm    Post subject:
Reply with quote

Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Tue Nov 10, 2015 12:18 am    Post subject:
Reply with quote

In addition, when bump->setEnabled(true); the textureMatrix has no effekt anymore. How can I use the textureMatrix in this case?
Back to top
View user's profile Send private message
scrawl
Appreciator


Joined: 14 Dec 2014
Posts: 175

PostPosted: Tue Nov 10, 2015 1:25 am    Post subject:
Reply with quote

Hi Tobias,

The texture matrix is a fixed function state that may not have an effect when a shader is used. To get the desired effect, the shader code needs to get the texture matrix via gl_TextureMatrix built in variable and then multiply the texture coordinates with it. I presume the osgFX::BumpMapping shader is not doing this.

The osgFX::BumpMapping shader appears to be written in ARB assembly rather than GLSL, so it's a bit difficult to modify it. You might be better off writing your own shader in GLSL.
Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Thu Nov 12, 2015 12:12 am    Post subject:
Reply with quote

I never thought, that I can say this. But I resolved my problem. Thank you Scrawl for your tip using an own shader. I used the shaders from http://fabiensanglard.net/bumpMapping/index.php (Vertex shader + Fragment shader) and modified it in addition from http://forum.openscenegraph.org/viewtopic.php?p=38982#38982 and this works fine also with a TexMat Smile
Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Thu Nov 12, 2015 1:20 am    Post subject:
Reply with quote

For everyone who wants to use a bump map shader in osg you can find a working code in the lines below.

The source file:
Quote:

#include <osg/Group>
#include <osg/Image>
#include <osg/MatrixTransform>
#include <osg/Node>
#include <osg/StateSet>
#include <osg/TexMat>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>

#include <osg/Program>
#include <osg/Shader>
#include <osg/Uniform>
#include <osgDB/FileUtils>

int main(int argc, char **argv) {

// Root
osg::Group* bumpRoot = new osg::Group();

// Model with bump mapping
osg::Geometry* bumpModel = new osg::Geometry();
bumpModel = (osg::Geometry*) osgDB::readNodeFile("Models/model_scifi_roadway_00straight.3ds");

// Model stateset to activate bump mapping shader
osg::StateSet* bumpState = new osg::StateSet();
bumpState = bumpModel->getOrCreateStateSet();

// Stateset shader program
osg::Program* bumpMapProgramObject = new osg::Program;

// Set shader
osg::Shader* bumpVertexObject = new osg::Shader(osg::Shader::VERTEX);
osg::Shader* bumpFragmentObject = new osg::Shader(osg::Shader::FRAGMENT);

std::string bumpVertexFileName = osgDB::findDataFile("Shading/newbump.vert");
bumpVertexObject->loadShaderSourceFromFile(bumpVertexFileName.c_str());
std::string bumpFragmentFileName = osgDB::findDataFile("Shading/newbump.frag");
bumpFragmentObject->loadShaderSourceFromFile(bumpFragmentFileName.c_str());

bumpMapProgramObject->addShader(bumpVertexObject);
bumpMapProgramObject->addShader(bumpFragmentObject);

// Set textures
osg::Texture2D *normal = new osg::Texture2D();
osg::Texture2D *diffuse = new osg::Texture2D();

const char* normal_texture = "Textures/Normal/texture_scifi_roadway_00normal.png";
const char* diffuse_texture = "Textures/texture_scifi_roadway_00.png";

osg::Image *normal_image = osgDB::readImageFile(normal_texture);
osg::Image *diffuse_image = osgDB::readImageFile(diffuse_texture);

normal->setImage(normal_image);
normal->setDataVariance(osg::Object::DYNAMIC);
normal->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
normal->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
normal->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
normal->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
normal->setResizeNonPowerOfTwoHint(false);
normal->setMaxAnisotropy(8.0f);

diffuse->setImage(diffuse_image);
diffuse->setDataVariance(osg::Object::DYNAMIC);
diffuse->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
diffuse->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
diffuse->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
diffuse->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
diffuse->setResizeNonPowerOfTwoHint(false);
diffuse->setMaxAnisotropy(8.0f);

// Set texture matrix
osg::TexMat* texMat = new osg::TexMat;
osg::Vec3d texPosition(0.0, 0.0, 0.0);
osg::Vec3d texAngles(0.0, 0.0, 0.0);
osg::Vec3d texScale(2.0, 2.0, 2.0);
osg::Matrixd texRot;
texRot.makeRotate(
osg::DegreesToRadians(texAngles.x()), osg::Vec3(1, 0, 0),
osg::DegreesToRadians(texAngles.y()), osg::Vec3(0, 1, 0),
osg::DegreesToRadians(texAngles.z()), osg::Vec3(0, 0, 1));
texMat->setMatrix(osg::Matrix::scale(texScale)*texRot*osg::Matrix::translate(texPosition));

const int TEXTURE_UNIT_BUMP = 1;
const int TEXTURE_UNIT_DIFFUSE = 0;

// Add bump map to model stateset
// normalTexture in newbump.frag as uniform sampler2D normalTexture
// diffuseTexture in newbump.frag as uniform sampler2D diffuseTexture
bumpState->addUniform(new osg::Uniform("normalTexture", TEXTURE_UNIT_BUMP));
bumpState->addUniform(new osg::Uniform("diffuseTexture", TEXTURE_UNIT_DIFFUSE));
bumpState->setAttributeAndModes(bumpMapProgramObject, osg::StateAttribute:ShockedN);
// State set options
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFFUSE, diffuse, osg::StateAttribute:ShockedN);
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFFUSE, texMat, osg::StateAttribute:ShockedN);
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_BUMP, normal, osg::StateAttribute:ShockedN);
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_BUMP, texMat, osg::StateAttribute:ShockedN);
//bumpState->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute:ShockedN);
//bumpState->setTextureMode(1, GL_TEXTURE_2D, osg::StateAttribute:ShockedN);
//bumpState->setGlobalDefaults();
//bumpState->setMode(GL_LIGHTING, osg::StateAttribute:ShockedN);
//bumpState->setMode(GL_BLEND, osg::StateAttribute:ShockedN);
bumpState->setMode(GL_CULL_FACE, osg::StateAttribute:ShockedN);
//bumpState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

// Add stateset to model
bumpModel->setStateSet(bumpState);

// Set model matrix transform
osg::MatrixTransform *MT = new osg::MatrixTransform();
MT->setDataVariance(osg::Object::STATIC);
MT->addChild(bumpModel);
bumpRoot->addChild(MT);

// Set viewer
osgViewer::Viewer bumpViewer;
bumpViewer.setSceneData(bumpRoot);
bumpViewer.setCameraManipulator(new osgGA::TrackballManipulator());
bumpViewer.realize();

while (!bumpViewer.done()) {
bumpViewer.frame();
}
return 0;
}


The modified newbump.frag
Quote:

uniform sampler2D diffuseTexture;
uniform sampler2D normalTexture;

// New bumpmapping
varying vec3 lightVec;
varying vec3 halfVec;
varying vec3 eyeVec;

void main() {

// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
vec3 normal = 2.0 * texture2D (normalTexture, gl_TexCoord[0].st).rgb - 1.0;
normal = normalize (normal);

// compute diffuse lighting
float lamberFactor= max (dot (lightVec, normal), 0.0) ;
vec4 diffuseMaterial = 0.0;
vec4 diffuseLight = 0.0;

// compute specular lighting
vec4 specularMaterial ;
vec4 specularLight ;
float shininess ;

// compute ambient
vec4 ambientLight = gl_LightSource[0].ambient;

if (lamberFactor > 0.0)
{
diffuseMaterial = texture2D (diffuseTexture, gl_TexCoord[0].st);
diffuseLight = gl_LightSource[0].diffuse;

// In doom3, specular value comes from a texture
specularMaterial = vec4(1.0) ;
specularLight = gl_LightSource[0].specular;
shininess = 0.05;
//shininess = pow (max (dot (halfVec, normal), 0.0), 2.0) ;

gl_FragColor = diffuseMaterial * diffuseLight * lamberFactor ;
gl_FragColor += specularMaterial * specularLight * shininess ;

}

gl_FragColor += ambientLight;

}


The modified newbump.vert
Quote:

attribute vec3 tangent;
varying vec3 lightVec;
varying vec3 halfVec;
varying vec3 eyeVec;

void main() {

//gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;

// Building the matrix Eye Space -> Tangent Space
vec3 n = normalize (gl_NormalMatrix * gl_Normal);
vec3 t = normalize (gl_NormalMatrix * tangent);
vec3 b = cross (n, t);

vec3 vertexPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 lightDir = normalize(gl_LightSource[0].position.xyz - vertexPosition);


// transform light and half angle vectors by tangent basis
vec3 v;
v.x = dot (lightDir, t);
v.y = dot (lightDir, b);
v.z = dot (lightDir, n);
lightVec = normalize (v);


v.x = dot (vertexPosition, t);
v.y = dot (vertexPosition, b);
v.z = dot (vertexPosition, n);
eyeVec = normalize (v);


vertexPosition = normalize(vertexPosition);

/* Normalize the halfVector to pass it to the fragment shader */

// No need to divide by two, the result is normalized anyway.
// vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0);
vec3 halfVector = normalize(vertexPosition + lightDir);
v.x = dot (halfVector, t);
v.y = dot (halfVector, b);
v.z = dot (halfVector, n);

// No need to normalize, t,b,n and halfVector are normal vectors.
//normalize (v);
halfVec = v ;


gl_Position = ftransform();

}


I hope I can help osg programmer with the same problem.
Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Thu Nov 12, 2015 10:49 pm    Post subject:
Reply with quote

In addition of course the new NVidia driver for Fallout 4 the bump on the model is shown in different colors. To fix this problem look up in the newbump.frag and comment out the "if (lamberFactor > 0.0)" instruction but don't comment out the content of this instruction
Back to top
View user's profile Send private message
SubSonicEr (Tobias Rick)
Newbie


Joined: 05 Nov 2015
Posts: 7
Location: Germany

PostPosted: Fri Nov 13, 2015 4:01 pm    Post subject:
Reply with quote

I found an other problem. When I rotate my object, the light direction also is rotated. How can I prevent this?
Back to top
View user's profile Send private message
trocolit
Newbie


Joined: 04 Apr 2016
Posts: 1

PostPosted: Mon Apr 04, 2016 4:12 pm    Post subject:
Reply with quote

Hi Tobias

I implemented the OSG BumpMap with no need to use shaders, as follow:

function source

Code:
 
void bumpMapOSG(osg::Geode *geode, osg::Group *group, osg::Image *normal_image, osg::Image *difuse_image, double scale_x,
        double scale_y) {

    if (!normal_image || !difuse_image) {
        std::cout << "IMAGE FAIL" << std::endl;
        exit(0);
    }

    osg::StateSet* bumpState = new osg::StateSet();

    // Set textures
    osg::ref_ptr<osg::Texture2D> normal_texture(new osg::Texture2D());
    osg::ref_ptr<osg::Texture2D> difuse_texture(new osg::Texture2D());

    normal_texture->setImage(normal_image);
    normal_texture->setDataVariance(osg::Object::DYNAMIC);
    normal_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
    normal_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
    normal_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    normal_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    normal_texture->setResizeNonPowerOfTwoHint(false);
    normal_texture->setMaxAnisotropy(8.0f);

    difuse_texture->setImage(difuse_image);
    difuse_texture->setDataVariance(osg::Object::DYNAMIC);
    difuse_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
    difuse_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
    difuse_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    difuse_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    difuse_texture->setResizeNonPowerOfTwoHint(false);
    difuse_texture->setMaxAnisotropy(8.0f);

    const int TEXTURE_UNIT_NORMAL = 1;
    const int TEXTURE_UNIT_DIFUSE = 2;

    bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_NORMAL, normal_texture, osg::StateAttribute::ON);
    bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFUSE, difuse_texture, osg::StateAttribute::ON);

    osg::ref_ptr<osg::Geometry> geometry = geode->asGeode()->getDrawable(0)->asGeometry();
    osg::Vec2Array* tex_coord = dynamic_cast<osg::Vec2Array*>(geometry->getTexCoordArray(0));

    for (unsigned int i = 0; i < tex_coord->getNumElements(); ++i)
        (*tex_coord)[i].set((*tex_coord)[i].x() * scale_x, (*tex_coord)[i].y() * scale_y);

    geometry->setStateSet(bumpState);
    if (tex_coord) {
        geometry->setTexCoordArray(TEXTURE_UNIT_NORMAL, tex_coord);
        geometry->setTexCoordArray(TEXTURE_UNIT_DIFUSE, tex_coord);
    } else {
        std::cout << "MISS TEXTURE COORDINATE " << std::endl;
        exit(0);
    }

    osgFX::BumpMapping* bump_mapping = new osgFX::BumpMapping();
    bump_mapping->setEnabled(true);
    bump_mapping->setLightNumber(0);
    bump_mapping->setNormalMapTextureUnit(TEXTURE_UNIT_NORMAL);
    bump_mapping->setDiffuseTextureUnit(TEXTURE_UNIT_DIFUSE);
    bump_mapping->addChild(geode);
    bump_mapping->prepareChildren();
    group->addChild(bump_mapping);

}
[\code]



Thank you!

Cheers,
Tiago
Back to top
View user's profile Send private message
cbuchner1
Appreciator


Joined: 14 Mar 2012
Posts: 310

PostPosted: Tue Apr 05, 2016 4:17 pm    Post subject:
using 3Ds Model in osgFX::BumpMapping and the Texture UV Coords for diffuse are not loaded
Reply with quote

Quote:
I implemented the OSG BumpMap with no need to use shaders, as follow:
osgFX::BumpMapping* bump_mapping = new osgFX::BumpMapping();


Hmm, by default this osgFX effect module will use shaders according to its documentation:

"This effect defines a preferred technique which uses ARB vertex & fragment programs, and a fallback technique which doesn't use fragment programs."


ARB fragment and vertex programs are some of the oldest types of programmable shaders.



Christian



2016-04-04 18:12 GMT+02:00 Tiago Trocoli < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:
Hi Tobias

I implemented the OSG BumpMap with no need to use shaders, as follow:

function source


Code:

void bumpMapOSG(osg::Geode *geode, osg::Group *group, osg::Image *normal_image, osg::Image *difuse_image, double scale_x,
        double scale_y) {

    if (!normal_image || !difuse_image) {
        std::cout << "IMAGE FAIL" << std::endl;
        exit(0);
    }

    osg::StateSet* bumpState = new osg::StateSet();

    // Set textures
    osg::ref_ptr<osg::Texture2D> normal_texture(new osg::Texture2D());
    osg::ref_ptr<osg::Texture2D> difuse_texture(new osg::Texture2D());

    normal_texture->setImage(normal_image);
    normal_texture->setDataVariance(osg::Object::DYNAMIC);
    normal_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
    normal_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
    normal_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    normal_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    normal_texture->setResizeNonPowerOfTwoHint(false);
    normal_texture->setMaxAnisotropy(8.0f);

    difuse_texture->setImage(difuse_image);
    difuse_texture->setDataVariance(osg::Object::DYNAMIC);
    difuse_texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
    difuse_texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
    difuse_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    difuse_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    difuse_texture->setResizeNonPowerOfTwoHint(false);
    difuse_texture->setMaxAnisotropy(8.0f);

    const int TEXTURE_UNIT_NORMAL = 1;
    const int TEXTURE_UNIT_DIFUSE = 2;

    bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_NORMAL, normal_texture, osg::StateAttribute:ShockedN);
    bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFUSE, difuse_texture, osg::StateAttribute:ShockedN);

    osg::ref_ptr<osg::Geometry> geometry = geode->asGeode()->getDrawable(0)->asGeometry();
    osg::Vec2Array* tex_coord = dynamic_cast<osg::Vec2Array*>(geometry->getTexCoordArray(0));

    for (unsigned int i = 0; i < tex_coord->getNumElements(); ++i)
        (*tex_coord)[i].set((*tex_coord)[i].x() * scale_x, (*tex_coord)[i].y() * scale_y);

    geometry->setStateSet(bumpState);
    if (tex_coord) {
        geometry->setTexCoordArray(TEXTURE_UNIT_NORMAL, tex_coord);
        geometry->setTexCoordArray(TEXTURE_UNIT_DIFUSE, tex_coord);
    } else {
        std::cout << "MISS TEXTURE COORDINATE " << std::endl;
        exit(0);
    }

    osgFX::BumpMapping* bump_mapping = new osgFX::BumpMapping();
    bump_mapping->setEnabled(true);
    bump_mapping->setLightNumber(0);
    bump_mapping->setNormalMapTextureUnit(TEXTURE_UNIT_NORMAL);
    bump_mapping->setDiffuseTextureUnit(TEXTURE_UNIT_DIFUSE);
    bump_mapping->addChild(geode);
    bump_mapping->prepareChildren();
    group->addChild(bump_mapping);

}
[code]



Thank you!

Cheers,
Tiago



------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66724#66724





_______________________________________________
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
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Build system [build] 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 BVH and model axis centering: a model... Paradox Plugins [osgPlugins] 0 Mon Oct 16, 2017 4:27 pm View latest post
No new posts Best Model For Augmented Reality? Bobykhani General [forum] 3 Sun Oct 15, 2017 6:49 am View latest post
No new posts Problem With Osg Texture Colors! Bobykhani General [forum] 1 Tue Oct 10, 2017 8:20 am View latest post
No new posts obj plugin does not support diffuse a... Ralf Habacker General 5 Tue Sep 19, 2017 6:21 am View latest post
No new posts Osg model assembly jaisingla General 0 Mon Sep 18, 2017 3:36 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