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 

bump mapping using GLSL shaders


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Morné Pistorius
Guest





PostPosted: Mon Nov 24, 2008 4:39 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi all,

I added bump mapping to a model using osgFX::BumpMapping, but I need something more flexible. My model has two sided lighting and osgFX doesn't support that. Do we have GLSL shaders for bumpmapping in OSG? I think that would be easier to modify to suit my needs than the assembler coded shaders used in osgFX. If anyone has an example of applying normal mapping with shaders in OSG, I would greatly appreciate it.


Thank you kindly,
Morne

------------------
Post generated by Mail2Forum
Back to top
Alejandro Aguilar Sierra
Guest





PostPosted: Mon Nov 24, 2008 5:02 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX doesn't
support that. Do we have GLSL shaders for bumpmapping in OSG? I think that
would be easier to modify to suit my needs than the assembler coded shaders
used in osgFX. If anyone has an example of applying normal mapping with
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne





------------------
Post generated by Mail2Forum
Back to top
Morné Pistorius
Guest





PostPosted: Wed Nov 26, 2008 12:30 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Thanks,

I managed to implement a standard bump mapping shader in OSG. Below is a code snippet that does it if it might help someone else. Shaders are attached.


Cheers,
Morne


osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;


osg::Geode* geode = new osg::Geode;


// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;


osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );


osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;


geom->setVertexArray(coords);


osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );


geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);


osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);


geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );


osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );


geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0 , coords->size() ) );
geode->addDrawable( geom );


// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );


// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath + "/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );


// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath + "/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );




//////////////////////////////////////////////////////////////////////////
// Set up bump mapping shaders


// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader( osg::Shader::VERTEX );
osg::Shader * bumpPixelShader = new osg::Shader( osg::Shader::FRAGMENT );
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath + "/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath + "/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );


// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );


// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT, osg::Geometry::ArrayData( tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT, osg::Geometry::ArrayData( tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );


// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4( 0.36, 0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4( 0.49, 0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4( 0.88, 0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f ) );


return geode;
}







On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.


On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX doesn't
support that. Do we have GLSL shaders for bumpmapping in OSG? I think that
would be easier to modify to suit my needs than the assembler coded shaders
used in osgFX. If anyone has an example of applying normal mapping with
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne


Quote:
_______________________________________________
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


_______________________________________________
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
Sukender
Guest





PostPosted: Wed Nov 26, 2008 2:46 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

This is not related to GLSL, but if someone needs it, I quickly wrote a function that transforms a gray-scale bump map into a normal map: http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that clean.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below is a
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0 ,
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );


//////////////////////////////////////////////////////////////////////////
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader( osg::Shader::VERTEX );
osg::Shader * bumpPixelShader = new osg::Shader( osg::Shader::FRAGMENT );
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4( 0.36,
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4( 0.49,
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4( 0.88,
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f ) );

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I think
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping with
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
osg-users mailing list


http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
?mit Uzun
Guest





PostPosted: Wed Nov 26, 2008 3:01 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi Sukender,

I have searched about Normal Map and I see that to create normal map we need 2 models( high detailed polygon and low detailed polygon ) and then we can create normal map using ray casting to find high detailed models normals at intersected areas and then save this normal as a texture which name is NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I haven't any models. Can I use Ocean wave texture to create bumpmapping? I mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function, then I think. take back bluish normal map Sukender?

2008/11/26 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote a function that transforms a gray-scale bump map into a normal map: http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that clean.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:


Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below is a
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0 ,
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );


