[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:


Code:
void LightShader::apply(osg::State& state) const
{
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
... // Original code
#else
    ...
    osg::Vec4 relPos = state.getModelViewMatrix() * _position;
    lightPosUniform.get()->set(relPos);
    ...
#endif
}




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:


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




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75204#75204







More information about the osg-users mailing list