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 

Light effect in osgOcean


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean]
View previous topic :: View next topic  
Author Message
abarral
Newbie


Joined: 21 Sep 2010
Posts: 14

PostPosted: Wed Sep 22, 2010 1:42 pm    Post subject:
Light effect in osgOcean
Reply with quote

Hello,

I am writting an application wich use osgOcean Plugin.

I add to an ocean scene a submarine (imported from a 3DS file), and I would like to activate spot lights of this submarine.
So I attach to the submarine a light :

Code:

Vec4f lightPose(0,-1270,0,1); // le kster mesurant1.26mètres (d'après blender et le fichier 3ds), on met la lampe juste devant.
m_lumSpotAvant = new Light;
m_lumSpotAvant->setLightNum(1);
m_lumSpotAvant->setPosition(lightPose);
// look downard (pointed on the seabed)
m_lumSpotAvant->setDirection(Vec3f(0,0,-1));
m_lumSpotAvant->setSpotCutoff(90.0);
m_lumSpotAvant->setSpotExponent(50);
m_lumSpotAvant->setConstantAttenuation(0.1);
m_lumSpotAvant->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

m_spotAvant = new LightSource;
m_spotAvant->setLight(m_lumSpotAvant);
m_spotAvant->setLocalStateSetModes(osg::StateAttribute::ON);
m_spotAvant->setStateSetModes(*_rootStateSet,osg::StateAttribute::ON);
this->addChild(m_spotAvant);

Where _rootStateSet is the StateSet of the OceanScene.

There is another light in my scene, created like in the oceanExemple :
Code:

StateSet* rootStateSet = m_oceanScene->getOrCreateStateSet();
osg::LightSource* lightSource = new osg::LightSource;
osg::ref_ptr<osg::Light> light = lightSource->getLight();
light->setLightNum(0);
light->setAmbient( osg::Vec4d(0.3f, 0.3f, 0.3f, 1.0f ));
light->setDiffuse( intColor( 191, 191, 191 ,255) );
light->setSpecular(osg::Vec4d( 0.1f, 0.1f, 0.1f, 1.0f ) );
light->setPosition( osg::Vec4f(osg::Vec3f(326.573, 1212.99 ,1275.19), 1.f) ); // point light
lightSource->setLocalStateSetModes(osg::StateAttribute::ON);
lightSource->setStateSetModes(*rootStateSet,StateAttribute::ON);
m_oceanScene->addChild( lightSource );


When I did it, I can't see my spotlight.

I tried to do the same thing in a non osgOcean Scene, with the same lights, and that's work... I can see my seabed illuminated by an ambiant light, an area above the spot, illuminated by the spot...

So why using an OceanScene disable my lighting effects ??


Best Regards,
A. BARRAL
Back to top
View user's profile Send private message
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Wed Sep 22, 2010 2:03 pm    Post subject:
Light effect in osgOcean
Reply with quote

Hello Adrien,

Quote:
So why using an OceanScene disable my lighting effects ??

osgOcean uses shaders for most of its effects, and these shaders assume
directional lights. You will have to customize the shaders to do the
right calculations for all types of light source.

This is not a trivial topic and will require you to get acquainted with
writing GLSL shaders and also to modify the code of osgOcean and
recompile it.

To make osgOcean use your customized shaders you have two options.

1. Modify the shaders embedded in the osgOcean source code and recompile
osgOcean.
2. Modify the shaders in osgOcean's resource directory and disable the
"USE_LOCAL_SHADERS" define in the osgOcean source code and recompile
osgOcean.

I've been thinking of removing the USE_LOCAL_SHADERS define in osgOcean.
Currently osgOcean will use shaders embedded in its source code if
USE_LOCAL_SHADERS==1, and will load shaders from files if it's ==0. I
think a more useful way would be to just make it try to load shaders
from files (from the current directory, then OSG's data file path list,
as is OSG standard) and if they're not found, use the shaders embedded
in the source. This will allow apps to easily customize shaders without
recompiling by just distributing the shaders with the app, and if they
just need the default shaders they can not distribute them and the
default ones from the source code will be used, all without recompiling.

I'll try to get around to doing this soon. Also I haven't heard from Kim
Bale in a very long time, so I may try to make a release of osgOcean
soon with the modifications I've made since the last release. It's been
a while now.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.webhop.org/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
abarral
Newbie


Joined: 21 Sep 2010
Posts: 14

PostPosted: Wed Sep 22, 2010 2:42 pm    Post subject:
Reply with quote

Hi !

Thank for your reply, but that is exacly what I would'nt want to read !
I am affraid about learning gl Shading Language.

Do you know some cool resources to learn it ? I have got the OpenGL Super Bible 4th edition, is it enough ?


Thanks !

A. BARRAL
Back to top
View user's profile Send private message
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Wed Sep 22, 2010 2:52 pm    Post subject:
Light effect in osgOcean
Reply with quote

Hello Adrien,

Quote:
Thank for your reply, but that is exacly what I would'nt want to read !
I am affraid about learning gl Shading Language.

Hehe, sorry about that! But you'll see you can do lots of great things
pretty easily once you've learned GLSL. It opens up a great new world. :-)

Quote:
Do you know some cool resources to learn it ? I have got the OpenGL Super Bible 4th edition, is it enough ?

I would recommend the OpenGL Shading Language (orange book) by Randi
Rost, it has a chapter about replicating OpenGL fixed pipeline in
shaders which will be useful to you.

Also this site is well done, though some parts are obsolete.

http://www.lighthouse3d.com/opengl/glsl/

And you can get ShaderGen (which was made by 3DLabs but is not
distributed anymore, but can be downloaded from http://www.mew.cx/glsl/)
which can generate shaders that replicate the fixed pipeline. It has a
GUI where you select which features you need and then it gives you the
corresponding GLSL shader.

Though you'll have to be careful to keep the parts that are specific to
osgOcean in place when you edit its shaders.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.webhop.org/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean] 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 osgOcean and OpenSceneGraph issue sta... Paradox osgOcean [osgOcean] 0 Tue Jun 20, 2017 10:21 am View latest post
No new posts osgOcean and OpenSceneGraph issue sta... Paradox osgOcean [osgOcean] 0 Tue Jun 20, 2017 10:16 am View latest post
No new posts osgOcean and OpenSceneGraph issue sta... Paradox osgOcean [osgOcean] 0 Tue Jun 20, 2017 10:13 am View latest post
No new posts osgOcean and OpenSceneGraph issue sta... Paradox osgOcean [osgOcean] 0 Tue Jun 20, 2017 10:04 am View latest post
No new posts osgOcean and OpenSceneGraph issue sta... Paradox osgOcean [osgOcean] 0 Tue Jun 20, 2017 10:03 am 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