//////////////////////////////////////////////////////////////////////////
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader( osg::Shader::VERTEX );
osg::Shader * bumpPixelShader = new osg::Shader( osg::Shader::FRAGMENT );
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4( 0.36,
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4( 0.49,
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4( 0.88,
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f ) );

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I think
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping with
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
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
_______________________________________________
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

_______________________________________________
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





--
?mit Uzun

------------------
Post generated by Mail2Forum
Back to top
Mike Weiblen
Guest





PostPosted: Wed Nov 26, 2008 3:54 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi, you may also find this doc useful:
http://mew.cx/osg_glsl_july2005.pdf

cheers
-- mew


On Mon, Nov 24, 2008 at 9:39 AM, Morn?© Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX doesn't
support that. Do we have GLSL shaders for bumpmapping in OSG? I think that
would be easier to modify to suit my needs than the assembler coded shaders
used in osgFX. If anyone has an example of applying normal mapping with
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne






--
Mike Weiblen -- Boulder Colorado USA -- http://mew.cx/


------------------
Post generated by Mail2Forum
Back to top
Sukender
Guest





PostPosted: Wed Nov 26, 2008 10:02 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you wrote... (maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture describing the color of your ocean's surface? If so, then the color of the texture is rarely related to bump/normal mapping. You'll have to create from scratch (or find) a bump/normal map. You can try using a picture edition software (such as "the Gimp") and use filters or generators to create a gray-scaled image (where white=high and black=low). This is what I often do when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but that's not the goal of the function I told you. createNormalMap() only converts a gray-scaled image to a normal map (texture that is blueish). The normal map can be then used more easily in OSG/OpenGL, using TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun <> a écrit:

Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map we need
2 models( high detailed polygon and low detailed polygon ) and then we can
create normal map using ray casting to find high detailed models normals at
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create bumpmapping? I
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function, then I
think. take back bluish normal map Sukender?

2008/11/26 Sukender <>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote a
function that transforms a gray-scale bump map into a normal map:
http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that clean.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below is a
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );



//////////////////////////////////////////////////////////////////////////
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader( osg::Shader::VERTEX
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader( osg::Shader::FRAGMENT
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4( 0.36,
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4( 0.49,
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4( 0.88,
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f ) );

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
osg-users mailing list



http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:
_______________________________________________
osg-users mailing list


http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org





------------------
Post generated by Mail2Forum
Back to top
?mit Uzun
Guest





PostPosted: Thu Nov 27, 2008 7:28 am    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi Sukender,

Thanks for reply. Sorry I can't express my expected result because of my english Razz Yes you understood me albeit my bad express. I have RGB texture and want to create bump map animated surface to make more realistic surface. I find normal map usage only osgVolume.cpp sample. If you know more sample, please let me know.

Thanks for helps.
Best Regards.

2008/11/27 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you wrote... (maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture describing the color of your ocean's surface? If so, then the color of the texture is rarely related to bump/normal mapping. You'll have to create from scratch (or find) a bump/normal map. You can try using a picture edition software (such as "the Gimp") and use filters or generators to create a gray-scaled image (where white=high and black=low). This is what I often do when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but that's not the goal of the function I told you. createNormalMap() only converts a gray-scaled image to a normal map (texture that is blueish). The normal map can be then used more easily in OSG/OpenGL, using TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/



Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:


Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map we need
2 models( high detailed polygon and low detailed polygon ) and then we can
create normal map using ray casting to find high detailed models normals at
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create bumpmapping? I
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function, then I
think. take back bluish normal map Sukender?

2008/11/26 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote a
function that transforms a gray-scale bump map into a normal map:
http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that clean.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below is a
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );



//////////////////////////////////////////////////////////////////////////
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader( osg::Shader::VERTEX
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader( osg::Shader::FRAGMENT
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT, osg::Geometry::ArrayData(
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT ) );

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4( 0.36,
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4( 0.49,
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4( 0.88,
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f ) );

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I need
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
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
Quote:
Quote:
_______________________________________________
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

_______________________________________________
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

_______________________________________________
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





--
?mit Uzun

------------------
Post generated by Mail2Forum
Back to top
Sukender
Guest





PostPosted: Thu Nov 27, 2008 9:55 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi ?mit,

Considering you want to *animate* your bump/normal map, you may:
- Use an image sequence of normal maps, that has the advantage of being almost the same code as for a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not taking memory for textures, even if you want a very smooth animation.

I just can't help you for shaders because I don't know anything about them. Try searching the web.

For non animated bumps, well maybe many wrote examples or code using it but I can't indicate you where.
For my part, I used a bump for the loading screen of a tiny game: the bump is loaded from a gray-scale, then converted to a normal map using my function, applied to a quad, and then modulated by the color texture. The light source then moves during the loading process. The code can be found at http://paratrooper.svn.sourceforge.net/viewvc/paratrooper/trunk/Src/App.cpp?view=markup (search for "TexEnvCombine::DOT3_RGB" and you'll find a block of code about the "logo"). Code is GPL, but as long as you just take a few lines, there's no problem for me using it the way you want.
Once it works for you, you'll be able to replace the texture by an image sequence.

However, you should try to have a look to shaders. If you find or acheive to write a nice animation, please tell me!

Hope it helps.

Just for curiosity: what are you working on?

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Thu, 27 Nov 2008 08:27:53 +0100, ?mit Uzun <> a écrit:

Quote:
Hi Sukender,

Thanks for reply. Sorry I can't express my expected result because of my
english Razz Yes you understood me albeit my bad express. I have RGB texture
and want to create bump map animated surface to make more realistic surface.
I find normal map usage only osgVolume.cpp sample. If you know more sample,
please let me know.

Thanks for helps.
Best Regards.

2008/11/27 Sukender <>

Quote:
Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you wrote...
(maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture
describing the color of your ocean's surface? If so, then the color of the
texture is rarely related to bump/normal mapping. You'll have to create from
scratch (or find) a bump/normal map. You can try using a picture edition
software (such as "the Gimp") and use filters or generators to create a
gray-scaled image (where white=high and black=low). This is what I often do
when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but
that's not the goal of the function I told you. createNormalMap() only
converts a gray-scaled image to a normal map (texture that is blueish). The
normal map can be then used more easily in OSG/OpenGL, using
TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG
samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun <> a
écrit:

Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map we
need
Quote:
2 models( high detailed polygon and low detailed polygon ) and then we
can
Quote:
create normal map using ray casting to find high detailed models normals
at
Quote:
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create bumpmapping? I
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function, then
I
Quote:
think. take back bluish normal map Sukender?

2008/11/26 Sukender <>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote a
function that transforms a gray-scale bump map into a normal map:
http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that
clean.
Quote:
Quote:

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below
is a
Quote:
Quote:
Quote:
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays(
osg::PrimitiveSet::QUADS, 0
Quote:
Quote:
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );




//////////////////////////////////////////////////////////////////////////
Quote:
Quote:
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader(
osg::Shader::VERTEX
Quote:
Quote:
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader(
osg::Shader::FRAGMENT
Quote:
Quote:
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT )
);
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT )
);
Quote:
Quote:
Quote:

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4(
0.36,
Quote:
Quote:
Quote:
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4(
0.49,
Quote:
Quote:
Quote:
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4(
0.88,
Quote:
Quote:
Quote:
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f )
);
Quote:
Quote:
Quote:

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I
need
Quote:
Quote:
Quote:
Quote:
Quote:
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
osg-users mailing list




http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:
Quote:
Quote:
_______________________________________________
osg-users mailing list



http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:

_______________________________________________
osg-users mailing list


http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org





------------------
Post generated by Mail2Forum
Back to top
?mit Uzun
Guest





PostPosted: Fri Nov 28, 2008 7:15 am    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi Sukender,

Quote:
Quote:
- Use an image sequence of normal maps, that has the advantage of being almost the same code as for >>a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not taking memory for textures, even if >>you want a very smooth animation.

Actually I will mix of two, I create one normal map from wave texture and then animate on the water surface by changing texture coordinates so it can be seen moving and waving water surface.

I will try as soon as possible but now I will look at OpenAL for couple of weeks Smile I need sounds as you. I think you use osgAL on your project but I will try to use OpenAL till the osgAudio is released. I am waiting 2.10 release with hoping osgAudio nodekit Smile

Quote:
Quote:
Just for curiosity: what are you working on?
I am trying to create submarine simulator but I am naive on this topic Smile I am learning GLSL and OpenGL. For now I want to create water simuation as you can see from http://dangerdeep.sourceforge.net/ But it is too hard for me at the present.

Best Regards.

2008/11/27 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi ?mit,

Considering you want to *animate* your bump/normal map, you may:
- Use an image sequence of normal maps, that has the advantage of being almost the same code as for a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not taking memory for textures, even if you want a very smooth animation.

I just can't help you for shaders because I don't know anything about them. Try searching the web.

For non animated bumps, well maybe many wrote examples or code using it but I can't indicate you where.
For my part, I used a bump for the loading screen of a tiny game: the bump is loaded from a gray-scale, then converted to a normal map using my function, applied to a quad, and then modulated by the color texture. The light source then moves during the loading process. The code can be found at http://paratrooper.svn.sourceforge.net/viewvc/paratrooper/trunk/Src/App.cpp?view=markup (search for "TexEnvCombine::DOT3_RGB" and you'll find a block of code about the "logo"). Code is GPL, but as long as you just take a few lines, there's no problem for me using it the way you want.
Once it works for you, you'll be able to replace the texture by an image sequence.

However, you should try to have a look to shaders. If you find or acheive to write a nice animation, please tell me!

Hope it helps.

Just for curiosity: what are you working on?

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/



Le Thu, 27 Nov 2008 08:27:53 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:


Quote:
Hi Sukender,

Thanks for reply. Sorry I can't express my expected result because of my
english Razz Yes you understood me albeit my bad express. I have RGB texture
and want to create bump map animated surface to make more realistic surface.
I find normal map usage only osgVolume.cpp sample. If you know more sample,
please let me know.

Thanks for helps.
Best Regards.

2008/11/27 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you wrote...
(maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture
describing the color of your ocean's surface? If so, then the color of the
texture is rarely related to bump/normal mapping. You'll have to create from
scratch (or find) a bump/normal map. You can try using a picture edition
software (such as "the Gimp") and use filters or generators to create a
gray-scaled image (where white=high and black=low). This is what I often do
when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but
that's not the goal of the function I told you. createNormalMap() only
converts a gray-scaled image to a normal map (texture that is blueish). The
normal map can be then used more easily in OSG/OpenGL, using
TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG
samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a
écrit:

Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map we
need
Quote:
2 models( high detailed polygon and low detailed polygon ) and then we
can
Quote:
create normal map using ray casting to find high detailed models normals
at
Quote:
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create bumpmapping? I
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function, then
I
Quote:
think. take back bluish normal map Sukender?

2008/11/26 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote a
function that transforms a gray-scale bump map into a normal map:
http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Hope this may be useful to someone, even if the function is not that
clean.
Quote:
Quote:

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG. Below
is a
Quote:
Quote:
Quote:
code snippet that does it if it might help someone else. Shaders are
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays(
osg::PrimitiveSet::QUADS, 0
Quote:
Quote:
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT );
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT );
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );




//////////////////////////////////////////////////////////////////////////
Quote:
Quote:
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader(
osg::Shader::VERTEX
Quote:
Quote:
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader(
osg::Shader::FRAGMENT
Quote:
Quote:
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
geom->setVertexAttribData( BINORMAL_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE ) );
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos ) );
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT )
);
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT )
);
Quote:
Quote:
Quote:

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4(
0.36,
Quote:
Quote:
Quote:
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4(
0.49,
Quote:
Quote:
Quote:
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4(
0.88,
Quote:
Quote:
Quote:
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f )
);
Quote:
Quote:
Quote:

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with glsl)
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I
need
Quote:
Quote:
Quote:
Quote:
Quote:
something more flexible. My model has two sided lighting and osgFX
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG? I
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler coded
shaders
Quote:
used in osgFX. If anyone has an example of applying normal mapping
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
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
Quote:
Quote:
Quote:
Quote:
_______________________________________________
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
Quote:
Quote:

