kbale / osgocean

An ocean rendering nodekit for OpenSceneGraph
GNU Lesser General Public License v3.0
109 stars 56 forks source link

Color #56

Open Krosyus opened 2 years ago

Krosyus commented 2 years ago

Hello ^^ I placed myself underwater and I would like to know why I can not put colors on my 2 ShapeDrawable object I tried without osgOcean and its works but on the example nothing passes as expected I may have forgotten an essential point '

here is my code if needed in the source file application.cpp before the "Set up the viewer": (nothing extraordinary)

osg::ref_ptr<osg::ShapeDrawable> cubeMap = new osg::ShapeDrawable();
osg::ref_ptr<osg::ShapeDrawable> cylinderMap = new osg::ShapeDrawable();
osg::ref_ptr<osg::Group> rootGroup = new osg::Group();

cubeMap->setShape(new osg::Box(osg::Vec3(0.0f, 0.0f, -210.0f), 2.0f));
cylinderMap->setShape(new osg::Cylinder(osg::Vec3(5.0f, 0.0f, -210.0f), 1.0f, 8.0f));
cubeMap->setColor(osg::Vec4f(1.0f, 0.0f, 0.0f, 0.0f));
cylinderMap->setColor(osg::Vec4f(1.0f,0.0f,1.0f,0.0f));
cylinderMap->setColorBinding(osg::Geometry::BIND_OVERALL);

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(cubeMap.get());
geode->addDrawable(cylinderMap.get());

scene->getOceanScene()->addChild(geode);
root->addChild(scene->getScene());

thanks in advance

kbale commented 2 years ago

Hi Souffou,

All nodes that are added to the ocean scene have a shader applied to them in order to replicate various above and below water effects (e.g. depth of field, shadows, water shading). You can see the shader used here: https://github.com/kbale/osgocean/blob/master/resources/shaders/osgOcean_ocean_scene.frag https://github.com/kbale/osgocean/blob/master/resources/shaders/osgOcean_ocean_scene.vert

If you look at the fragment shader you will see it doesn't take into account the the colour of the geometry when computing the final fragment colour, it relies on all objects that are added to the scene being texture mapped. It would be fairly trivial to modify this shader to use the geometry colour if you wish to though.

Hope that helps,

Kim.

On Mon, 7 Mar 2022 at 09:40, Souffou Daoudou @.***> wrote:

Hello ^^ I placed myself underwater and I would like to know why I can not put colors on my 2 ShapeDrawable object I tried without osgOcean and its works but on the example nothing passes as expected I may have forgotten an essential point '

here is my code if needed in the source file application.cpp before the "Set up the viewer": (nothing extraordinary)

osg::ref_ptr cubeMap = new osg::ShapeDrawable(); osg::ref_ptr cylinderMap = new osg::ShapeDrawable(); osg::ref_ptr rootGroup = new osg::Group();

cubeMap->setShape(new osg::Box(osg::Vec3(0.0f, 0.0f, -210.0f), 2.0f)); cylinderMap->setShape(new osg::Cylinder(osg::Vec3(5.0f, 0.0f, -210.0f), 1.0f, 8.0f)); cubeMap->setColor(osg::Vec4f(1.0f, 0.0f, 0.0f, 0.0f)); cylinderMap->setColor(osg::Vec4f(1.0f,0.0f,1.0f,0.0f)); cylinderMap->setColorBinding(osg::Geometry::BIND_OVERALL);

osg::ref_ptr geode = new osg::Geode; geode->addDrawable(cubeMap.get()); geode->addDrawable(cylinderMap.get());

scene->getOceanScene()->addChild(geode); root->addChild(scene->getScene());

thanks in advance

— Reply to this email directly, view it on GitHub https://github.com/kbale/osgocean/issues/56, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXXT5PHZ37SPM5WWPTX2G3U6XFIJANCNFSM5QCXTEYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

Krosyus commented 2 years ago

Oh

Allright, I’ll see what I can do. Thanks

kbale commented 2 years ago

Hi Souffou,

I should add that you can add your own shader to your scene nodes which will override the scene shader and use the same uniforms that are applied to the scene. So you can copy the base scene shader and modify it for your own node. You don't need to modify the base shader itself.

Cheers,

Kim.

On Mon, 7 Mar 2022 at 10:38, Souffou Daoudou @.***> wrote:

Oh

Allright, I’ll see what I can do. Thanks

— Reply to this email directly, view it on GitHub https://github.com/kbale/osgocean/issues/56#issuecomment-1060474965, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXXT5NYW7YGIPYAEPJIA5TU6XMCZANCNFSM5QCXTEYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

Krosyus commented 2 years ago

HOOOOO

Copy and modify the base shader Okay thanks for the tips

Have a nice day