i'm trying to create an osgViewer application to display 3D models (*.ive, *.osgb files) and use the osgEarth shaders for lighting. I only want to show the 3D model without a MapNode underneath. How do i need to set up the view/camera with the Shaders to get the models displayed with correct lighting?
Hello. I noticed in your example that the sunLS is a sibling to groupPhong, both are children of root. Is it possible that sunLS needs to be in your node tree above your model?
Otherwise everything looks fine to my untrained eye. If in doubt, run osgEarth::Registry::shaderGenerator().run(root) -- that might make some of your explicit calls to shaderize superfluous, like the material callback.
The position of the sunLight object should not matter since it's "only" a direction not an actual position, right? When using a MapNode the model is placed on the earth at a given position, but in the model viewer the model is loaded at 0,0,0.
Are there some "limitations" in the light shader code which only work when a globe is present?
No, there are no limitations like that. The Phong shader is pretty generic. If you're still having issues I recommend making minor edits to PhongLighting.frag.glsl and PhongLighting.vert.glsl to track down where the problem is in your code w.r.t. lighting.
I was having problems the other day and tracked my issue down very quickly this way. I just used StateSet's setDefine(), then a pragma import_defines on it, and ifdef'd bits of code to check where logic was breaking. So on my object I set a define, then in the shader just updated the color to yellow and returned whenever the shader was called with that define. Then I refined the code to track down deeper. I eventually found I was assigning material properties incorrectly. You can probably do something similar.