_______________________________________________
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

_______________________________________________
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

_______________________________________________
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





--
?mit Uzun

------------------
Post generated by Mail2Forum
Back to top
Sukender
Guest





PostPosted: Sun Nov 30, 2008 3:31 pm    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi ?mit,

When you need some hints about what I already did, then just ask me! And if you need big portions of code, just go ahead (I saw your project is GPL, right?).

About osgAudio, I'm terrobly sorry, but if I'm alone I won't be the one that will design and code osgAudio. I really need that EVERYONE that want to see osgAudio work together. If you want I can give you hints on haow to include the existing osgAL to your project, but not much more.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Fri, 28 Nov 2008 08:15:41 +0100, ?mit Uzun <> a écrit:

Quote:
Hi Sukender,

Quote:
Quote:
- Use an image sequence of normal maps, that has the advantage of being almost the same code as for >>a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not taking memory for textures, even if >>you want a very smooth animation.

Actually I will mix of two, I create one normal map from wave texture and
then animate on the water surface by changing texture coordinates so it can
be seen moving and waving water surface.

I will try as soon as possible but now I will look at OpenAL for couple of
weeks Smile I need sounds as you. I think you use osgAL on your project but I
will try to use OpenAL till the osgAudio is released. I am waiting 2.10
release with hoping osgAudio nodekit Smile

