[osg-users] OpenGL ES 2.0 and LIGHTING

Werner Modenbach Werner.Modenbach at texion.eu
Fri Nov 16 03:36:39 PST 2018


Hi Grigoriy,

why don't you do the multiply in the shader like you do with gl_vertex?

- Werner -

Am 16.11.2018 um 12:29 schrieb Grigoriy Mylnikov:
> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




More information about the osg-users mailing list