Lighting works on simple osg::Geometries without shaders?

classic Classic list List threaded Threaded
5 messages Options
ceranco ceranco
Reply | Threaded
Open this post in threaded view
|

Lighting works on simple osg::Geometries without shaders?

Hi,
After reading the FAQ and various posts, my understanding was that simple osg::Geometries (created manually) needed shaders for lighting to work:
osgEarth::Registry::shaderGenerator().run(geom);

But when I create a shape using the following pseudo-code:

auto vertices = new Vec3Array;
// ... populate vertices
auto normals = new Vec3Array;
// ... populate normals
auto colors = new Vec4Array;
colors->push_back({1.0, 0.0, 0.0, 1.0});

auto primitiveSet = new //.......

auto geom = new Geometry;
geometry->setVertexArray(vertices);
geometry->setNormalsArray(normals, Array::Binding::BIND_PER_VERTEX);
geometry->setColorsArray(colors, Array::Binding::BIND_OVERALL);
geometry->addPrimitiveSet(primitiveSet);
geometry->setUseVertexBufferObjects(true);
The geometry is correctly lit even when I don't generate the shaders using the Registry.
But when I create a shape using osg::Shape, it doesn't show the lighting without it.

Does anyone know why?
Eran Cohen
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Lighting works on simple osg::Geometries without shaders?

Eran,
What lighting are you using? Where are you putting your geometry in the scene graph? A simple untextured geometry won't need any shader generation to be lit even under and osgearth scene graph. 

osg::ShapeDrawable is an old immediate mode implementation and won't interact with shaders at all.

On Sun, Feb 24, 2019, 9:30 AM ceranco [via osgEarth] <[hidden email]> wrote:
Hi,
After reading the FAQ and various posts, my understanding was that simple osg::Geometries (created manually) needed shaders for lighting to work:
osgEarth::Registry::shaderGenerator().run(geom);

But when I create a shape using the following pseudo-code:

auto vertices = new Vec3Array;
// ... populate vertices
auto normals = new Vec3Array;
// ... populate normals
auto colors = new Vec4Array;
colors->push_back({1.0, 0.0, 0.0, 1.0});

auto primitiveSet = new //.......

auto geom = new Geometry;
geometry->setVertexArray(vertices);
geometry->setNormalsArray(normals, Array::Binding::BIND_PER_VERTEX);
geometry->setColorsArray(colors, Array::Binding::BIND_OVERALL);
geometry->addPrimitiveSet(primitiveSet);
geometry->setUseVertexBufferObjects(true);
The geometry is correctly lit even when I don't generate the shaders using the Registry.
But when I create a shape using osg::Shape, it doesn't show the lighting without it.

Does anyone know why?
Eran Cohen



If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Lighting-works-on-simple-osg-Geometries-without-shaders-tp7592431.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
Glenn Waldron / Pelican Mapping
ceranco ceranco
Reply | Threaded
Open this post in threaded view
|

Re: Lighting works on simple osg::Geometries without shaders?

Hi Glenn,

gwaldron wrote
Eran,
What lighting are you using?
I'm using the SkyNode to light my scene.


gwaldron wrote
Where are you putting your geometry in the scene graph?
My scene graph is as follows: Root -> SkyNode -> MapNode -> Geometry.

gwaldron wrote
A simple untextured geometry won't need any shader generation
to be lit even under and osgearth scene graph.

osg::ShapeDrawable is an old immediate mode implementation and won't
interact with shaders at all.
I see, I'm still trying to wrap my head around the difference between the old and new OpenGL modes and how lighting works in each one.
I thought that OpenGL lighting only works by default in OpenGL when using the Fixed Pipeline.
Does this mean that osg::Geometry uses the fixed pipeline (and the SkyNode sun is GL_LIGHT0) or that OSG has default shaders that are used and are compatible with osgEarth?

Thanks for the help!
Eran Cohen
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Lighting works on simple osg::Geometries without shaders?

Eran,

The SkyNode introduces a shader program; thus, anything under the SkyNode will render using shaders. So your geometry will be lit by the SkyNode using its shaders.

OpenSceneGraph (when compiled with the default settings) supports both FFP and shader-based rendering. You can mix them in a scene. But when you add a shader to a node, everything below that node are now subject to the shader pipeline and not the FFP.

GL_LIGHTING is an FFP mode and is meaningless in the context of the shader pipeline.

osgEarth features are "shaders-only" and you should not expect anything under an osgEarth node to support FFP features like GL_LIGHTING.

You are correct, this stuff can be confusing. :)
Glenn Waldron / Pelican Mapping
ceranco ceranco
Reply | Threaded
Open this post in threaded view
|

Re: Lighting works on simple osg::Geometries without shaders?

gwaldron wrote
Eran,

The SkyNode introduces a shader program; thus, anything under the SkyNode will render using shaders. So your geometry will be lit by the SkyNode using its shaders.

OpenSceneGraph (when compiled with the default settings) supports both FFP and shader-based rendering. You can mix them in a scene. But when you add a shader to a node, everything below that node are now subject to the shader pipeline and not the FFP.

GL_LIGHTING is an FFP mode and is meaningless in the context of the shader pipeline.

osgEarth features are "shaders-only" and you should not expect anything under an osgEarth node to support FFP features like GL_LIGHTING.

You are correct, this stuff can be confusing. :)
I think I understand better now.
Thanks for the explanation :)
Eran Cohen