Quote:
Quote:
Just for curiosity: what are you working on?
I am trying to create submarine simulator but I am naive on this topic Smile I
am learning GLSL and OpenGL. For now I want to create water simuation as you
can see from http://dangerdeep.sourceforge.net/ But it is too hard for me at
the present.

Best Regards.

2008/11/27 Sukender <>

Quote:
Hi ?mit,

Considering you want to *animate* your bump/normal map, you may:
- Use an image sequence of normal maps, that has the advantage of being
almost the same code as for a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not
taking memory for textures, even if you want a very smooth animation.

I just can't help you for shaders because I don't know anything about them.
Try searching the web.

For non animated bumps, well maybe many wrote examples or code using it but
I can't indicate you where.
For my part, I used a bump for the loading screen of a tiny game: the bump
is loaded from a gray-scale, then converted to a normal map using my
function, applied to a quad, and then modulated by the color texture. The
light source then moves during the loading process. The code can be found at

http://paratrooper.svn.sourceforge.net/viewvc/paratrooper/trunk/Src/App.cpp?view=markup(search for "TexEnvCombine::DOT3_RGB" and you'll find a block of code about
the "logo"). Code is GPL, but as long as you just take a few lines, there's
no problem for me using it the way you want.
Once it works for you, you'll be able to replace the texture by an image
sequence.

