[osg-users] OpenGL ES 2.0 and LIGHTING

Grigoriy Mylnikov digitalw0lf at yandex.ru
Fri Nov 16 03:29:55 PST 2018

Sorry for delayed reply.

My goal is to open and display .osgt files on android the same way they can be opened on desktop. This includes using several lights inside a model, both directional and point lights.

I have some progress with writing shaders, but I have troubles with understanding OSG states. I've updated osg::Light apply() code to pass light position (relative to camera) as uniform:

void LightShader::apply(osg::State& state) const
... // Original code
    osg::Vec4 relPos = state.getModelViewMatrix() * _position;

But it seems that state.getModelViewMatrix() does not gives me valid view matrix.

If I could get light position (relative to camera), I can use it in shaders like this:

vec3 APos = vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 fromPointToLight = lightPos.xyz - APos;

Read this topic online here:

More information about the osg-users mailing list