However, you should try to have a look to shaders. If you find or acheive
to write a nice animation, please tell me!

Hope it helps.

Just for curiosity: what are you working on?

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Thu, 27 Nov 2008 08:27:53 +0100, ?mit Uzun <> a
écrit:

Quote:
Hi Sukender,

Thanks for reply. Sorry I can't express my expected result because of my
english Razz Yes you understood me albeit my bad express. I have RGB
texture
Quote:
and want to create bump map animated surface to make more realistic
surface.
Quote:
I find normal map usage only osgVolume.cpp sample. If you know more
sample,
Quote:
please let me know.

Thanks for helps.
Best Regards.

2008/11/27 Sukender <>

Quote:
Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you
wrote...
Quote:
Quote:
(maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture
describing the color of your ocean's surface? If so, then the color of
the
Quote:
Quote:
texture is rarely related to bump/normal mapping. You'll have to create
from
Quote:
Quote:
scratch (or find) a bump/normal map. You can try using a picture edition
software (such as "the Gimp") and use filters or generators to create a
gray-scaled image (where white=high and black=low). This is what I often
do
Quote:
Quote:
when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but
that's not the goal of the function I told you. createNormalMap() only
converts a gray-scaled image to a normal map (texture that is blueish).
The
Quote:
Quote:
normal map can be then used more easily in OSG/OpenGL, using
TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG
samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun <> a
écrit:

Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map
we
Quote:
Quote:
need
Quote:
2 models( high detailed polygon and low detailed polygon ) and then we
can
Quote:
create normal map using ray casting to find high detailed models
normals
Quote:
Quote:
at
Quote:
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create
bumpmapping? I
Quote:
Quote:
Quote:
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function,
then
Quote:
Quote:
I
Quote:
think. take back bluish normal map Sukender?

2008/11/26 Sukender <>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote
a
Quote:
Quote:
Quote:
Quote:
function that transforms a gray-scale bump map into a normal map:

http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Quote:
Quote:
Quote:
Quote:
Hope this may be useful to someone, even if the function is not that
clean.
Quote:
Quote:

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG.
Below
Quote:
Quote:
is a
Quote:
Quote:
Quote:
code snippet that does it if it might help someone else. Shaders
are
Quote:
Quote:
Quote:
Quote:
Quote:
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays(
osg::PrimitiveSet::QUADS, 0
Quote:
Quote:
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );





//////////////////////////////////////////////////////////////////////////
Quote:
Quote:
Quote:
Quote:
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader(
osg::Shader::VERTEX
Quote:
Quote:
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader(
osg::Shader::FRAGMENT
Quote:
Quote:
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE )
);
Quote:
Quote:
Quote:
Quote:
Quote:
geom->setVertexAttribData( BINORMAL_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE )
);
Quote:
Quote:
Quote:
Quote:
Quote:
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos )
);
Quote:
Quote:
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT
)
Quote:
Quote:
);
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT
)
Quote:
Quote:
);
Quote:
Quote:
Quote:

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4(
0.36,
Quote:
Quote:
Quote:
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4(
0.49,
Quote:
Quote:
Quote:
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4(
0.88,
Quote:
Quote:
Quote:
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f
)
Quote:
Quote:
);
Quote:
Quote:
Quote:

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with
glsl)
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
<> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I
need
Quote:
Quote:
Quote:
Quote:
Quote:
something more flexible. My model has two sided lighting and
osgFX
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG?
I
Quote:
Quote:
Quote:
Quote:
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler
coded
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
shaders
Quote:
used in osgFX. If anyone has an example of applying normal
mapping
Quote:
Quote:
Quote:
Quote:
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
osg-users mailing list





http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
_______________________________________________
osg-users mailing list




http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:
Quote:
Quote:

_______________________________________________
osg-users mailing list



http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Quote:
Quote:

_______________________________________________
osg-users mailing list


http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org





------------------
Post generated by Mail2Forum
Back to top
?mit Uzun
Guest





PostPosted: Mon Dec 01, 2008 8:31 am    Post subject:
bump mapping using GLSL shaders
Reply with quote

Hi Sukender,

I am only searching and trying to develop this project. For now it's not commercial Smile

I am looking OpenAL and after learning much of this API I look for osgAL and try to implement. So If I have problem, absolutely I will ask for your help Smile

For developing osgAudio I may help as much as I can do, but I am not prof as you guess. For now we can only wait a hero to be leader for save this API Smile

Thanks so much for everyting.

Regards.

2008/11/30 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi ?mit,

When you need some hints about what I already did, then just ask me! And if you need big portions of code, just go ahead (I saw your project is GPL, right?).

About osgAudio, I'm terrobly sorry, but if I'm alone I won't be the one that will design and code osgAudio. I really need that EVERYONE that want to see osgAudio work together. If you want I can give you hints on haow to include the existing osgAL to your project, but not much more.

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/



Le Fri, 28 Nov 2008 08:15:41 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:


Quote:
Hi Sukender,

Quote:
Quote:
- Use an image sequence of normal maps, that has the advantage of being almost the same code as for >>a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not taking memory for textures, even if >>you want a very smooth animation.

Actually I will mix of two, I create one normal map from wave texture and
then animate on the water surface by changing texture coordinates so it can
be seen moving and waving water surface.

I will try as soon as possible but now I will look at OpenAL for couple of
weeks Smile I need sounds as you. I think you use osgAL on your project but I
will try to use OpenAL till the osgAudio is released. I am waiting 2.10
release with hoping osgAudio nodekit Smile

Quote:
Quote:
Just for curiosity: what are you working on?
I am trying to create submarine simulator but I am naive on this topic Smile I
am learning GLSL and OpenGL. For now I want to create water simuation as you
can see from http://dangerdeep.sourceforge.net/ But it is too hard for me at
the present.

Best Regards.

2008/11/27 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
Hi ?mit,

Considering you want to *animate* your bump/normal map, you may:
- Use an image sequence of normal maps, that has the advantage of being
almost the same code as for a non animated bump.
- Or look at (procedural) shaders, that will have the advantage of not
taking memory for textures, even if you want a very smooth animation.

I just can't help you for shaders because I don't know anything about them.
Try searching the web.

For non animated bumps, well maybe many wrote examples or code using it but
I can't indicate you where.
For my part, I used a bump for the loading screen of a tiny game: the bump
is loaded from a gray-scale, then converted to a normal map using my
function, applied to a quad, and then modulated by the color texture. The
light source then moves during the loading process. The code can be found at

http://paratrooper.svn.sourceforge.net/viewvc/paratrooper/trunk/Src/App.cpp?view=markup(search for "TexEnvCombine::DOT3_RGB" and you'll find a block of code about
the "logo"). Code is GPL, but as long as you just take a few lines, there's
no problem for me using it the way you want.
Once it works for you, you'll be able to replace the texture by an image
sequence.

However, you should try to have a look to shaders. If you find or acheive
to write a nice animation, please tell me!

Hope it helps.

Just for curiosity: what are you working on?

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Thu, 27 Nov 2008 08:27:53 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a
écrit:

Quote:
Hi Sukender,

Thanks for reply. Sorry I can't express my expected result because of my
english Razz Yes you understood me albeit my bad express. I have RGB
texture
Quote:
and want to create bump map animated surface to make more realistic
surface.
Quote:
I find normal map usage only osgVolume.cpp sample. If you know more
sample,
Quote:
please let me know.

Thanks for helps.
Best Regards.

2008/11/27 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
Hi ?mit,

Err... I'm terribly sorry but I did not understood all of what you
wrote...
Quote:
Quote:
(maybe my english?)

What do you call "Ocean wave texture"? Is that simply the RGB texture
describing the color of your ocean's surface? If so, then the color of
the
Quote:
Quote:
texture is rarely related to bump/normal mapping. You'll have to create
from
Quote:
Quote:
scratch (or find) a bump/normal map. You can try using a picture edition
software (such as "the Gimp") and use filters or generators to create a
gray-scaled image (where white=high and black=low). This is what I often
do
Quote:
Quote:
when I don't need to bee 100% realistic: that's just a nice bump map.

I know you can create normal mapping for low polys from hi polys, but
that's not the goal of the function I told you. createNormalMap() only
converts a gray-scaled image to a normal map (texture that is blueish).
The
Quote:
Quote:
normal map can be then used more easily in OSG/OpenGL, using
TexEnvCombine::DOT3_RGB. If you need examples, you can look at the OSG
samples (I guess there is a normal map somewhere), or ask me.

Note that using Google, I easily found some bump maps examples:
http://www.filterforge.com/filters/216-bump.jpg
http://www.m3corp.com/a/download/3d_textures/bump/instantcarpet.jpg

I just hope this answers your questions.

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 16:01:29 +0100, ?mit Uzun < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a
écrit:

Quote:
Hi Sukender,

I have searched about Normal Map and I see that to create normal map
we
Quote:
Quote:
need
Quote:
2 models( high detailed polygon and low detailed polygon ) and then we
can
Quote:
create normal map using ray casting to find high detailed models
normals
Quote:
Quote:
at
Quote:
intersected areas and then save this normal as a texture which name is
NormalMap.

But my question is, I want to create NormalMap the ocean waves. But I
haven't any models. Can I use Ocean wave texture to create
bumpmapping? I
Quote:
Quote:
Quote:
mean Can I create NormalMap from related wave texture?

If I send the my oceanwave texture to the createNormalMap function,
then
Quote:
Quote:
I
Quote:
think. take back bluish normal map Sukender?

2008/11/26 Sukender < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>

Quote:
This is not related to GLSL, but if someone needs it, I quickly wrote
a
Quote:
Quote:
Quote:
Quote:
function that transforms a gray-scale bump map into a normal map:

http://pvle.sourceforge.net/Doc/Html/Utility3D_8cpp-source.html#l00115
Quote:
Quote:
Quote:
Quote:
Hope this may be useful to someone, even if the function is not that
clean.
Quote:
Quote:

Sukender
PVLE - Lightweight cross-platform game engine -
http://pvle.sourceforge.net/


Le Wed, 26 Nov 2008 13:29:33 +0100, Morné Pistorius <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> a écrit:

Quote:
Thanks,
I managed to implement a standard bump mapping shader in OSG.
Below
Quote:
Quote:
is a
Quote:
Quote:
Quote:
code snippet that does it if it might help someone else. Shaders
are
Quote:
Quote:
Quote:
Quote:
Quote:
attached.

Cheers,
Morne

osg::Node * VOSGFloorGrid::CreateBumpMappedFloor()
{
const int BASE_TEX_UNIT = 0;
const int BUMP_TEX_UNIT = 1;
const int TANGENT_ATR_UNIT = 6;
const int BINORMAL_ATR_UNIT = 7;

osg::Geode* geode = new osg::Geode;

// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;

osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );

osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;

geom->setVertexArray(coords);

osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 1.0, 0.0 );

geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,1.0f);

geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );

osg::Vec2Array* tcoords = new osg::Vec2Array(4);
float n = 5.0f; // no of times the texture is repeated
(*tcoords)[0].set( 0.0f, 0.0f );
(*tcoords)[1].set( n, 0.0f );
(*tcoords)[2].set( n, n );
(*tcoords)[3].set( 0.0f, n );
geom->setTexCoordArray( BASE_TEX_UNIT, tcoords );
geom->setTexCoordArray( BUMP_TEX_UNIT, tcoords );

geom->addPrimitiveSet( new osg::DrawArrays(
osg::PrimitiveSet::QUADS, 0
Quote:
Quote:
,
Quote:
coords->size() ) );
geode->addDrawable( geom );

// Compute smoothed normals
osgUtil::SmoothingVisitor smoother;
smoother.apply( *geode );

// model texture
osg::Texture2D * diffuse = new osg::Texture2D;
diffuse->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/Floor.tga" ) );
diffuse->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
diffuse->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
diffuse->setResizeNonPowerOfTwoHint( false );
diffuse->setMaxAnisotropy( 8.0f );

// bump map texture
osg::Texture2D * normal = new osg::Texture2D;
normal->setImage( osgDB::readImageFile( m_sSystemPath +
"/Resources/FloorNormalMap.tga" ) );
normal->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
normal->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT
);
Quote:
Quote:
Quote:
Quote:
Quote:
normal->setResizeNonPowerOfTwoHint( false );
normal->setMaxAnisotropy( 8.0f );





//////////////////////////////////////////////////////////////////////////
Quote:
Quote:
Quote:
Quote:
Quote:
// Set up bump mapping shaders

// Load and compile shader source
osg::Program * bump = new osg::Program;
osg::Shader * bumpVertexShader = new osg::Shader(
osg::Shader::VERTEX
Quote:
Quote:
);
Quote:
osg::Shader * bumpPixelShader = new osg::Shader(
osg::Shader::FRAGMENT
Quote:
Quote:
);
Quote:
bumpVertexShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.vert" );
bumpPixelShader->loadShaderSourceFromFile( m_sSystemPath +
"/Resources/bumpmap.frag" );
bump->addShader( bumpVertexShader );
bump->addShader( bumpPixelShader );

// Set up the shader stateset
osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setTextureAttribute( BASE_TEX_UNIT, diffuse );
stateset->setTextureAttribute( BUMP_TEX_UNIT, normal );
stateset->setAttributeAndModes( bump, osg::StateAttribute:ShockedN );

// Compute tangent space for geometry
osg::ref_ptr< osgUtil::TangentSpaceGenerator > tsg = new
osgUtil::TangentSpaceGenerator;
tsg->generate( geom, BUMP_TEX_UNIT );
geom->setVertexAttribData( TANGENT_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE )
);
Quote:
Quote:
Quote:
Quote:
Quote:
geom->setVertexAttribData( BINORMAL_ATR_UNIT,
osg::Geometry::ArrayData(
Quote:
Quote:
Quote:
tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE )
);
Quote:
Quote:
Quote:
Quote:
Quote:
bump->addBindAttribLocation( "rm_Tangent", TANGENT_ATR_UNIT );
bump->addBindAttribLocation( "rm_Binormal", BINORMAL_ATR_UNIT );

// Initialise Uniforms
// Vertex shader
osg::Vec3 Pos( 0, 0, 1000 );
stateset->addUniform( new osg::Uniform( "fvLightPosition", Pos )
);
Quote:
Quote:
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "fvEyePosition", Pos ) );
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT
)
Quote:
Quote:
);
Quote:
Quote:
Quote:
stateset->addUniform( new osg::Uniform( "bumpMap", BUMP_TEX_UNIT
)
Quote:
Quote:
);
Quote:
Quote:
Quote:

// Fragment shader
stateset->addUniform( new osg::Uniform( "fvAmbient", osg::Vec4(
0.36,
Quote:
Quote:
Quote:
0.36, 0.36, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvSpecular", osg::Vec4(
0.49,
Quote:
Quote:
Quote:
0.49, 0.49, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fvDiffuse", osg::Vec4(
0.88,
Quote:
Quote:
Quote:
0.88, 0.88, 1.0 ) ) );
stateset->addUniform( new osg::Uniform( "fSpecularPower", 100.0f
)
Quote:
Quote:
);
Quote:
Quote:
Quote:

return geode;
}




On Mon, Nov 24, 2008 at 5:02 PM, Alejandro Aguilar Sierra <
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi,

I suggest you to see the osgshaders example (how osg deals with
glsl)
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
and then consult chapter 11 of the orange book (OpenGL shading
language). You can find the shaders used in the book at
http://3dshaders.com/

Hope it helps.

-- A.

On Mon, Nov 24, 2008 at 10:39 AM, Morné Pistorius
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,
I added bump mapping to a model using osgFX::BumpMapping, but I
need
Quote:
Quote:
Quote:
Quote:
Quote:
something more flexible. My model has two sided lighting and
osgFX
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
doesn't
Quote:
support that. Do we have GLSL shaders for bumpmapping in OSG?
I
Quote:
Quote:
Quote:
Quote:
think
Quote:
Quote:
that
Quote:
would be easier to modify to suit my needs than the assembler
coded
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
shaders
Quote:
used in osgFX. If anyone has an example of applying normal
mapping
Quote:
Quote:
Quote:
Quote:
with
Quote:
Quote:
Quote:
shaders in OSG, I would greatly appreciate it.
Thank you kindly,
Morne
_______________________________________________
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
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
_______________________________________________
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
Quote:
Quote:
Quote:
Quote:

_______________________________________________
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
Quote:
Quote:

_______________________________________________
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

_______________________________________________
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

_______________________________________________
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





--
?mit Uzun

------------------
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 Projective Mapping orthodoxality General 1 Wed Feb 27, 2019 5:43 pm View latest post
No new posts Happy New Year to all OSG Users Chris Hanson General 0 Mon Jan 07, 2019 10:17 am View latest post
No new posts osg-users Digest, Vol 138, Issue 27 Zachary1234 General 0 Tue Jan 01, 2019 1:16 am View latest post
No new posts pass mat4 as attribute for glsl sirian_ye General 4 Tue Nov 27, 2018 4:58 am View latest post
No new posts osg-users Digest, Vol 137, Issue 14 poweruserm@live.com.au General 0 Fri Nov 16, 2018 11:16 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